如何产生一个只有资源没有DllMain()的DLL
用VC产生一个DLL,加入rc文件,删掉.c和.h文件,加入rc文件对应的resource.h头文件。
1、新建工程Win32 Dynamic-Link Library,一个空的工程,选择相应的生成路径和工程名字。
2、添加 ****.rc 和 resource.h的头文件,进行修改操作。
3、添加编译设置Configurations。 步骤:Build -> Configurations->Add。 若添加UDebug,则
在Copy Setting from 选择 Debug;URelease 同理 Release。
4、分别设置UDebug 和URelease 的属性设置。 Project->Setting->C/C++->Catrgory:
Preprocessor ,在Preprocessor definitions 中添加 _UNICODE,UNICODE
其中,URelease中添加NDEBUG,UDebug是_DEBUG 。
5、有时还要替换掉原有文件中包含过去resource.h。比如stdafx.h 等。
编译,连接错误:
LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12
查MSDN文章:DLL for Beginners. 如果一个DLL没有DllMain()--(当然这个DllEntry可以在VC的编译选项里指定,或者/DllEntry:FuncName。),编译器自动使用C Runtime Library的DllMainCRTStartup().
加入msvcrt.lib 或msvcrtd.lib (for debug mode),编译通过。这个DLL没有显式的DllMain().
注意:
有时会报错误 cmd.exe 无法运行。
则是 Project->Setting->post-build step 的路径设置错误
UDebug的情况下:
copy .\UDebug\pollmodifierres.dll ..\..\..\public\binv4\URelease
URelease的情况下:
copy .\URelease\pollmodifierres.dll ..\..\..\public\binv4\URelease
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The KB article is apply to the previous version of VC, in visual studio 2005, there is a little different on how to set the configurations. but the principle under the configuration is the same.
To solve it, do the following steps:
1. Open project property pages by Alt+F7
2. Navigate to Configuration properties->Linker->Input section.
3. Add msvcrtd.lib; mfcs80ud.lib to the Ignore specific library.
4. Add mfcs80ud.lib msvcrtd.lib to the Additional dependencies.
Now we will tell you how to find out these two disorder libraries. In the project property pages, navigate to configuration properties->linker->command line, add /verbose:lib to the additional option. Rebuild your project, and look carefully to the output window, you will find that is mfcs80ud.lib generated the link error, look before mfcs80ud.lib, you will find there is only one CRT library before it, so ignore these 2 libraries in the Ignore specific library, then add them in the additional dependencies with right order. Rebuild again, it should works.