BCB怎么调用DLL中的函数?能说的细点吗?非常感谢!!!!!

 我来答
匿名用户
2013-06-07
展开全部
推荐你看《BCB编写DLL终极手册》这篇文章
如下片段:
二. 静态调用 DLL
使用 $BCB path\Bin\implib.exe 生成 Lib 文件,加入到工程文件中
将该文件拷贝到当前目录,使用 implib MyDll.lib MyDll.dll 生成
// Unit1.h // TForm1 定义
#include "DllForm.h" // TDllFrm 定义
//---------------------------------------------------------------------------

__declspec(dllimport) class __stdcall MyDllClass {

public:

MyDllClass();

void CreateAForm();

TDllFrm* DllMyForm;
};
extern "C" __declspec(dllimport) __stdcall void CreateFromFunct();

class TForm1 : public TForm{...}

// Unit1.cpp // TForm1 实现
void __fastcall TForm1::Button1Click(TObject *Sender)
{ // 导出类实现,导出类只能使用静态方式调用

DllClass = new MyDllClass();

DllClass->CreateAForm();

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{ // 导出函数实现

CreateFromFunct();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{

delete DllClass;
}

三. 动态调用 DLL
// Unit1.h
class TForm1 : public TForm
{
...
private: // User declarations
void (__stdcall *CreateFromFunct)();
...
}

// Unit1.cpp // TForm1
HINSTANCE DLLInst = NULL;
void __fastcall TForm1::Button2Click(TObject *Sender)
{

if( NULL == DLLInst ) DLLInst = LoadLibrary("DLL.dll"); //上面的 Dll

if (DLLInst) {

CreateFromFunct = (void (__stdcall*)()) GetProcAddress(DLLInst,

"CreateFromFunct");

if (CreateFromFunct) CreateFromFunct();

else ShowMessage("Could not obtain function pointer");

}
else ShowMessage("Could not load DLL.dll");
}

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{

if ( DLLInst ) FreeLibrary (DLLInst);
}

四. DLL 作为 MDIChild (子窗体) 【只编写动态调用的例子】

实际上,调用子窗体的 DLL 时,系统只是检查应用程序的 MainForm 是否为 fsMDIForm 的窗体,这样只

要把调用程序的 Application 的 Handle 传递给 DLL 的 Application 即可;同时退出 DLL 时也要恢复

Application

// MDIChildPro.cpp // Dll 实现 CPP
#include "unit1.h" // TForm1 定义
TApplication *SaveApp = NULL;
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{

if ( (reason==DLL_PROCESS_DETACH) && SaveApp )

Application = SaveApp ; // 恢复 Application

return 1;
}

extern "C" __declspec(dllexport) __stdcall void TestMDIChild(
//1024X768

TApplication* mainApp,

LPSTR lpCaption)
{

if ( NULL == SaveApp ) // 保存 Application,传递 Application

{

SaveApp = Application;

Application = mainApp;

}
// lpCaption 为子窗体的 Caption

TForm1 *Form1 = new TForm1 ( Application, lpCaption );

Form1->Show();
}
注:上面的程序使用 BCB 3.0 编译成功

五. BCB 调用 VC 编写的 DLL
1. 名字分解:

没有名字分解的函数

TestFunction1 // __cdecl calling convention

@TestFunction2 // __fastcall calling convention

TESTFUNCTION3 // __pascal calling convention

TestFunction4 // __stdcall calling convention

有名字分解的函数

@TestFunction1$QV // __cdecl calling convention

@TestFunction2$qv // __fastcall calling convention

TESTFUNCTION3$qqrv // __apscal calling convention

@TestFunction4$qqrv // __stdcall calling convention<br
意法半导体(中国)投资有限公司
2023-06-12 广告
单片机,即单片微控制器,也称为单片微型计算机,是将中央处理器(CPU)、存储器(ROM,RAM)、输入/输出接口和其他功能部件集成在一块 在一个小块的集成电路上,从而实现对整个电路或系统的数字式控制。单片机不是完成某一个逻辑功能的芯片,而是... 点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式