vb 6 C#中的代码转换 [英] vb 6 code converstion in C#

查看:117
本文介绍了vb 6 C#中的代码转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


i将您的vb代码转换为c#,但如果我做错了,请错误地指导我。



////// ////// vb code ///////////////

Hi i am converting your vb code into c# but having error kindly guide me if i am doing something wrong.

////////////vb code///////////////

Public Declare Function IO_HasScanner Lib "scandll.dll" (ByVal IVS_600DS As String, ByVal hHandle As Long) As Long

Private Sub CmdConnect_Click()
Dim lRet As Long

lRet = IO_HasScanner("IDCapture", Me.hwnd)
If lRet = 0 Then
    Text1.Text = "Scanner connected."
    bLoaded = True
    CmdConnect.Enabled = False
    OptionManual.Value = True
    strGreyImageFile = "G01.bmp"
    strColorImageFile = "C01.bmp"
    strGreyImageFile_Head = "GH01.bmp"
    strColorImageFile_Head = "CH01.bmp"
Else
    Text1.Text = "Device not connected."
    bLoaded = False
    CmdConnect.Enabled = True
End If
End Sub





///////// c#4.0代码////////





/////////c# 4.0 code////////

[DllImport("ScanDll.dll")]
        public static extern long IO_HasScanner(string IVS_600DS, long hHandle);

        private void Form1_Load(object sender, EventArgs e)
        {
            long result;
            result = IO_HasScanner("IDCapture", this.Handle.ToInt32()); //// Get Error on this line.
            MessageBox.Show(result.ToString());
        }

推荐答案

好的 - 你会的。

A long Int32 不同 - 它是 Int64

尝试:

Well yes - you will.
A long is not the same as an Int32 - it's an Int64
Try:
long result;
result = IO_HasScanner("IDCapture", this.Handle.ToInt64());


也许你现在可以试试 - 长期改为Int32



Maybe you can try this now - long changed to Int32

[DllImport("ScanDll.dll")]
public static extern Int32 IO_HasScanner([MarshalAs(UnmanagedType.VBByRefStr)] ref string IVS_600DS, Int32 hHandle);

private void Form1_Load(object sender, EventArgs e)
{
   Int32 result;
   result = IO_HasScanner("IDCapture", this.Handle.ToInt32()); 
   MessageBox.Show(result.ToString());
}


只是数据类型不匹配



i使用long而不是int32。



just data type mismatch

i was using long instead of int32.

[DllImport(@"ScanDll.dll")]
public static extern Int32 IO_HasScanner(string IVS_600DS, int hHandle);

private void Form1_Load(object sender, EventArgs e)
{
    long result;
    result = IO_HasScanner("IDCapture", this.Handle.ToInt32());
    MessageBox.Show(result.ToString());
}


这篇关于vb 6 C#中的代码转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆