读书人

error C2146解决方法

发布时间: 2012-11-10 10:48:51 作者: rapoo

error C2146
错误信息
1>CustomDll.cpp
1>d:\我的文档\visual studio 2008\projects\customdll\customdll\customdll.h(6) : error C2146: 语法错误 : 缺少“;”(在标识符“DLLFuncAdd”的前面)
1>d:\我的文档\visual studio 2008\projects\customdll\customdll\customdll.h(6) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\我的文档\visual studio 2008\projects\customdll\customdll\customdll.h(6) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

C/C++ code
customdll.h#ifdef CustomDLL_EXPORTS#define CustomDLL_API_declspec(dllexport)#else#define CustomDLL_API_declspec(dllimport)#endifCustomDLL_APIint DLLFuncAdd(int a,int b);

C/C++ code
customdll.c#include "CustomDll.h"#include <windows.h>BOOL APIENTRY DllMain(HMODULE hModule,DWORD ul_reason_for_call,LPVOID lpReserved){    switch(ul_reason_for_call)    {        //动态链接库被映射到某个进程的地址空间    case DLL_PROCESS_ATTACH:        //应用程序创建新的线程    case DLL_THREAD_ATTACH:        //应用程序某个线程正常终止    case DLL_THREAD_DETACH:        //动态链接库将被卸载    case DLL_PROCESS_DETACH:        break;    }    return TRUE;}//自定义导出函数,求两个整数的和int DLLFuncAdd(int a,int b){    return a+b;}


这是抄的书上的代码,但运行错误,求助

[解决办法]

CustomDLL_APIint是什么?
是CustomDLL_API int么?
另外

#define CustomDLL_API_declspec(dllexport)
应该写成
#define CustomDLL_API __declspec(dllexport)

读书人网 >C++

热点推荐