一个dll动态库的问题

wangyan0512 2003-04-24 09:57:00
MYDLL.CPP (源文件)

#include"MyDll.h"

int WINAPI DllMain ( HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
return TRUE ;
}

EXPORT int CALLBACK Max(int a, int b)
{
if(a>=b)
{
return a;
}
else
{
return b;
}
}

EXPORT int CALLBACK Min(int a, int b)
{
if(a>=b)
{
return b;
}
else
{
return a;
}
}


头文件 :MYDLL.H
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif


EXPORT int CALLBACK Max(int a, int b);
EXPORT int CALLBACK Min(int a, int b);

提示出错:
Compiling...
MyDll.cpp
d:\vc\c\c_dll\mydll\mydll\mydll.h(8) : error C2146: syntax error : missing ';' before identifier 'Max'
d:\vc\c\c_dll\mydll\mydll\mydll.h(8) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

MyDll.obj - 2 error(s), 0 warning(s)
...全文
22 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
siriuswmx 2003-04-27
  • 打赏
  • 举报
回复
高手,你能不能看看我的问题“如何在BC中生成dll文件?”谢谢
wangyan0512 2003-04-27
  • 打赏
  • 举报
回复
我直接引入头文件,调用函数的
wangyan0512 2003-04-24
  • 打赏
  • 举报
回复
加上windows.h后,编译不在报错,但调用时出错,提示如下:
Compiling...
use_dll.cpp
d:\work\use_dll\mydll.h(8) : error C2146: syntax error : missing ';'

before identifier 'Max'
d:\work\use_dll\mydll.h(8) : fatal error C1004: unexpected end of

file found
Error executing cl.exe.

use_dll.obj - 2 error(s), 0 warning(s)
  • 打赏
  • 举报
回复
你所使用的某些关键字定义在windows.h中
wangyan0512 2003-04-24
  • 打赏
  • 举报
回复
但是,你说一下,我出错的原因吗?
  • 打赏
  • 举报
回复
呵呵,你的程序我在VC6.0下已经可以顺利编译通过!
wangyan0512 2003-04-24
  • 打赏
  • 举报
回复
--------------------Configuration: dll - Win32 Debug--------------------
经过修改后,还是有错,提示如下:

Compiling...
MyDll.cpp
d:\work\试验dll\dll\dll\mydll.h(8) : error C2146: syntax error : missing ';' before identifier 'Max'
d:\work\试验dll\dll\dll\mydll.h(8) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

MyDll.obj - 2 error(s), 0 warning(s)
  • 打赏
  • 举报
回复
#include <windows.h> //少了!而且注意包含顺序!这个要在最前面!
#include"MyDll.h"

int WINAPI DllMain ( HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
return TRUE ;
}

EXPORT int CALLBACK Max(int a, int b)
{
if(a>=b)
{
return a;
}
else
{
return b;
}
}

EXPORT int CALLBACK Min(int a, int b)
{
if(a>=b)
{
return b;
}
else
{
return a;
}
}
keenleung 2003-04-24
  • 打赏
  • 举报
回复
头文件 :MYDLL.H
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllimport) //从CPP文件中导入
#else
#define EXPORT __declspec (dllimport)
#endif
//下面的导出函数声明不变
...

MYDLL.CPP (源文件)
#include"MyDll.h"

#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport) //从这里导出
#else
#define EXPORT __declspec (dllexport)
#endif
//下面的导出函数定义不用带EXPORT关键字
int CALLBACK Max(int a, int b)
{
if(a>=b)
{
return a;
}
else
{
return b;
}
}


Try it!





  • 打赏
  • 举报
回复
那应该与dll无关,因为我已经试过了,没有任何问题!VC6.0下
你是如何调用的?

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧