c++ - DLL 中 WINAPI 函数的链接器错误 LNK2001, header 和库都存在,我缺少什么?

标签 c++

我有一个简单的 DLL,我试图在 VS2010 Express 中编译它。 DLL的代码如下:

#pragma comment(linker, "/EXPORT:PlusOne=_PlusOne@4")

#include <windows.h>
#include <commctrl.h>

extern "C"  __declspec(dllexport) int PlusOne(int inNum)
{
    inNum++;
    return inNum;
};

extern "C"  __declspec(dllexport) LRESULT CALLBACK OwnerDrawButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam,
                               LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
//further processing will go here
   return DefSubclassProc(hWnd, uMsg, wParam, lParam);
};

__stdcall在项目选项中被选中

plusOne 函数本身可以正常编译,但第二个函数不能。

DefSubclassProc 是在 commctrl.h 中声明的,但我在该函数上遇到错误,完整的错误文本包括搜索到的库(包括此函数所在的 commdlg32)如下:

1>  Searching libraries
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\winmm.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\kernel32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\user32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\gdi32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\winspool.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\comdlg32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\advapi32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\shell32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\ole32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\oleaut32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\uuid.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\odbc32.lib:
1>      Searching C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\odbccp32.lib:
1>      Searching c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\MSVCRT.lib:
1>      Searching c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\OLDNAMES.lib:
1>  
1>  Finished searching libraries
1>dlltest.obj : error LNK2001: unresolved external symbol _DefSubclassProc@16
1>s:\documents\my documents\visual studio 2010\Projects\dlltest\Release\dlltest.dll : fatal error     LNK1120: 1 unresolved externals

看起来它找不到函数,但是库和 header 都存在,所以我不明白为什么。

顺便说一句,代码的动机是我在 vba 中子类化一个窗口,但是在 vba 中使用窗口过程非常不稳定,所以我想尝试将它移到一个 dll 中。

请帮助我了解这里出了什么问题。

最佳答案

“Comctl32.lib”(不是“commdlg32.lib”)是这个函数“存在”的地方。

参见 MSDN:http://msdn.microsoft.com/en-us/library/windows/desktop/bb776403(v=vs.85).aspx

关于c++ - DLL 中 WINAPI 函数的链接器错误 LNK2001, header 和库都存在,我缺少什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10839447/

相关文章:

c++ - 在类型实例化期间强制触发 static_assert

python - 将结构从 C++ 传递到 Python

c++ - 我应该如何实现我的 C++ 异常?

c++ - 将 vector 值传递给 Eigen 库格式

c++ - g++ 无法识别选项 -wl

c++ - 使用 cmake 添加 _CRT_SECURE_NO_WARNINGS 定义

c++ - 邻接表函数中的段错误

c++ - 如何在 vector<vector<class *>> 中存储类对象并通过引用或值访问它们并将它们传递给函数

c++ - 如何在编译时获得人类可读的复杂表达式类型?

python - 无法编译需要 C99 编译器 (AFAIU) 的 pyethash python 包。错误 - 无法打开包含文件 : 'alloca.h'