先贴代码
dll的vc接口  unsigned pascal ICC_tsi_apiC(HANDLE fd, int len, unsigned char *comm, int *lenr, unsigned char *resp);vb的声明:Declare Function ICC_tsi_api Lib "crwicc.dll" (ByVal fd As Integer, ByVal lenc As Integer, ByVal comm As String, ByVal lenr As Integer, ByVal resp As String) As Integervb的调用public hport As Integerpublic resp As Stringpublic tsiResp As Integerdim inlen As Integerdim outlen As Integerdim pass As String pass = "002400000702ffff55c736"
 temp = "002400000702ffff55c736"
 inlen = Len(temp) / 2 tsiResp = ICC_tsi_api(hport, inlen, pass, outlen, resp)vs调试执行到此句
出错
“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”未处理 System.AccessViolationException
  Message="尝试读取或写入受保护的内存。这通常指示其他内存已损坏。"
  Source="工程1"
  StackTrace:
       在 工程1.Module1.ICC_tsi_api(Int32 fd, Int32 lenc, String& comm, Int32 lenr, String& resp)
       在 工程1.Form1.readCard_Click(Object eventSender, EventArgs eventArgs) 位置 E:\测试vs\Form1.vb:行号 41
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 工程1.Form1.Main() 位置 E:\测试vs\Form1.Designer.vb:行号 1
       在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()

解决方案 »

  1.   

    这个DLL是.NET下开发的,你有安装.NET的运行库吗?
      

  2.   

    刚才没看全面,你本来就在.NET环境下, 楼主,你的贴应发在VB.ENT
      

  3.   

    dll的vc接口  unsigned pascal ICC_tsi_apiC(HANDLE fd, int len, unsigned char *comm, int *lenr, unsigned char *resp); 
    改成类是下面的
    void WINAPI ICC_tsi_apiC(HANDLE fd, long len, LPCSTR comm, long lenr, LPCSTR resp); vb的调用:
    没用过VB.net ,但vb5.0的调用方式是 :
    public hport As long 
    public resp As String 
    public tsiResp As long
    dim inlen As Integer 
    dim outlen As Integer 
    dim pass As String resp = String$(255,chr(0))
    pass = String$(255,chr(0))ICC_tsi_api(hport, inlen, pass, outlen, resp) 
    ......
      

  4.   

    改成地址传递试试
    Declare Function ICC_tsi_api Lib "crwicc.dll" (ByVal fd As Integer, ByVal lenc As Integer, ByVal comm As String, Byref lenr As Integer, Byref resp As String) As Integer 
      

  5.   

    哦,忘了说一句:在
    ICC_tsi_apiC(HANDLE fd, long len, LPCSTR comm, long lenr, LPCSTR resp)函数中
    comm,resp的处理用 strcpy 赋值
      

  6.   

    dll的vc接口  unsigned pascal ICC_tsi_apiC(HANDLE fd, int len, unsigned char *comm, int *lenr, unsigned char *resp); 
    vb的声明:Declare Function ICC_tsi_api Lib "crwicc.dll" (ByVal fd As Integer, ByVal lenc As Integer, ByVal comm As String, ByVal lenr As Integer, ByVal resp As String) As Integer VC接口的后面三个参数是指针,我觉得你在VB.NET的声明后面三个参数应该改为BYREF(按地址传递)