查找DLL名称 [英] Find the DLL name

查看:59
本文介绍了查找DLL名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hI,

我在运行时加载了2个DLL.但是我想在函数调用中添加一个日志,以了解函数调用的起源. (即)函数A可以一直从DLL A调用,而函数B可以一直从DLL B调用.是否有任何功能可以打印称为fucntion的DLL名称.

hI,

I have 2 DLL''s loaded at runtime. But I want to add a log in the function calls to know the origin of the function call. (i.e) Function A can be called from DLL A all the times and Function B can be called from DLL B all the times. Is there any function to print the DLL name of the particular fucntion called.

推荐答案

我用Google搜索了一些内容,并在点网框架中找到了一些内容.我发现的示例在VB.NET中,但是由于您使用的是C ++/CLI(托管C ++),因此它应该可以轻松转换,尤其是在您查阅MSDN文档时.

来了该示例使用System.Reflection命名空间检查stacktrace:
I googled some and found something in the dot net framework. The example I found is in VB.NET but since you''re using C++/CLI (managed C++) it should translate easily especially when you consult the MSDN documentation.

Here it goes. The example uses the System.Reflection namespace to inspect the stacktrace:
Dim method As System.Reflection.MethodBase = New StackTrace().GetFrame(1).GetMethod()
MessageBox.Show(method.Name)



因此,请访问此处以了解有关此内容的更多信息: http://msdn.microsoft.com/zh-cn/library/system.diagnostics.stacktrace.aspx [



So please visit here to read more about it: http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx[^]

Hope this helps! Please tell us if you got that to work for you.

Best Regards,
Manfred


是的,就DLL是托管程序集而言.方法如下:

Yes, as far as DLLs are managed assemblies. Here is how:

System::Diagnostics::StackTrace^ stackTrace = gcnew System::Diagnostics::StackTrace();
int count = stackTrace->FrameCount;
for (int level = 0; level < count; level++) {
    System::Diagnostics::StackFrame^ frame =    
          stackTrace->GetFrame(level);
    System::Reflection::MethodBase^ method = frame->GetMethod();
    System::Type^ type = method->GetType();
    System::Reflection::Assembly^ assembly = type->Assembly;
    System::String^ location = assembly->Location;
    System::String^ name = method->Name;
    //use name and location
} //loop frames



抱歉,如果您发现它有点尖锐"-我刚从我的C#代码中翻译并添加了一点.

如需更多煽动,请参阅我的文章:
希望您在这里……只有一次 [



Sorry if you find it a bit "sharpish" -- I just translated from my C# code and added a bit.

For more incite, see my article:
Wish You Were Here… Only Once[^]



Wait! I just realized, maybe we all answered not exactly your question.
It gives some ideas, but it may be not that.

If I''m right, the final answers will depend on many other factors. Please indicate:

1) Do you need information about managed assembly calls or also native unmanaged?
2) Can you modify those DLLs?
3) At what time do you want to obtain the names: if at the time of loading library/assembly -- this is trivial, if on each call -- may or may not be possible, depending on other factors.
4) How exactly do you load DLLs?
5) Do you need just first-level calls (from your project) or also all indirect calls?
5a) Do you want only DLLs directly loaded from your project or also indirectly loaded?

Thank you.
--SA


由于您使用的是c ++/cli,因此可以使用 Cecil [ ^ ]注入日志记录功能.

这是两个使用cecil注入功能的示例:
http://stackoverflow.com/questions/4261645/inject-property-call-with- mono-cecil [ ^ ]

http://sourceforge.net/projects/reflexil/ [
Since you are using c++/cli you can use Cecil[^] to inject logging functionality.

Here are two examples using cecil to inject functionality:
http://stackoverflow.com/questions/4261645/inject-property-call-with-mono-cecil[^]

http://sourceforge.net/projects/reflexil/[^]

The last one is fairly powerful.

Hopefully this is enough to get you started.

Regards
Espen Harlinn


这篇关于查找DLL名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆