请教高手,SymInitialize()和SymLoadModule()这两个函数怎么用?

swbreath 2004-09-03 09:39:20
请问这两个函数是干什么用的,大体是什么功能,那里有具体一点的介绍,在msdn上看了半天还是没有明白是什么意思,在此小弟先谢了,

我重新写了一个小个程序,就出现下列情况,
testsym.obj : error LNK2001: unresolved external symbol __imp__SymInitialize@12
Debug/testsym.exe : fatal error LNK1120: 1 unresolved externals
是怎么回事呀!谢谢!
...全文
901 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
swbreath 2004-09-06
  • 打赏
  • 举报
回复
DentistryDoctor,牙科医生兄你说的MSDN0209期的buglayers中有详细的从事贸易子,在那里能找到相关的资料,小弟先谢了!
Coder 青田 2004-09-06
  • 打赏
  • 举报
回复
SymInitialize
The SymInitialize function initializes the symbol handler for a process.

BOOL SymInitialize(
IN HANDLE hProcess,
IN LPSTR UserSearchPath,
IN BOOL fInvadeProcess
);

Parameters
hProcess
Handle to the process for which symbols are to be maintained. If the application is a debugger, use the process handle for the object being debugged, otherwise use the GetCurrentProcess function to obtain the process handle.
UserSearchPath
Pointer to a null-terminated string that specifies a path, or series of paths separated by a semicolon (;), that is used to search for symbol files. If a value of NULL is used, then ImageHlp attempts to form a symbol path from the following sources:
Current directory
Environment variable _NT_SYMBOL_PATH
Environment variable _NT_ALTERNATE_SYMBOL_PATH
Environment variable SYSTEMROOT
fInvadeProcess
If this value is TRUE, ImageHlp enumerates the loaded modules for the process and effectively calls the SymLoadModule function for each module.
Return Values
If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError.

Remarks
The SymInitialize function is used to initialize the symbol handler for a process. In the context of the symbol handler, a process is a convenient object to use when collecting symbol information. Usually, symbol handlers are used by debuggers and other tools that need to load symbols for a process being debugged.

///////////////////////////////////////////////


SymLoadModule
The SymLoadModule function loads the symbol table.

BOOL SymLoadModule(
IN HANDLE hProcess,
IN HANDLE hFile,
IN LPSTR ImageName,
IN LPSTR ModuleName,
IN DWORD BaseOfDll,
IN DWORD SizeOfDll
);

Parameters
hProcess
Handle to the process that was originally passed to the SymInitialize function.
hFile
Handle to the file for the executable image. This argument is used mostly by debuggers, where the debugger passes the file handle obtained from a debug event. A value of NULL indicates that hFile is not used.
ImageName
Pointer to a null-terminated string that specifies the name of the executable image. This name can contain a partial path, a full path, or no path at all. If the file cannot be located by the name provided, the symbol search path is used.
ModuleName
Pointer to a null-terminated string that specifies a shortcut name for the module. If the pointer value is NULL, ImageHlp creates a name using the base name of the symbol file.
BaseOfDll
Specifies the load address of the module. If the value is zero, ImageHlp obtains the load address from the symbol file. The load address contained in the symbol file is not necessarily the actual load address. Debuggers and other applications having an actual load address should use the real load address when calling this function.
SizeOfDll
Specifies the size of the module. If the value is zero, ImageHlp obtains the size from the symbol file. The size contained in the symbol file is not necessarily the actual size. Debuggers and other applications having an actual size should use the real size when calling this function.
Return Values
If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError.

Remarks
The symbol handler creates an entry for the module and if the deferred symbol loading option is turned off, an attempt is made to load the symbols. If deferred symbol loading is enabled, the module is marked as deferred and the symbols are not loaded until a reference is made to a symbol in the module.

To unload the symbol table, use the SymUnloadModule function.



DentistryDoctor 2004-09-06
  • 打赏
  • 举报
回复
#pragma comment (lib,"imagehlp.lib"),
DentistryDoctor 2004-09-06
  • 打赏
  • 举报
回复
这两个函数的使用,MSDN0209期的buglayers中有详细的从事贸易子。
pigo 2004-09-06
  • 打赏
  • 举报
回复

up :)
holyeagle 2004-09-04
  • 打赏
  • 举报
回复
对了例子编译的时候会有
Error Message: C2668: InlineIsEqualGUID: Ambiguous Call to Overloaded Function
这个编译错误,把每个InlineIsEqualGUID改为::ATL::InlineIsEqualGUID() ,这是因为SDK和alt空间的名字空间问题。
holyeagle 2004-09-04
  • 打赏
  • 举报
回复
http://www.microsoft.com/china/MSDN/library/windev/COMponentdev/ACOMSymbolEngineAidsDebugging.mspx
MS的中文介绍,还有相关例子
深圳万兴 2004-09-04
  • 打赏
  • 举报
回复
关注中
Kudeet 2004-09-04
  • 打赏
  • 举报
回复
Header: Declared in Dbghelp.h.
Library: Use Dbghelp.lib.


# include <Dbghelp.h>
#pragma comment(lib, "Dbghelp.lib")
swbreath 2004-09-04
  • 打赏
  • 举报
回复
而且不能加# include <Dbghelp.h>
如果加了dbghelp.h的话,将会出现大量的错误!
我用的是#include <Imagehlp.h>
请问#include <Imagehlp.h>和dbghelp.h有区别吗?我是指就运行SymInitialize()和SymLoadModule()这两个函数而言,谢谢
kpld8888 2004-09-04
  • 打赏
  • 举报
回复
Up
swbreath 2004-09-04
  • 打赏
  • 举报
回复
谢谢上面的高人,但是问题还没有完全解决。能在指点指点吗?
我写了一个简单的程序,
main(int argc,char *argv[] )
{
int err;
HANDLE dhandle;

printf("this is test\n");
printf("argv[0]:%s,argv[1]:%s\n",argv[0],argv[1]);

//dhandle = GetCurrentProcess();
//SymInitialize(dhandle,"",FALSE);

if(!SymInitialize(GetCurrentProcess(),"",FALSE))
{
err=GetLastError();
printf("Failed Initailize Process Symbol table,WIN32 Errcd:%d",err);
return 0;
}
if(!SymLoadModule(GetCurrentProcess(),NULL,argv[0],NULL,0,0))
{
err=GetLastError();
printf("Failed load symbol filename:%s,WIN32 Errcd:%d",argv[0],err);
return 0;
}
}

dbghelp.lib是在vc的开发环境中设置的,现在问题出现了,我在vc的开发环境下运行没有问题,但是我直接在console下,键入命令就出现问题了
C:\vctest\testmain\Debug>testmain
this is test
argv[0]:testmain,argv[1]:(null)
Failed load symbol filename:testmain,WIN32 Errcd:0
或者
C:\vctest\testmain\Debug>C:\vctest\testmain\Debug\testmain
this is test
argv[0]:C:\vctest\testmain\Debug\testmain,argv[1]:(null)
Failed load symbol filename:C:\vctest\testmain\Debug\testmain,WIN32 Errcd:0
再次感谢
flyelf 2004-09-03
  • 打赏
  • 举报
回复
#pragma comment(lib, " Dbghelp.lib")

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧