如何根据函数的地址来调用函数? 是这样的:HMODULE hD3D9 = LoadLibrary("Kernel32.dll");LPVOID pSystemDirectory =GetProcAddress(hD3D9,"GetSystemDirectory");//函数的地址已经找到了 请问怎么根据pSystemDirectory 来调用GetSystemDirectory函数? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GetSystemDirectory 的函数原型如果是 int GetSystemDirectory(int param);typedef (* int GetSYSDIR)(int param);GetSYSDIR GetSysDir;GetSysDir =GetProcAddress(hD3D9,"GetSystemDirectory");int m = GetSysDir (1); 就可以调用了 typedef UINT (WINAPI* PFNGetSystemDirectory)(LPTSTR lpBuffer, UINT uSize);HMODULE hD3D9 = LoadLibrary("Kernel32.dll");PFNGetSystemDirectory pSystemDirectory =(PFNGetSystemDirectory)GetProcAddress(hD3D9,"GetSystemDirectory"); 不对啊函数原型:IDirect3D9 * Direct3DCreate9( UINT SDKVersion);typedef (*IDirect3D9 MyDirect3DCreate9)(UINT SDKVersion );C:\1\hxwdllwx\hxwdllwx.cpp(10) : error C2146: syntax error : missing ')' before identifier 'MyDirect3DCreate9'C:\1\hxwdllwx\hxwdllwx.cpp(10) : error C2146: syntax error : missing ';' before identifier 'MyDirect3DCreate9'C:\1\hxwdllwx\hxwdllwx.cpp(10) : error C2040: 'IDirect3D9' : 'int *' differs in levels of indirection from 'struct IDirect3D9'C:\1\hxwdllwx\hxwdllwx.cpp(10) : fatal error C1004: unexpected end of file found LS正解,不过有个笔误,typedef (* int GetSYSDIR)(int param); 改为 typedef (int *GetSYSDIR)(int param);然后在赋值时加个类型转换 GetSysDir = (GetSYSDIR)GetProcAddress(hD3D9,"GetSystemDirectory"); #include "stdafx.h"#include <Windows.h>#include <tchar.h>typedef UINT (WINAPI* PFNGetSystemDirectory)(LPWSTR lpBuffer, UINT uSize);int main(){ HMODULE hD3D9 = LoadLibrary("Kernel32.dll"); if(hD3D9) { PFNGetSystemDirectory pFn = (PFNGetSystemDirectory)GetProcAddress(hD3D9, "GetSystemDirectoryW"); if(pFn) { WCHAR buf[MAX_PATH] = {0}; pFn(buf, MAX_PATH); wprintf(L"%s\n", buf); } FreeLibrary(hD3D9); } return 0; } Kernel32.dll中导出的GetSystemDirectoryA和GetSystemDirectoryW这两个函数,不是GetSystemDirectory 哈哈其实我要调用的是由 d3d9.dll导出的 Direct3DCreate9 函数IDirect3D9 * Direct3DCreate9( UINT SDKVersion); 直接调用不行吗?还从kernel32.dll中导出? 比如话: 我要调用的是GetSystemDirectory 因为我已经在我的程序里封装了一个GetSystemDirectory函数 如果直接调用的话不就是调用了自己封装的那个函数了吗 ::GetSystemDirectory();使用作用域标识符 还是重复调用自己的函数 MessageBox个不停 IDirect3D9 * WINAPI Direct3DCreate9(UINT SDKVersion){ MessageBox(0,"拦截到了",0,0); ::Direct3DCreate9(SDKVersion); return 0;} 难道要这样?执行到 Direct3DCreate9函数时 调用另外一个DLL导出的函数然后sleep 将自己重命名另外一个DLL就执行Direct3DCreate9 这时执行的就是system32里面的d3d9.dll 导出的函数这样啊? 麻烦了点 IDirect3D9 * WINAPI Direct3DCreate9(UINT SDKVersion){ MessageBox(0,"拦截到了",0,0); char chPath[MAX_PATH]; GetSystemDirectory(chPath,MAX_PATH); strcat(chPath,"\\d3d9.dll"); HMODULE hD3D9 = LoadLibrary(chPath); if (hD3D9 == NULL) { MessageBox(0,"failed",0,0); } LPVOID pDirect3DCreate9 =GetProcAddress(hD3D9,"Direct3DCreate9"); if (pDirect3DCreate9 == NULL) { MessageBox(0,"GetProcAddress Failed",0,0); } _asm { mov eax,SDKVersion mov ecx ,pDirect3DCreate9 call ecx } return 0;}内联汇编也可以啊不过调用约定那些麻烦 不知道怎么搞了 哈哈 我也刚想到内联汇编的但是调用约定 堆栈平衡那些就麻烦了 函数原型是:IDirect3D9 * Direct3DCreate9( UINT SDKVersion);约定是 _stdcall 右至左 压栈 PUSHAD POPAD 还是崩溃ingIDirect3D9 * WINAPI Direct3DCreate9(UINT SDKVersion){ __asm pushad MessageBox(0,"拦截到了",0,0); char chPath[MAX_PATH]; GetSystemDirectory(chPath,MAX_PATH); strcat(chPath,"\\d3d9.dll"); HMODULE hD3D9 = LoadLibrary(chPath); if (hD3D9 == NULL) { MessageBox(0,"failed",0,0); } LPVOID pDirect3DCreate9 =GetProcAddress(hD3D9,"Direct3DCreate9"); if (pDirect3DCreate9 == NULL) { MessageBox(0,"GetProcAddress Failed",0,0); } _asm { mov eax,SDKVersion mov ecx ,pDirect3DCreate9 call ecx } __asm popad return 0;} 一个怪异的问题客户端使用ADO连接SQLSERVER2000问题 问下下划线 ‘_’的虚拟键值是多少。。。 怎样能把对话框上的还原功能取消? 如何实现windows搜索里面的那个动画角色。 面试问题!!!!!!! Visual C++未来发展趋势 (三)请 ljn2(没有人2 (账户惨被封))来接分,感谢你回答问题,我日,终于搞定了,版主不要删啊~ w_mac(wendy) BCB_FANS(四大名捕之追杀令) 进来领分,非常感谢。 3 请问怎样让Edit控件只能输入数字(包括小数点)? 高手救命!! 如何恢复VC2008资源视图中误删内容? gsoap代理的结构体如何转换成XML字符串
typedef (* int GetSYSDIR)(int param);
GetSYSDIR GetSysDir;
GetSysDir =GetProcAddress(hD3D9,"GetSystemDirectory");int m = GetSysDir (1); 就可以调用了
PFNGetSystemDirectory pSystemDirectory =(PFNGetSystemDirectory)GetProcAddress(hD3D9,"GetSystemDirectory");
不对啊
函数原型:
IDirect3D9 * Direct3DCreate9(
UINT SDKVersion
);
typedef (*IDirect3D9 MyDirect3DCreate9)(UINT SDKVersion );
C:\1\hxwdllwx\hxwdllwx.cpp(10) : error C2146: syntax error : missing ')' before identifier 'MyDirect3DCreate9'
C:\1\hxwdllwx\hxwdllwx.cpp(10) : error C2146: syntax error : missing ';' before identifier 'MyDirect3DCreate9'
C:\1\hxwdllwx\hxwdllwx.cpp(10) : error C2040: 'IDirect3D9' : 'int *' differs in levels of indirection from 'struct IDirect3D9'
C:\1\hxwdllwx\hxwdllwx.cpp(10) : fatal error C1004: unexpected end of file found
改为 typedef (int *GetSYSDIR)(int param);
然后在赋值时加个类型转换 GetSysDir = (GetSYSDIR)GetProcAddress(hD3D9,"GetSystemDirectory");
#include "stdafx.h"
#include <Windows.h>
#include <tchar.h>typedef UINT (WINAPI* PFNGetSystemDirectory)(LPWSTR lpBuffer, UINT uSize);
int main()
{
HMODULE hD3D9 = LoadLibrary("Kernel32.dll");
if(hD3D9)
{
PFNGetSystemDirectory pFn = (PFNGetSystemDirectory)GetProcAddress(hD3D9, "GetSystemDirectoryW");
if(pFn)
{
WCHAR buf[MAX_PATH] = {0};
pFn(buf, MAX_PATH);
wprintf(L"%s\n", buf);
}
FreeLibrary(hD3D9);
}
return 0;
}
其实我要调用的是由 d3d9.dll导出的 Direct3DCreate9 函数
IDirect3D9 * Direct3DCreate9(
UINT SDKVersion
);
函数 如果直接调用的话不就是调用了自己封装的那个函数了吗
{
MessageBox(0,"拦截到了",0,0);
::Direct3DCreate9(SDKVersion);
return 0;
}
执行到 Direct3DCreate9函数时 调用另外一个DLL导出的函数
然后sleep 将自己重命名
另外一个DLL就执行Direct3DCreate9 这时执行的就是system32里面的d3d9.dll 导出的函数
这样啊? 麻烦了点
{
MessageBox(0,"拦截到了",0,0);
char chPath[MAX_PATH];
GetSystemDirectory(chPath,MAX_PATH);
strcat(chPath,"\\d3d9.dll");
HMODULE hD3D9 = LoadLibrary(chPath);
if (hD3D9 == NULL)
{
MessageBox(0,"failed",0,0);
}
LPVOID pDirect3DCreate9 =GetProcAddress(hD3D9,"Direct3DCreate9");
if (pDirect3DCreate9 == NULL)
{
MessageBox(0,"GetProcAddress Failed",0,0);
}
_asm
{
mov eax,SDKVersion
mov ecx ,pDirect3DCreate9
call ecx
}
return 0;
}
内联汇编也可以啊不过调用约定那些麻烦 不知道怎么搞了
哈哈 我也刚想到内联汇编的但是调用约定 堆栈平衡那些就麻烦了
函数原型是:
IDirect3D9 * Direct3DCreate9(
UINT SDKVersion
);
约定是 _stdcall
IDirect3D9 * WINAPI Direct3DCreate9(UINT SDKVersion)
{
__asm pushad
MessageBox(0,"拦截到了",0,0);
char chPath[MAX_PATH];
GetSystemDirectory(chPath,MAX_PATH);
strcat(chPath,"\\d3d9.dll");
HMODULE hD3D9 = LoadLibrary(chPath);
if (hD3D9 == NULL)
{
MessageBox(0,"failed",0,0);
}
LPVOID pDirect3DCreate9 =GetProcAddress(hD3D9,"Direct3DCreate9");
if (pDirect3DCreate9 == NULL)
{
MessageBox(0,"GetProcAddress Failed",0,0);
}
_asm
{
mov eax,SDKVersion
mov ecx ,pDirect3DCreate9
call ecx
}
__asm popad
return 0;
}