vb向VC写的DLL传递自定义结构类型的数组参数,字符串有乱码解决思路
vb向VC写的DLL传递自定义结构类型的数组参数,字符串有乱码
VC相关代码
//自定义数据结构
typedef struct tagCardInfo{
LPCSTR lpNo;//编号
LPCSTR lpName;//姓名
} CARDINFO,*LPCARDINFO;
//函数
int __stdcall GetCard(HWND hWnd,LPCARDINFO lpCardInfo, ){
CARDINFO *point;
for (int i = 0; i < 10; i++ )
{
point=&lpCardInfo[i];
MessageBox(0,(*point).lpName,_T( "test "),MB_ICONINFORMATION);
}
return 0;
}
VB代码:
Private Type CardInfo
No As String
Name As String
End Type
Private Declare Function PrintCard Lib "htprint.dll "
(ByVal hWnd As Long, ByRef Card As CardInfo) As Integer
Private Sub Command1_Click()
Dim nSpeed As Integer
Dim x As String
Dim tm(9) As CardInfo
Dim i As Integer
For i = 0 To 9
With tm(i)
.No = "编号 " & i
.Name = "姓名 " & i
End With
Next
Call GetCard(0, tm(0))
请问我这样象VC DLL传递参数对吗?为什么MESSAGEBOX对话框除了第一个CARDINFO显示正确,循环到后面的,显示都是乱码?
------解决方案--------------------
http://support.microsoft.com/kb/187912
------解决方案--------------------
VB用的是BSTR不是LPCSTR……
------解决方案--------------------
BSTR, 当然VC这一端也得按BSTR处理。
------解决方案--------------------
VB的string并不等于VC的LPCSTR
VC相关代码
//自定义数据结构
typedef struct tagCardInfo{
LPCSTR lpNo;//编号
LPCSTR lpName;//姓名
} CARDINFO,*LPCARDINFO;
//函数
int __stdcall GetCard(HWND hWnd,LPCARDINFO lpCardInfo, ){
CARDINFO *point;
for (int i = 0; i < 10; i++ )
{
point=&lpCardInfo[i];
MessageBox(0,(*point).lpName,_T( "test "),MB_ICONINFORMATION);
}
return 0;
}
VB代码:
Private Type CardInfo
No As String
Name As String
End Type
Private Declare Function PrintCard Lib "htprint.dll "
(ByVal hWnd As Long, ByRef Card As CardInfo) As Integer
Private Sub Command1_Click()
Dim nSpeed As Integer
Dim x As String
Dim tm(9) As CardInfo
Dim i As Integer
For i = 0 To 9
With tm(i)
.No = "编号 " & i
.Name = "姓名 " & i
End With
Next
Call GetCard(0, tm(0))
请问我这样象VC DLL传递参数对吗?为什么MESSAGEBOX对话框除了第一个CARDINFO显示正确,循环到后面的,显示都是乱码?
------解决方案--------------------
http://support.microsoft.com/kb/187912
------解决方案--------------------
VB用的是BSTR不是LPCSTR……
------解决方案--------------------
BSTR, 当然VC这一端也得按BSTR处理。
------解决方案--------------------
VB的string并不等于VC的LPCSTR