这篇文章可能不适用于我所知道的64位系统,但它在32位Windows上工作。
我尝试了Gendef,但未能产生DEF文件。在为了我自己的目的而开始编写DLL的目的已经解决了此问题后,我建议使用TINNY_IMPDEF.EXE的TCC,它可以使用。 (TCC = Fabrice Bellard和后来的Grishka的Tiny C编译器。)此外,与DllTool(可能是Gendef)不同,它是否可以使用GCC使用-s来剥离输出DLL!
如果使用GCC,请使用dllTool从def生成 *.a库文件。 TCC将仅使用两条命令行来完成DLL和EXE的整个构建。我有一组命令,可以通过GCC或TCC构建DLL或EXE,并使用所有四个可能的组合。
下面的批处理文件,以随意掠夺...我确定它可以改善,但至少它可以按原样干净工作。
@ECHO OFF
REM This system seems to work regardless of which compiler makes the DLL or the EXE. Try to simplify for GCC.
REM TCC命令。创建3个文件,DLL和DEF,然后再创建EXE。 rem e: coding tcc tcc.exe -shared e: coding tcc xpless test_dll test_dll test_dll.c -oe: coding tcc xpce tcc xpess test_dll test_dll test_dll.dll.dll.dll.dll.dll.dll.dll.dll rem tcc.exe E: Coding tcc 示例 test_dll test_exe.c e: Coding tcc xples test_dll test_dll test_dll.def -oe: coding coding tcc emexps tcc emampes test_dll test_dll test_dll test_dll.exe test_dll.dll.exe
REM GCC命令。警告!仍然需要TCC的tiny_impdef.exe! e: coding gcc bin gcc.exe -s -s -shared -ie: coding gcc include -mwindows e: coding tcc > test_dll test_dll.dll e:编码 tcc “ tiny_impdef.exe” e:编码 tcc 示例 test_dll test_dll.def -le: coding tcc xpless test_dll libtest_dll.a e: coding gcc gcc bin bin bin gcc.exe -s exe -s -s -s -s -s -s -e gcc include -mwindows e: Coding tcc 示例 test_dll test_exe.c e: Coding tcc empples tcc xpless test_dll libtest_dll.a -oe: coding coding tcc tcc empples test_dll test_dll test_dll test_dll test_dll.exe test_dll.exe
启动E:编码 TCC 示例 test_dll test_dll.exe
为了完整性,这是测试dll的C代码:
#include <windows.h>
#define DLL_EXPORT __declspec(dllexport)
DLL_EXPORT void ZoodleWurdle(){
MessageBox (0, "Wurdle", "Zoodle", MB_ICONINFORMATION);
}
DLL_EXPORT void MangleWurzel(){
MessageBox (0, "Mangled", "Wurzels", MB_ICONINFORMATION);
}
抱歉,我必须从某个地方开始,我从不喜欢Foo,Bar,Hello and World ...这是Exe:
#include <windows.h>
void ZoodleWurdle();
void MangleWurzel();
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
ZoodleWurdle(); MangleWurzel();
return 0;
}