请教LoadLibrary使用方法!

wzhenhang 2010-08-03 10:34:59
HINSTANCE HInst = LoadLibrary("list.dll");
if(HInst == NULL)
{
cout<<"xxxxxxxxxxxxxxx!\n"<<endl;
return 0;
}
typedef CList* (*create)();
create c;
c = (create)GetProcAddress(HInst,"CreateClist");
if(c == NULL)
{
cout<<"create list failed!\n";
return 0;
}
CList* mylist = c();
if (NULL != mylist)
{
cout << "list construct." << endl;
}
mylist->Insert(3);
我使用如上方法调用LoadLibary函数,成功返回了list类型的实例对象mylist,但是在调用其方法的时候失败!
mylist->Insert(3);
main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall CList::Insert(int)" (__imp_?Insert@CList@@QAE_NH@Z)
Debug/list_dll_test.exe : fatal error LNK1120: 1 unresolved externals

头文件中
extern "C" LIST_API CList* CreateClist();函数用于创建实例对象
LIST_API CList* CreateClist()
{
CList *mylist = new CList;
return mylist;
}
请问这是什么原因?是不是因为C与C++函数名重载相关的原因?是不是这样就表示不能通过loadlibary的方法调用dll中的类?
...全文
738 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
芸香传奇 2011-08-18
  • 打赏
  • 举报
回复
没有看懂。。。
  • 打赏
  • 举报
回复
学习中。。。。我给你顶
悟迟 2010-08-03
  • 打赏
  • 举报
回复
谢谢楼主结贴
Eleven 2010-08-03
  • 打赏
  • 举报
回复
解决??
wzhenhang 2010-08-03
  • 打赏
  • 举报
回复
蛋疼
class LIST_API CList {
private:
typedef struct list {
int item;
struct list *nextPtr;
} List;
List *headPtr, *tailPtr;
public:
CList(void);
~CList(void);
virtual bool Insert(int value); // insert a value to list

virtual bool Delete(int value); // delete a value from list

virtual void Show(void)const; // show list

// TODO: add your methods here.
};
需要将类的函数声明为虚函数,来人送分结贴

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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