[英]64 bits DLL c/c++ interface to Delphi
I have a .h
file that I need to translate into Delphi, to call a DLL interface that is written in C/C++.我有一个
.h
文件,我需要将其翻译成 Delphi,以调用用 C/C++ 编写的 DLL 接口。
In 32bit, everything goes well, I can use the DLL with a Delphi app with no issue.在 32 位中,一切顺利,我可以毫无问题地使用 DLL 和 Delphi 应用程序。
In 64bit, it does not work very well.在 64 位中,它不能很好地工作。
I did not write this DLL interface, it comes from a third party that does hardware.这个DLL接口不是我写的,它来自做硬件的第三方。
namespace gXusb {
typedef int INTEGER;
typedef short INT16;
typedef unsigned CARDINAL;
typedef unsigned char CARD8;
typedef float REAL;
typedef double LONGREAL;
typedef char CHAR;
typedef unsigned char BOOLEAN;
typedef void * ADDRESS;
struct CCamera;
extern "C" EXPORT_ void __cdecl Enumerate( void (__cdecl *CallbackProc)(CARDINAL) );
extern "C" EXPORT_ CCamera *__cdecl Initialize( CARDINAL Id );
Is Cardinal
still 32bit unsigned under 64bit? Cardinal
在 64 位下仍然是 32 位无符号吗?
I'm not very sure about this way of declaring this function type and what it does with 64bit compilation:我不太确定这种声明此 function 类型的方式以及它对 64 位编译的作用:
void (__cdecl *CallbackProc)(CARDINAL)
It looks a bit cumbersome.看起来有点麻烦。
What puzzles me is this:让我困惑的是:
typedef unsigned CARDINAL;
I have figured out this is 32bit for a 32bit DLL, but did it stay 32bit under a 64bit DLL?我发现这是 32 位的 32 位 DLL,但它在 64 位 DLL 下是否保持 32 位?
Something like the following should work fine in both 32bit and 64bit:类似以下的内容在 32 位和 64 位中都应该可以正常工作:
unit gXusb;
interface
type
// prefixing types that Delphi already declares...
_INTEGER = Int32;
_INT16 = Int16;
_CARDINAL = UInt32;
CARD8 = UInt8;
_REAL = Single;
LONGREAL = Double;
_CHAR = AnsiChar;
_BOOLEAN = ByteBool;
ADDRESS = Pointer;
CCamera = record end;
PCCamera = ^CCamera;
UsbEnumCallback = procedure(Param: _CARDINAL); cdecl;
procedure Enumerate(Cb: UsbEnumCallback); cdecl;
function Initialize(Id: _CARDINAL): PCCamera; cdecl;
implementation
const
TheDLLName = 'the.dll';
procedure Enumerate; external TheDLLName;
function Initialize; external TheDLLName;
end.
Personally, I would just get rid of any type aliases that are not strictly necessary, use native Delphi types were appropriate, eg:就个人而言,我会摆脱任何不是绝对必要的类型别名,使用本机 Delphi 类型是合适的,例如:
unit gXusb;
interface
type
CARD8 = UInt8;
CCamera = record end;
PCCamera = ^CCamera;
UsbEnumCallback = procedure(Param: UInt32); cdecl;
procedure Enumerate(Cb: UsbEnumCallback); cdecl;
function Initialize(Id: UInt32): PCCamera; cdecl;
implementation
const
TheDLLName = 'the.dll';
procedure Enumerate; external TheDLLName;
function Initialize; external TheDLLName;
end.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.