调用DLL例子中使用LoadLibrary方法//怎么还需要DLL的头文件???

mirroatl239 mirroatl239 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

[code=c]
void CTestDllDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
typedef CExportTest* (*lpCall)(CExportTest*);
typedef int (*fCall)(void);
//创建dll句柄
HINSTANCE hDll;
//装载dll
CExportTest* pInput = new CExportTest();
pInput->m_i = 2;
hDll = LoadLibrary(_T("DllInstenceMfc.dll"));
if(NULL==hDll)
{
AfxMessageBox(_T("DLL加载失败!"));
}
//检索指定DLL中的输出库函数地址
lpCall pFunc = NULL;
fCall pFI = NULL;
pFunc =(lpCall)GetProcAddress(hDll,(LPCSTR)"ExportClass");
pFI = (fCall)GetProcAddress(hDll,(LPCSTR)"TestFunc");
if(NULL==pFunc)
{
AfxMessageBox(_T("DLL内部函数调用失败!"));
}
if(NULL==pFI)
{
AfxMessageBox(_T("DLL内部函数TestFunc调用失败!"));
}
//创建DLL对话框
CExportTest* pDll = pFunc(pInput);
if(pDll != NULL)
{
int i = pDll->ExportInt();
CString str;
str.Format(_T("%d"),i);
AfxMessageBox(str);
}
if(pFI != NULL)
{
int x = pFI();
CString str;
str.Format(_T("%d"),x);
AfxMessageBox(str);
}
FreeLibrary(hDll);
delete pInput;
}



下面代码不使用编译不过啊

#pragma once
class CExportTest
{
public:
CExportTest(void);
virtual ~CExportTest(void);
public:
virtual int ExportInt();
//virtual int ExportStr(int x) = 0;
public:
int m_i;
};

#include "StdAfx.h"
#include "ExportTest.h"


CExportTest::CExportTest(void)
{
m_i = 1;
}


CExportTest::~CExportTest(void)
{
}

int CExportTest::ExportInt(void)
{
return m_i;
}


[/code]
...全文
评论 10
收藏 已收藏
分享
返回顶部
mirroatl239
进程/线程/DLL 15,466 成员 49,169 内容