使用Delphi中的enum参数调用DLL中的C函数
发布时间:2020-12-15 09:35:46 所属栏目:大数据 来源:网络整理
导读:我有一个用C语言编写的第三方(Win32)DLL,它公开了以下接口: DLL_EXPORT typedef enum{ DEVICE_PCI = 1,DEVICE_USB = 2} DeviceType;DLL_EXPORT int DeviceStatus(DeviceType kind); 我希望从德尔福那里得到它. 如何在Delphi代码中访问DeviceType常量?或者,
我有一个用C语言编写的第三方(Win32)DLL,它公开了以下接口:
DLL_EXPORT typedef enum { DEVICE_PCI = 1,DEVICE_USB = 2 } DeviceType; DLL_EXPORT int DeviceStatus(DeviceType kind); 我希望从德尔福那里得到它. 如何在Delphi代码中访问DeviceType常量?或者,如果我应该直接使用值1和2,我应该使用什么Delphi类型的“DeviceType类型”参数?整数?字? 解决方法
在C中从外部DLL声明接口的常用方法是在.H头文件中公开其接口.然后,要从C访问DLL,.H头文件必须在C源代码中包含#included.
转换为Delphi术语,您需要创建一个以pascal术语描述相同接口的单元文件,将c语法转换为pascal. 对于您的情况,您将创建一个文件,如… unit xyzDevice; { XYZ device Delphi interface unit translated from xyz.h by xxxxx -- Copyright (c) 2009 xxxxx Delphi API to libXYZ - The Free XYZ device library --- Copyright (C) 2006 yyyyy } interface type TXyzDeviceType = integer; const xyzDll = 'xyz.dll'; XYZ_DEVICE_PCI = 1; XYZ_DEVICE_USB = 2; function XyzDeviceStatus ( kind : TXyzDeviceType ) : integer; stdcall; external xyzDLL; name 'DeviceStatus'; implementation end. 您可以在源代码的uses子句中声明它.并以这种方式调用函数: uses xyzDevice; ... case XyzDeviceStatus(XYZ_DEVICE_USB) of ... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |