关于DLL调用

来源:百度知道 编辑:UC知道 时间:2024/05/31 10:43:29
void CMy2Dlg::On_opendll()
{
// TODO: Add your control notification handler code here
HINSTANCE h;
h=::LoadLibrary("dll.dll");//装入DLL
::GetProcAddress(h,"hide");
::FreeLibrary(h);//释放DLL
}

void CMy2Dlg::OnButton5()
{
// TODO: Add your control notification handler code here
HINSTANCE h;
h=::LoadLibrary("dll.dll");
::GetProcAddress(h,"show");
::FreeLibrary(h);
}

dll 的cpp文件
CDllApp::CDllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance

}

/////////////////////////////////////////////////////////////////////////////
// The one and only CDllApp object
CDllApp theApp;

CDllApp::show()
{
HWND h=::FindWindow("Shell_TrayWnd",NULL);
::ShowWindow(h,SW_SHOW);

}

CDllApp::hide()
{
HWND

::GetProcAddress(h,"hide");
之后只是获得了函数的地址,应该再调用一下才能让函数的功能实现。
如果放到CdllApp中可以运行是因为在装载的过程中直接调用它.

另外你再看一下你在dll中的声明对么
它的声明和普通的exe文件的声明不同,需要在前面加东西

以下为例:
如果你在dll中定义的是 int add(int a,int b);这么一个函数
在调用的时候,你首先返回地址,这个你已经做了
然后就是
typedef int (myreturn)(int a,int b);
FARPORC procaddr=(myreturn)::GetProcAddress();
int result=myreturn(2,4);

::GetProcAddress 支持获取函数地址,没有调用函数

要配置dll中函数声明时 加 __declspec(dllexport)

0分的只能说这么多了 ,哈哈

dll.dll这个文件要放在同一目录,或者你放到windows\system32里面