how to translate c header file to delphi 2006
How to translate the following?
1)
#ifndef __LVR_NET_SDK_H__
#define __LVR_NET_SDK_H__
#ifdef __LVR_NET_EXPORT__
#define LVR_NET_API extern "C" __declspec(dllexport)
#else
#define LVR_NET_API extern "C" __declspec(dllimport)
#endif
2)
typedef struct {
DWORD dwAlarmInput;
DWORD dwVideoLoss;
DWORD dwMotionDetect;
DWORD dwVideoCover;
DWORD dwReserve[16];
}LVR_NET_ALARM_INFO, *LPLVR_NET_ALARM_INFO;
3)
LVR_NET_API DWORD __stdcall LvrNetGetSd开发者_Go百科kVersion();
Thanks.
(1): Depends on if you only want to use this header to interface to the C lib, in that case you can safely ignore it.
(If you are translating a whole package to Delphi, and want to generate a DLL based on it, you'll need to add
something like {$ifdef LVR_NET_EXPORT} export; {$endif} to the function declarations, and in the main library file (the one that starts with "library") add the function to the "exports" clause (again {$ifdef LVR_NET_EXPORT}) )
In short: ignore
(2):
Type LPLVR_NET_ALARM_INFO = ^LVR_NET_ALARM_INFO
LVR_NET_ALARM_INFO = Record
dwAlarmInput,
dwVideoLoss,
dwMotionDetect,
dwVideoCover : DWORD;
dwReserve : array[0..15] of DWord;
end;
TLVR_NET_ALARM_INFO = LVR_NET_ALARM_INFO; // not needed but Delphi style convention
This isn't necessarily enough, since the way the record is packed is not defined this way. But the original fragment also lacks information about packing.
3)
function LvrNetGetSdkVersion:DWord;
or
function LvrNetGetSdkVersion:DWord; stdcall; external 'dllname.dll' name 'LvrNetGetSdkVersion';
to import from a dll. Note the "name" part where you can adjust the case of the imported identifier
You could translate the structure like this:
type
TLVR_NET_ALARM_INFO = record
dwAlarmInput : Cardinal;
dwMotionDetect : Cardinal;
dwVideoCover : Cardinal;
dwReserve array [0..15] of Cardinal;
end;
var
LVR_NET_ALARM_INFO : TLVR_NET_ALARM_INFO;
and the function declaration:
interface
function LvrNetGetSDKVersion: Cardinal; stdcall;
implementation
function LvrNetGetSDKVersion; external 'nameofthedll.dll';
Everything untested though. I hope it helps
Also check out DrBob. There you can find the tool HeadConv which can automatically convert C-Header files to Delphi. Its nice to start with, but not perfect.
精彩评论