我可以让DLL告诉EXE叫什么名字吗? [英] can I have a DLL tell what EXE call it?
本文介绍了我可以让DLL告诉EXE叫什么名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以让DLL告诉它叫什么EXE吗?
在DLL的一个属性中,我想从调用EXE的app.config中读取,但无法弄清____.My.MySettings.
到目前为止,这是我的代码,但是CallingProcName正在重播"ctor"
can I have a DLL tell what EXE is call it?
In one of the DLL''s properties I want to read from the calling EXE''s app.config but can''t figure out the ____.My.MySettings.
Here is my code so far but the CallingProcName is returing "ctor"
Public ReadOnly Property ISLogConnectionString As String
Get
Dim ScriptDefaultMode
Dim StackTrace As New StackTrace()
Dim StackFrame As StackFrame = StackTrace.GetFrame(1)
Dim CallingProcName = StackFrame.GetMethod().Name
' what settings server are we going to look to first?
Try
' look for an App.Config Setting of zDefaultRing (ISScriptingTemplate) in the EXE's ApplicationSettings
Dim exeConfig As Configuration
exeConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim sectGroup As ApplicationSettingsGroup
sectGroup = exeConfig.GetSectionGroup("applicationSettings")
Dim sect As ClientSettingsSection
sect = sectGroup.Sections(CallingProcName & ".My.MySettings")
Dim elm As SettingElement
elm = sect.Settings.Get("zDefaultRing")
ScriptDefaultMode = elm.Value.ValueXml.InnerXml
.
.
.
.
.
.
推荐答案
您可以使用类System.Diagnostics.StackTrace
获取当前调用堆栈的所有详细信息.请参阅:
http://msdn.microsoft.com/en-us/library/system.diagnostics. stacktrace.aspx [ ^ ].
您还可以找到执行以下代码的代码的入口程序集:
You can get all detail of the current call stack using the classSystem.Diagnostics.StackTrace
. Please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx[^].
You can also find out the entry assembly of the code executing the following code:
System.Reflection.Assembly entryAssembly = System.Reflection.Assembly.GetEntryAssembly();
// and this is its main executable module file:
string exeFile = entryAssembly.Location;
请参阅:
http://msdn.microsoft.com/en-us/library/system.reflection. assembly.aspx [^ ].
Please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^].
这篇关于我可以让DLL告诉EXE叫什么名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文