调用dll 的问题

sanguang 2004-06-18 08:47:05
本人为初学者 学习中遇到一个问题 特来请求各位帮助

拿到一个 dll 文件 只有 bcb 的调用方法 我想在delphi 中调用
dll: Key.dll
bcb 调用方法 在项目中包含 Key_import.h Key_import.cpp
——-----------------------------------------------------------
Key_import.h 内容:
#ifndef KEY_IMPORT_H
#define KEY_IMPORT_H

enum { KS_SAMPLE_RATE, KS_CHANNELS, KS_ANTI_ALIAS, KS_SHIFT_KEY };

typedef HKEY;

typedef __declspec(dllimport) HKEY (__stdcall *IKey_Create)();
typedef __declspec(dllimport) void (__stdcall *IKey_Set)(HKEY ksHandle, int property, int value);
typedef __declspec(dllimport) void (__stdcall *IKey_PutSamples)(HKEY ksHandle, short int * data, int dataSize );
typedef __declspec(dllimport) int (__stdcall *IKey_GetSamples)(HKEY ksHandle, short int * data, int maxSize, int * inSize );

extern IKey_Create Key_Create;
extern IKey_Set Key_Set;
extern IKey_PutSamples Key_PutSamples;
extern IKey_GetSamples Key_GetSamples;

int InitKeyLib();

#endif
——-----------------------------------------------------------
Key_import.cpp 内容


#include "Windows.h"
#include "Key_import.h"

IKey_Create Key_Create;
IKey_Set Key_Set;
IKey_PutSamples Key_PutSamples;
IKey_GetSamples Key_GetSamples;

int InitKeyLib()
{
HINSTANCE KeyLibDll;
KeyLibDll = LoadLibrary( "Key.dll" );

if (KeyLibDll == NULL)
return -1;

Key_Create = (IKey_Create)GetProcAddress( KeyLibDll, "Key_Create" );
Key_Set = (IKey_Set)GetProcAddress( KeyLibDll, "Key_Set" );
Key_PutSamples = (IKey_PutSamples)GetProcAddress( KeyLibDll, "Key_PutSamples" );
Key_GetSamples = (IKey_GetSamples)GetProcAddress( KeyLibDll, "Key_GetSamples" );

if ((!Key_Create) || (!Key_Set) || (!Key_PutSamples) || (!Key_GetSamples))
return 0;

return 1;
}
——-----------------------------------------------------------
期望各位大佬能够帮忙把这俩引用文件转为.pas 我在这里先谢过了

...全文
156 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fyje 2004-06-18
  • 打赏
  • 举报
回复
三.DLL中函数及窗体的调用
==========================
1.调用方法一
--------------
implementation //在此的下方写明调用函数的DLL

{$R *.DFM}
//DLL内函数调用
function PenniesToSoins(SourceResult:Integer):Integer;
StdCall external 'FIRSTDLL.DLL';

........

2.调用方法二
==============
type //在此创建一个函数类
// 1 -------------------------------
{ First, define a procedural data type, this should reflect the
procedure that is exported from the DLL. }
{ Create a new exception class to reflect a failed DLL load }
TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall;
EDLLLoadError = class(Exception);//同时分创建一个出错记录类
// 1 -------------------------------
TMAINCLTR = class(TForm) //这里不变,系统自动生成

......

procedure TMAINCLTR.ToolButton1Click(Sender: TObject);
var //按钮的调用事件:调用过程
LibHandle: THandle;
ShowPerSN: TShowPerSN;
begin
Application.Title:='人力资源管理系统DLL文件测试程式';
{ Attempt to load the DLL 尝试装入DLL文件}
LibHandle := LoadLibrary('MGRPERSN.DLL');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('Unable to Load DLL(无法成功装入MGRPERSN.DLL)');
@ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN');
if not (@ShowPerSN = nil) then
ShowPerSN(Application.Handle, '人事资料管理')//呼叫出窗体
else
RaiseLastWin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;
============== END ==================
fyje 2004-06-18
  • 打赏
  • 举报
回复
delphi中静态调用:
procedure Key_Create; external 'key.dll' index 1;。。。

netsys2 2004-06-18
  • 打赏
  • 举报
回复
你应该去DELPHI的论坛问问。

如果是DELPHI转为CB,我们还可以帮忙。
futulove 2004-06-18
  • 打赏
  • 举报
回复
有些道理

13,871

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧