在MFC程序里,EXE程序,如何能得到自定义的函数地址?

来源:百度知道 编辑:UC知道 时间:2024/05/06 07:36:47
比如:
void MyTestApp::MyFunction() //我想要得到地址的函数
{}

void MyTestApp::Buttion() //一个按钮,在里面想得到上面的函数地址
{
//我想用这样的方法得到MyFunction函数地址
DWORD addr = (DWORD)MyFunction;
//上面这句为什么不行呢?编译时出错!
}

有什么办法能使用上面类似的方法,得到函数地址?
谢谢!

直接(int *)MyFunction就是函数的地址了
void MyTestApp::Buttion()
{
int addr = (int *)MyFunction;
}

HINSTANCE hInst = LoadLibrary("User32.DLL");
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF, BYTE, DWORD);
MYFUNC fun = NULL;
//取得SetLayeredWindowAttributes函数指针
fun = (MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if (fun)
{
fun(this->GetSafeHwnd(), 0, 220, 2);
}
FreeLibrary(hInst);
}
这个只能获得dll里面的函数

DWORD addr = (DWORD)MyFunction;
换成DWORD addr = (DWORD)this->MyFunction;

我再vc6里试了编译通过
你没有include "windows.h"吧

C++ 建议去微软的中文论坛看看

&MyTestApp::MyFunction