第一次编译后,输出 如下,--------------------Configuration: Tesgine - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
LINK : fatal error LNK1561: entry point must be defined
Error executing cl.exe.XXX.dll - 1 error(s), 0 warning(s)===========================
再按f7编译,就能通过了。请问为什么会这样?怎么解决?
Compiling resources...
Compiling...
StdAfx.cpp
LINK : fatal error LNK1561: entry point must be defined
Error executing cl.exe.XXX.dll - 1 error(s), 0 warning(s)===========================
再按f7编译,就能通过了。请问为什么会这样?怎么解决?
Error Message
entry point must be defined
The linker did not find an entry point. You may have intended to link as a DLL, in which case you should link with the /DLL option. You may have also forgotten to specify the name of the entry point; link with the /ENTRY option. Otherwise, you should include a main, wmain, WinMain, or wMain function in your code.If you are using LIB and intend to build a .dll, one reason for this error is that you supplied a .def file. If so, remove the .def file from the build.
目前的问题就是RebuiltAll后找到入口函数,再按F7后可能找到,如果还找不到再找F7,试几就找到了。
目前的问题就是RebuiltAll后找到入口函数,再按F7后可能找到,如果还找不到再找F7,试几就找到了。
#include <windows.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}extern "C" declspec(dllexport) void myfunc1(void){
MessageBox(NULL,TEXT("myfuc run..."),TEXT("note"),MB_OK);
return;
}调用DLL的程序文件
#include <windows.h>
void(*pmyfunc)(void);int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LPSTR lpMod = TEXT("c:\\mydll.dll");//改成DLL路径
HMODULE hMod = (HMODULE)LoadLibrary(lpMod);
pmyfunc = (void(*)(void))GetProcAddress(hMod, TEXT("myfunc1"));
pmyfunc(); return 0;
}你的源码没贴出来,不好判断。
我估计:
1,如果你是显示加载的DLL(调用LoadLibrary),那就是在GetProcAddress函数中写错了DLL中的函数名。
2,如果你是隐式加载的DLL,那么DLL中的函数声明应该在你的程序中声明为
extern "C" _declspec(dllimport) void myfunc1(void);我写了个示例,但没有亲自验证,应该可以正确执行。你和你的程序对照一下,看哪里不正确。
我确实使用了LIB,而且是在编译为DLL,工程中存在DEF文件,但是我删除了DEF文件,仍然不行。PS:VC6.0
在APP中声明DLL中的函数是否正确?
extern "C" _declspec(dllimport)
使用的LIB为静态库,不需要import
RELEASE 方式编译时, .DEF 文件需要放在RELEASE文件夹中。