c的dll里的部分代码是:
///////////////////////////
char str[100]="dll发来的消息是: ...";
SendMessage(m_hWnd,12,*str,0);//m_hWnd是vb窗口的代号
//////////////////////////////////vb的窗口处理函数是:
'''''''''''''''''''''''''''''
Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
dim str1 as string*100
If uMsg = 12 Then
MsgBox "收到dll字符串消息,字符串是:(?????)"
End If
WndProc = CallWindowProc(GetProp(hWnd, OLDWNDPROC), hWnd, uMsg, wParam, lParam)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''
vb如何将vc里的str字符串提取到vb代码的"字符串是:(?????)"或str1里????
///////////////////////////
char str[100]="dll发来的消息是: ...";
SendMessage(m_hWnd,12,*str,0);//m_hWnd是vb窗口的代号
//////////////////////////////////vb的窗口处理函数是:
'''''''''''''''''''''''''''''
Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
dim str1 as string*100
If uMsg = 12 Then
MsgBox "收到dll字符串消息,字符串是:(?????)"
End If
WndProc = CallWindowProc(GetProp(hWnd, OLDWNDPROC), hWnd, uMsg, wParam, lParam)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''
vb如何将vc里的str字符串提取到vb代码的"字符串是:(?????)"或str1里????
///////////////////////////
char str[100]="dll发来的消息是: ...";
SendMessage(m_hWnd,12,strlen(str),*str);//m_hWnd是vb窗口的代号
//////////////////////////////////
第一次发错了!
Dim byteVal() As Byte
Dim str As StringRedim byteVal(1 To wParam) As Byte '看你从DLL发出的消息,wParam参数应该是字串字节大小
CopyMemory byteVal(1), ByVal lParam, wParam
str = StrConv(byteVal, vbFormUnicode)
'str = StrConv(byteVal, vbUnicode)
'上面两个字符转换随便试一个,我这里没得调试
Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
dim a(100-1) as byte, lLen as long, str as string
If uMsg = 12 Then
copymemory a(0), byval wParam, 100
lLen = instrB(1, a, chr(0)) 'C 标准字符串以 \0 结束
if lLen <> 0 then '如果发送的字符串没有用 \0 结束(因此没有用lstrcpy而是用copymemory),就认为字符串长 100,否则截短
redim preserve a(lLen-1)
end if
str = strconv(a, vbUnicode)
MsgBox "收到dll字符串消息,字符串是:(" & str & ")"
End If
WndProc = CallWindowProc(GetProp(hWnd, OLDWNDPROC), hWnd, uMsg, wParam, lParam)
End Function
是在一个进程里的!!
SendMessage(m_hWnd,12,(WPARAM)str,0);VB里面的代码可以用Tiger_Zhao在4楼写的代码
不过,建议你直接回调VB的过程,从而直接传入字符串
连接错误啊!
"ReDim Preserve a(lLen - 1)"错误!提示是:数组维数已经定义!
我把"dim a(100-1) as byte"改成"dim a() as byte",!错误!提示是:"实时错误:'9'下标越界!"
怎么办啊?这是什么错误?
redim a(lLen-1)
lLen=100
redim a(lLen-1)
vc:
///////////////////
SendMessage(m_hWnd,12,(WPARAM)str,(LPARAM)strlen(str));
//////////////////////
vb:
''''''''''''''''''''''''''''''''''''''''''''''''
Dim a() As Byte, i As Long, str As String
If uMsg = 12 Then
ReDim a(lParam - 1)
CopyMemory a(0), ByVal wParam, lParam
str = StrConv(a, vbUnicode)
MsgBox "收到dll字符串消息,字符串是:(" & str & ")"
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
程序没有执行:MsgBox "收到dll字符串消息,字符串是:(" & str & ")"
vc:
///////////////////
SendMessage(m_hWnd,12,(WPARAM)str,0);
//////////////////////
vb:
Dim a(100) As Byte, i As Long, str As String
If 12 = uMsg Then
' MsgBox "!!!!"
' ReDim a(wParam - 1)
CopyMemory a(0), ByVal wParam, 100
str = a
' str = StrConv(a, vbUnicode)
Form1.Text1 = str
MsgBox "收到dll字符串消息,字符串是:(" & str & ")"
End If
结果str全是:"?????"
试:str1=strconv(a,vbfromunicode)
vb代码是:
'''''''''''''''''''''''''
Dim a() As Byte, i As Long, str As String
If 12 = uMsg Then
ReDim a(wParam - 1)
CopyMemory a(0), ByVal lParam, wParam
str = StrConv(a, vbUnicode)
Form1.Text1 = str
MsgBox "收到dll字符串消息,字符串是:(" & str + ")"
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''
vc代码是:
///////////////
SendMessage(m_hWnd,12,strlen(str),(LPARAM)&(*str));//m_hWnd是vb窗口的代号
////////////////////////
不知道我以上代码在:dll和VB程序不是同一个进程的情况下是否可以通过?