c++ - DLL 项目中的 C++ 编译错误

标签 c++ dll compiler-errors

这是我的代码:

#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/

相关文章:

.net - 一个 DLL,多个项目?

c - 将 VB 回调函数传递给 C dll - 菜鸟被卡住了

c# - 从 C++ 中的 char* 获取 C# 中的 byte[]

c++ - 对编译器C++ FreeBSD上的符号 'FCGX_InitRequest'的错误 undefined reference

c - 左值错误和数组指针

c++ - 如何在 Eclipse 中运行使用 MinGW 编译的 C++ 程序?如何 "link(?)"?

跨 DLL 的 C++ 全局变量

c++ - 错误: cannot convert `void (*)()' to `float'

c++ - 如何在不引入循环包含的情况下构建它?

c++ - 从文本文件开头的行中删除空格