我有一個問題,重用從VB 6.0到VB.NET使用的C++ DLL。從VB.NET調用非託管代碼C++ dll
我的一個隊友在VB6.0中編寫了一個代碼,用於調用在VC++ 6.0中編程的Ansi C++ DLL。
該函數聲明如下;
3210在VB6.0前者代碼中調用此DLL這樣
status = IniciaGestion(Me.hWnd, "DRVCOMM2.ini", mensaerror)
其中mensaerror
是被定義爲
Public mensaerror As String * 256
輸出參數現在,我可以使用從VB這個DLL 。淨?
我有這個第三個參數的聲明有問題。
我使用這個聲明
<DllImport("GestionPrg.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
Public Shared Function IniciaGestion(<MarshalAs(UnmanagedType.I4)> ByVal a As Integer, <MarshalAs(UnmanagedType.LPStr)> ByVal b As String, <OutAttribute(), MarshalAs(UnmanagedType.LPTStr)> ByRef c As String) As Long
,並調用函數如下
Dim mensaerror As String
Class1.IniciaGestion(Me.Handle, "C:\\Windows\\DRVCOMM2.ini", mensaerror)
我調試和函數被調用,但是當我去分配價值mensaerror
在C++代碼產生一個例外。
任何人都可以幫助我在VB.NET中的聲明?
,除非你真的知道你在做什麼,當調用VB中的外部庫時,你永遠不會聲明字符串「ByRef」。 – GSerg