Home > Software engineering >  (urgent) vb call c would be how should correspond to when the DLL?
(urgent) vb call c would be how should correspond to when the DLL?

Time:11-06

Vb call would be how should correspond to the c + + DLL?

CodePudding user response:

String is not to go, as for the transformation of baidu win32api,

CodePudding user response:

VC docking VB string can use BSTR type, you can search BSTR would be

CodePudding user response:

VC code doesn't change, not me

CodePudding user response:

Can write a adapter DLL, using standard DLL or ActiveX DLL.

CodePudding user response:

Can write a adapter DLL, using standard DLL or ActiveX DLL.

CodePudding user response:

If you really want to pass the Unicode string to API, can use an array of bytes to transfer data,
Such as the first converts a string to a Unicode coded into the byte array, and then passed on the byte array, such as:
 
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxW" (ByVal HWND As Long, _
ByRef lpText As Any, _
ByRef lpCaption As Any, _
ByVal wType As Long As Long)
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, _
ByVal dwFlags As Long, _
ByVal lpMultiByteStr As String, _
ByVal cchMultiByte As Long, _
ByRef lpWideCharStr As Any, _
ByVal cchWideChar As Long As Long)
Private Const CP_ACP=0 'default to ANSI code page

Private Sub Command1_Click ()
Dim str_message As String, _
Str_title As String, _
Array_message () As Byte, _
Attay_title () As Byte

Str_message="this is a UNICODE, please determine,"
Str_title="UNICODE title"
Array_message=ASCII2UNICODE (str_message)
Attay_title=ASCII2UNICODE (str_title)
MessageBox 0, array_message (0), attay_title (0), and 64

End Sub

Private Function ASCII2UNICODE (ByVal in_str_ascii As String) As Byte ()
Dim wLength As Long, _
Out_buff () As Byte
WLength=MultiByteToWideChar (in_str_ascii CP_ACP, 0, 1, vbNull, 0) 'made to convert the wide character of space size
ReDim out_buff (wLength)
In_str_ascii MultiByteToWideChar CP_ACP, 0, 1, out_buff (0), wLength
ASCII2UNICODE=out_buff
End the Function

CodePudding user response:

refer to 6th floor still human response:
if you really want to pass the Unicode string to API, can use an array of bytes to transfer data,
Such as the first converts a string to a Unicode coded into the byte array, and then passed on the byte array, such as:
 
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxW" (ByVal HWND As Long, _
ByRef lpText As Any, _
ByRef lpCaption As Any, _
ByVal wType As Long As Long)
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, _
ByVal dwFlags As Long, _
ByVal lpMultiByteStr As String, _
ByVal cchMultiByte As Long, _
ByRef lpWideCharStr As Any, _
ByVal cchWideChar As Long As Long)
Private Const CP_ACP=0 'default to ANSI code page

Private Sub Command1_Click ()
Dim str_message As String, _
Str_title As String, _
Array_message () As Byte, _
Attay_title () As Byte

Str_message="this is a UNICODE, please determine,"
Str_title="UNICODE title"
Array_message=ASCII2UNICODE (str_message)
Attay_title=ASCII2UNICODE (str_title)
MessageBox 0, array_message (0), attay_title (0), and 64

End Sub

Private Function ASCII2UNICODE (ByVal in_str_ascii As String) As Byte ()
Dim wLength As Long, _
Out_buff () As Byte
WLength=MultiByteToWideChar (in_str_ascii CP_ACP, 0, 1, vbNull, 0) 'made to convert the wide character of space size
ReDim out_buff (wLength)
In_str_ascii MultiByteToWideChar CP_ACP, 0, 1, out_buff (0), wLength
ASCII2UNICODE=out_buff
End the Function


Available, thank you.

CodePudding user response:

In fact, don't bother,
API statement, the statement would be parameters for byval wc as long,
In VB6 called, STRPTR (string variables or constants) transmission line,


6th floor said MessageBoxW, for example, in a statement, the second and the third parameter is changed to byval xx as long

Then call, can be like this:
MessageBox 0, STRPTR (" message content "), STRPTR (" title "), 64

CodePudding user response:

Ok, I will try!
  •  Tags:  
  • API
  • Related