先贴代码
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()
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()
解决方案 »
- VBA强人入,关于EXCEL统计
- SQL Server 的远程备份和还原问题?
- 请教一个关于TreeView加载的问题(UP者,回复都有分)
- 求助!关于局域网通讯的问题
- 如何通过SCROLLBAR控制图片的滚动
- 如何修改另一程序中被禁用的控件的属性,即修改Enabled=false控件属性
- RichEditBox里的文字可以弄成一行红一行黑么?
- 关于在VB中启动邮件程序的问题
- 我在《程序员大本营2001--微软版》中的压缩文件中发现病毒
- 高手看过来,如何用load定义一个控件数组?
- Floodfill函数 如何保证(X,Y)点坐标一定在封闭区域内??
- Chen8013 请进来!!还有个问题期待解决
改成类是下面的
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)
......
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
ICC_tsi_apiC(HANDLE fd, long len, LPCSTR comm, long lenr, LPCSTR resp)函数中
comm,resp的处理用 strcpy 赋值
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(按地址传递)