我正在将最初用 vb6 编写的应用程序转换为 vb.net。该应用程序所做的其中一件事是将“类型”对象发送到 dll。我尝试将类型转换为结构并 p/调用 dll,但它似乎不起作用。我被困了一个星期,任何帮助将不胜感激
这是该类型的 vb6 代码
'Define WICS Communications Control Block (CCB).
Type WicsCCBType ' Create user-defined type.
CCBNum As String * 1
CCBVer As String * 1
Resp1 As String * 4
Resp2 As String * 4
PLUA As String * 8
LLUA As String * 8
Mode As String * 8
ReqMax As String * 5
ResMax As String * 5
End Type
这是调用 dll 的方式
Private Declare Sub WICSRASP Lib "wicsrasp.dll" (MyWicsCCB As WicsCCBType)
WICSRASP MyWicsCCB
这是我用 vb.net 尝试过的,但它不起作用
'Define WICS Communications Control Block (CCB).
<System.Runtime.InteropServices.StructLayoutAttribute( _
System.Runtime.InteropServices.LayoutKind.Sequential, _
CharSet:=System.Runtime.InteropServices.CharSet.[Unicode])> _
Structure WicsCCBType ' Create user-defined type.
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=1)> Dim CCBNum As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=1)> Dim CCBVer As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=4)> Dim Resp1 As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=4)> Dim Resp2 As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=8)> Dim PLUA As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=8)> Dim LLUA As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=8)> Dim Mode As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=5)> Dim ReqMax As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=5)> Dim ResMax As String
End Structure
这是我试图称呼它的地方
<System.Runtime.InteropServices.DllImportAttribute("C:\windows\system32\wicsrasp.dll")> _
Public Shared Sub WICSRASP(
ByRef CCB As WicsCCBType,
ByRef Request As DAWicsRequestType,
ByRef Response As DAWicsResponseType)
End Sub
Dim CCB As New modWICSDiary.WicsCCBType()
CCB.CCBNum = "B"
CCB.CCBVer = "2"
CCB.LLUA = " "
CCB.Mode = "CICSMO2 "
CCB.ReqMax = "2100 "
CCB.ResMax = "2100 "
CCB.Resp1 = "0 "
CCB.Resp2 = "0 "
CCB.PLUA = "WICSPLU "
NativeMethods.WICSRASP(CCB)
至于值,相同的值适用于 vb6 类型
再次提前谢谢你