这是我的代码:
#include "stdafx.h"
#include <Windows.h>
extern "C" int __stdcall myfunction ();
BOOL WINAPI DllMain ( HINSTANCE hin, DWORD reason, LPVOID lpvReserved );
int __stdcall myfunction ()
{
MessageBoxW(NULL,L"Question",L"Title",MB_OK);
return 0;
}
BOOL WINAPI DllMain ( HINSTANCE hin, DWORD reason, LPVOID lpvReserved )
{
return TRUE;
}
当我编译时显示这些错误:
error LNK2028: reference to simbol (token) unresolved (0A000027) "extern "C" int stdcall MessageBoxW(struct HWND *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) in the function "extern "C" int __stdcall myfunction(void)" (?myfunction@@$$J10YGHXZ)
error LNK2019: External symbol "extern "C" int stdcall MessageBoxW(struct HWND *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) unresolved used in the function "extern "C" int __stdcall myfunction(void)" (?myfunction@@$$J10YGHXZ)
我不明白错误在哪里及其原因。 如果有人可以帮助我修复它,我将非常感谢 :)
最佳答案
谢谢大家,但问题是 user32.lib。
#include "stdafx.h"
#include <Windows.h>
#pragma comment(lib,"user32.lib"); //Missing lib (No compile errors)
BOOL __stdcall DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) {
return TRUE;
}
extern "C" __declspec(dllexport) void __stdcall SomeFunction() {
MessageBoxA(NULL, "Hello", "HELLO", 0x000000L); //0x000000L = MB_OK
}
我希望这对像我这样的菜鸟有帮助。
关于c++ - DLL 项目中的 C++ 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11406598/