以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 C/C++编程思想 』 (http://bbs.xml.org.cn/list.asp?boardid=61) ---- BCB编写DLL终极手册 (http://bbs.xml.org.cn/dispbbs.asp?boardid=61&rootid=&id=68672) |
-- 作者:卷积内核 -- 发布时间:10/24/2008 8:49:00 AM -- BCB编写DLL终极手册 一. 编写 DLL File/New/Dll 生成 Dll 的向导,然后可以添加导出函数和导出类 导出函数:extern "C" __declspec(dllexport) ExportType FunctionName(Parameter) 导出类:class __declspec(dllexport) ExportType ClassName{...} 例子:(说明:只是生成了一个 DLL.dll ) #include "DllForm.h" // TDllFrm 定义 USERES("Dll.res"); class __declspec(dllexport) __stdcall MyDllClass { //导出类 TDllFrm* DllMyForm2; //--------------------------------------------------------------------------- MyDllClass::MyDllClass() void MyDllClass::CreateAForm() __declspec(dllimport) class __stdcall MyDllClass { class TForm1 : public TForm{...} void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) 三. 动态调用 DLL // Unit1.cpp // TForm1 void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) 要把调用程序的 Application 的 Handle 传递给 DLL 的 Application 即可;同时退出 DLL 时也要恢复 Application // MDIChildPro.cpp // Dll 实现 CPP extern "C" __declspec(dllexport) __stdcall void TestMDIChild( //1024X768 五. BCB 调用 VC 编写的 DLL
|
-- 作者:卷积内核 -- 发布时间:10/24/2008 8:50:00 AM -- TESTFUNCTION3$qqrv // __apscal calling convention @TestFunction4$qqrv // __stdcall calling convention 使用 extern "C" 不会分解函数名 使用 Impdef MyLib.def MyLib.DLL 生成 def 文件查看是否使用了名字分解 2. 调用约定: __pascal Pascal格式 __stdcall 标准调用 __fastcall 把参数传递给寄存器 3. 解决调用约定: 4. 使用别名: 5. 动态调用例子 return strRetStdcall; extern "C" __declspec(dllexport) LPSTR __cdecl BCBLoadVCWin32Cdecl() return strRetCdecl; extern "C" __declspec(dllexport) LPSTR __fastcall BCBLoadVCWin32Fastcall() return strRetFastcall; 其实动态调用与调用 BCB 编写的 DLL 没有区别,关键是查看 DLL 的导出函数名字 EXPORT ord:0000='BCBLoadVCWin32Fastcall::' BCBLoadVCWin32Cdecl = (LPSTR (__cdecl *) () ) //Why?不是 'BCBLoadVCWin32Fastcall::',而是 '@BCBLoadVCWin32Fastcall@0'? |
-- 作者:卷积内核 -- 发布时间:10/24/2008 8:51:00 AM -- BCBLoadVCWin32Fastcall = (LPSTR (__fastcall *) () ) //GetProcAddress ( DllInst, "BCBLoadVCWin32Fastcall::" ); GetProcAddress ( DllInst, "@BCBLoadVCWin32Fastcall@0" ); if ( BCBLoadVCWin32Fastcall ) { ShowMessage( BCBLoadVCWin32Fastcall() ); } else ShowMessage ( "Can't find the __fastcall Function!" ); } else ShowMessage ( "Can't find the Dll!" ); } 6. 静态调用例子 Linker 提示不能找到函数的实现 IMPORTS 对应的函数声明和实现如下: void __fastcall TfrmStatic::btnLoadDllClick(TObject *Sender) |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
11,781.250ms |