参考:http://baike.baidu.com/view/1340740.htm
参考:http://stackoverflow.com/questions/14361992/dll-load-library-error-code-126
例如DLL加载操作:
加载失败时,通过GetLastError获取失败原因:报错 126|无法找到指定模块
1. 使用GetLastError()获取错误码
注意:出现错误,需要立即获取错误码,否则可能就会丢失错误码信息。
You should call the GetLastError function immediately when a function's return value indicates that such a call will return useful data. That is because some functions callSetLastError(0) when they succeed, wiping out the error code set by the most recently failed function.
2. 使用FormatMessage获取Error值对应的字符串解释
{
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
sPrompt.Format(_T("Load Library falied<ErrorReason = %d|%s>!"), dw, lpMsgBuf);
LocalFree(lpMsgBuf);
}
3. 获取加载失败缺失的dll,有下面两种方法
a. 使用 Dependency查找缺失的dll Use dependency walker to look for any obvious problems (which you have already done)
b. 使用微软提供的工具"utility Process",查看执行的过程,找出丢失的文件,Use the sysinternals utility Process Monitorhttp://technet.microsoft.com/en-us/sysinternals/bb896645 from Microsoft to trace all file access while your dll is trying to load. With this utility, you will see everything that that dll is trying to pull in and usually the problem can be determined from there.
像下面这种报错信息,显示在各个path目录去找dll文件,都没有找到
14:03:00.5985372 CallSelectCity.exe 4600 CreateFile C:\Windows\SysWOW64\ac1st17.dll NAMENOT FOUND Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
14:03:00.5988220 CallSelectCity.exe 4600 CreateFile C:\Windows\system\ac1st17.dll NAME NOT FOUND Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
14:03:00.5989958 CallSelectCity.exe 4600 CreateFile C:\Windows\ac1st17.dll NAME NOT FOUND Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu 转载请标明来源