初学dll,先记录下问题,不求甚解
win2003+vs2003
代码:
include <iostream>
#include "DLLTutorial.h"
#define? DLL_EXPORT
extern "C"
{
DECLDIR int Add(int a, int b)
{
return a+b;
}
DECLDIR void Function(void)
{
std::cout<<"DLL called!"<<std::endl;
}
};
问题:
正在编译...
DLLTutorial.cpp
f:\hbj\112\112\DLLTutorial.cpp(9) : error C2491: “Add” : 不允许 dllimport 函数 的定义
f:\hbj\112\112\DLLTutorial.cpp(14) : error C2491: “Function” : 不允许 dllimport 函数 的定义
解决:
include <iostream>
#include "DLLTutorial.h"
#define? DLL_EXPORT
顺序反了,
应改为:
#define? DLL_EXPORT
#include <iostream>
#include "DLLTutorial.h"
extern "C"
{
DECLDIR int Add(int a, int b)
{
return a+b;
}
DECLDIR void Function(void)
{
std::cout<<"DLL called!"<<std::endl;
}
};
win2003+vs2003
代码:
include <iostream>
#include "DLLTutorial.h"
#define? DLL_EXPORT
extern "C"
{
DECLDIR int Add(int a, int b)
{
return a+b;
}
DECLDIR void Function(void)
{
std::cout<<"DLL called!"<<std::endl;
}
};
问题:
正在编译...
DLLTutorial.cpp
f:\hbj\112\112\DLLTutorial.cpp(9) : error C2491: “Add” : 不允许 dllimport 函数 的定义
f:\hbj\112\112\DLLTutorial.cpp(14) : error C2491: “Function” : 不允许 dllimport 函数 的定义
解决:
include <iostream>
#include "DLLTutorial.h"
#define? DLL_EXPORT
顺序反了,
应改为:
#define? DLL_EXPORT
#include <iostream>
#include "DLLTutorial.h"
extern "C"
{
DECLDIR int Add(int a, int b)
{
return a+b;
}
DECLDIR void Function(void)
{
std::cout<<"DLL called!"<<std::endl;
}
};