【发布时间】:2011-08-14 04:51:45
【问题描述】:
我正在创建我的第一个 DLL。 我只有一个单例类和一个 LRESULT CALLBACK 函数,我将在 DLL 中创建并导入我的一个项目。我的 MSVC++ 项目架构由 DLLMain.cpp 文件(未更改)、一个定义单例类和 LRESULT 函数的头文件和一个实现 LRESULT 函数的 cpp 文件组成。
我的问题:项目没有编译。我有 2 个编译错误,我不明白到底是什么错误以及如何修复它。
1>c:\users\testcreatedll\dlltest.h(15):错误 C2059:语法错误:'__declspec(dllexport)'
1>c:\users\testcreatedll\dlltest.h(39): 错误 C2065: 'TestWndProc' : 未声明的标识符
我的头文件:
#ifndef DLLTEST_H
#define DLLTEST_H
#include <windows.h>
// This is from a tutorial I am following
#ifdef _CLASSINDLL
#define CLASSINDLL_CLASS_DECL __declspec(dllexport)
#else
#define CLASSINDLL_CLASS_DECL __declspec(dllimport)
#endif
namespace MyTest
{
LRESULT CALLBACK CLASSINDLL_CLASS_DECL TestWndProc( HWND hwnd, UINT msg, LPARAM lParam, WPARAM wParam );
class CLASSINDLL_CLASS_DECL TestClass
{
// Singleton class
public:
static bool testStaticVar;
static TestClass* getInstance()
{
if ( instance == NULL ) { instance = new TestClass(); }
return instance;
}
void add()
{
myMember++;
}
private:
static TestClass* instance;
WNDPROC myProc;
int myMember;
TestClass() : myMember(0) { myProc = (WNDPROC)&TestWndProc; }
~TestClass() {}
};
}
#endif // DLLTEST_H
我的 cpp 文件:
#include "stdafx.h"
#include "DLLTest.h"
namespace MyTest
{
// Create/Initialise? Class Static variables
bool TestClass::testStaticVar = false;
TestClass* TestClass::instance = NULL;
LRESULT CALLBACK TestWndProc( HWND hwnd, UINT msg, LPARAM lParam, WPARAM wParam )
{
switch (msg)
{
case WM_CREATE:
{
}
break;
default:
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
【问题讨论】:
标签: c++ winapi dll compilation