byte a = new byte();
a = null;
ikeyCom.OpenDevice(0,ref a);我试了一下这样调,可是还是不行,说
 无法将 NULL 转换成“byte”,因为它是一种数值类型

解决方案 »

  1.   

    定义成ref类型参数,就一点要有地址传进去,null没有地址,一定出错
      

  2.   

    byte a = new byte();
    ikeyCom.OpenDevice(0,ref a);
      

  3.   

    按楼上的写了,出现如下错误:无效指针
    有关调用实时(JIT)调试而不是此对话框的详细信息,
    请参阅此消息的结尾。************** 异常文本 **************
    System.NullReferenceException: 无效指针
       at IKEYCOMLib.IiKey.OpenDevice(Int32 lFlags, Byte& pAppId)
       at AxIKEYCOMLib.AxCoiKey.OpenDevice(Int32 lFlags, Byte& pAppId)
       at IkeyOcxJiaMi.Form1.button3_Click(Object sender, EventArgs e) in c:\winformpoject\ikeyocxjiami\form1.cs:line 171
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    ************** 已加载的程序集 **************
    mscorlib
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
    ----------------------------------------
    IkeyOcxJiaMi
        程序集版本: 1.0.1721.22337
        Win32 版本: 1.0.1721.22337
        基本代码: file:///C:/WinFormPoject/IkeyOcxJiaMi/bin/Debug/IkeyOcxJiaMi.exe
    ----------------------------------------
    System.Windows.Forms
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
    ----------------------------------------
    System
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
    ----------------------------------------
    AxInterop.IKEYCONTROLLib
        程序集版本: 1.0.0.0
        Win32 版本: 1.0.0.0
        基本代码: file:///C:/WinFormPoject/IkeyOcxJiaMi/bin/Debug/AxInterop.IKEYCONTROLLib.DLL
    ----------------------------------------
    System.Drawing
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
    ----------------------------------------
    AxInterop.IKEYCOMLib
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.0.0
        基本代码: file:///C:/WinFormPoject/IkeyOcxJiaMi/bin/Debug/AxInterop.IKEYCOMLib.DLL
    ----------------------------------------
    System.Xml
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
    ----------------------------------------
    Interop.IKEYCOMLib
        程序集版本: 2.0.0.0
        Win32 版本: 2.0.0.0
        基本代码: file:///C:/WinFormPoject/IkeyOcxJiaMi/bin/Debug/Interop.IKEYCOMLib.DLL
    ----------------------------------------
    System.Windows.Forms.resources
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.windows.forms.resources/1.0.5000.0_zh-chs_b77a5c561934e089/system.windows.forms.resources.dll
    ----------------------------------------
    Interop.IKEYCONTROLLib
        程序集版本: 1.0.0.0
        Win32 版本: 1.0.0.0
        基本代码: file:///C:/WinFormPoject/IkeyOcxJiaMi/bin/Debug/Interop.IKEYCONTROLLib.DLL
    ----------------------------------------
    System.resources
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.resources/1.0.5000.0_zh-chs_b77a5c561934e089/system.resources.dll
    ----------------------------------------
    Accessibility
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/accessibility/1.0.5000.0__b03f5f7f11d50a3a/accessibility.dll
    ----------------------------------------
    mscorlib.resources
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/mscorlib.resources/1.0.5000.0_zh-chs_b77a5c561934e089/mscorlib.resources.dll
    ----------------------------------------************** JIT 调试 **************
    计算机的配置文件(machine.config)的 
     system.windows.forms 节中必须设置 jitDebugging 值。
    编译应用程序时还必须启用\r\n调试。\r\n\r\n例如: \r\n\r\n<configuration>\r\n    <system.windows.forms jitDebugging="true" />\r\n</configuration>\r\n\r\n启用 JIT 调试后,任何未处理的异常\r\n都将被发送到此计算机上注册的 JIT 调试器,\r\n而不是由此对话框处理。\r\n
      

  4.   

    byte a = new byte(){0}; //这样呢?不知道语法写错没
    ikeyCom.OpenDevice(0,ref a);前面一个参数是什么意思?
      

  5.   

    谢谢楼上的,不行
    第一参数没有问题,是一个int型