GetProcAddress()失败 GetLastError() 127
来源:互联网 发布:ios降级会清除数据吗 编辑:程序博客网 时间:2024/05/06 08:00
有错误127的代码如下:
#include<windows.h>#include<stdio.h>//#pragma comment(linker,"/export:add=dllA_old.add")HMODULE hModule=NULL; //模块句柄FARPROC proc; //函数入口指针typedef int (__cdecl *Add)(int a,int b);Add padd;BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ){if(NULL==hModule){hModule=LoadLibrary("dllA_old.dll");}if(NULL==hModule){MessageBoxA(NULL,"获取dllA_old.dll失败","caption",0);return 0;} return TRUE;}int add(int a,int b){padd=(Add)GetProcAddress(hModule,"add"); //这里获取函数地址失败 127if(NULL==padd){char msg[256];sprintf(msg,"获取add()失败:%d",GetLastError());MessageBoxA(NULL,msg,"caption",0);return 0;}return padd(a,b);}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
修改方法,就是在add函数中,进行加装dll操作,而不是在dll的入口处加载dll文件,代码如下:
#include<windows.h>#include<stdio.h>//#pragma comment(linker,"/export:add=dllA_old.add")HMODULE hModule=NULL; //模块句柄FARPROC proc; //函数入口指针typedef int (__cdecl *Add)(int a,int b);Add padd;BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ){if(NULL==hModule){hModule=LoadLibrary("dllA_old.dll");}if(NULL==hModule){MessageBoxA(NULL,"获取dllA_old.dll失败","caption",0);return 0;} return TRUE;}int add(int a,int b){hModule=LoadLibrary("dllA_old.dll");//在这里加载哈padd=(Add)GetProcAddress(hModule,"add");if(NULL==padd){char msg[256];sprintf(msg,"获取add()失败:%d",GetLastError());MessageBoxA(NULL,msg,"caption",0);return 0;}return padd(a,b);}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
您的十分满意是我追求的宗旨。
您的一点建议是我后续的动力。
0 0
- GetProcAddress()失败 GetLastError() 127
- LoadLibrary(Ex)失败,GetLastError返回127 (找不到指定的程序)
- GetProcAddress
- GetProcAddress
- GetProcAddress
- GetProcAddress
- GetProcAddress
- GetProcAddress
- GetProcAddress
- GetProcAddress()
- UpdateLayeredWindow()失败,GetLastError()返回0
- Creat 失败,getlasterror返回10093
- GetProcAddress 出错,返回NULL(127)
- 创建线程失败。GetLastError 为 8
- LoadLibrary失败,getlasterror返回126的心得
- Wince LoadLibrary失败,GetLastError= 193
- LoadLibrary加载库失败,getlasterror = 193.
- OpenProcess调用失败,GetLastError返回5
- java.lang.UnsatisfiedLinkError: could not load needed library 'library' : link_image[1963]:
- What Makes Node.js Faster Than Java?
- 蓝桥杯——基础练习之字母图形
- 动手学Android之十——异步任务
- Data Manipulation with R(Phil Spector) 阅读摘要
- GetProcAddress()失败 GetLastError() 127
- HTML输入框优化
- To "windows mobile 5.0 pocket pc device" connection failed 这个产品的配置数据已损坏,请与技术支持人员联系
- 发一个用状态机实现的按键检测是VERILOG代码
- 高通物联网技术解决方案:从汽车到智慧城市
- Leetcode: Decode ways
- 远程调用服务(RPC)和消息(Message Queue)对比及其适用/不适用场合
- 机器学习9(2)推荐系统
- 用GDB调试程序