什么是VB6等价的C ++ char数组? [英] What's is the VB6 equivalent of a C++ char array?
问题描述
我试图从VB6应用程序中调用用C ++编写的DLL。
I'm trying to call a DLL written in C++ from a VB6 application.
这是调用DLL的C ++示例代码。
Here's the C++ example code for calling the DLL.
char firmware[32];
int maxUnits = InitPowerDevice(firmware);
< DLL调用约定。
Public Declare Function InitPowerDevice Lib "PwrDeviceDll.dll" (ByRef firmware() As Byte) As Long
Dim firmware(32) As Byte
InitPowerDevice(firmware)
编辑:C ++原型:
Name: InitPowerDevice
Parameters: firmware: returns firmware version in ?.? format in a character string (major revision and minor revision)
Return: >0 if successful. Returns number of Power devices connected
CLASS_DECLSPEC int InitPowerDevice(char firmware[]);
推荐答案
很久了,
// In the C code when compiling to build the dll
CLASS_DECLSPEC int __stdcall InitPowerDevice(char firmware[]);
' VB Declaration
Public Declare Function InitPowerDevice Lib "PwrDeviceDll.dll" _
(ByVal firmware As String) As Long
' VB Call
Dim fmware as String
Dim r as Long
fmware = Space(32)
r = InitPowerDevice(fmware)
我不认为VB6支持以任何正常方式调用 cdecl
函数 - 可能有hacks做。可能你可以写一个包装 dll
,它包含 cdecl
函数和 stdcall
函数并转发这个调用。
I don't think VB6 supports calling cdecl
functions in any normal way - there may be hacks for doing it. May be you can write a wrapper dll
which wraps the cdecl
function with a stdcall
function and just forwards the call.
这些是一些黑客 - 但我没有尝试过。
These are some hacks - but I haven't tried it.
http:// planet- source-code.com/vb/scripts/ShowCode.asp?txtCodeId=49776&lngWId=1
http://planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId = 62014& lngWId = 1
这篇关于什么是VB6等价的C ++ char数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!