How to get the current instance handle
-
I have searched for a way to get the instance handle of the module that my code is executing in. AfxGetInstanceHandle function available, but only when running as an MFC dll. GetModuleHadndle is available, but requires the path of the dllm which I don't have. I cannot inject code in DllMain to "remember" the instance handle because I don't have access to it. I have a solution that is quite extensive using "Process Helper", "PE Image Helper" APIs and are quite time consuming. I hope to find a better way of doing it. Probably there exist a way for it, but I haven't found it yet. Does anybody have a solution for it?
-
I have searched for a way to get the instance handle of the module that my code is executing in. AfxGetInstanceHandle function available, but only when running as an MFC dll. GetModuleHadndle is available, but requires the path of the dllm which I don't have. I cannot inject code in DllMain to "remember" the instance handle because I don't have access to it. I have a solution that is quite extensive using "Process Helper", "PE Image Helper" APIs and are quite time consuming. I hope to find a better way of doing it. Probably there exist a way for it, but I haven't found it yet. Does anybody have a solution for it?
Per Nilsson wrote: GetModuleHadndle is available, but requires the path of the dllm which I don't have. Actually you do. First make a call to
GetModuleFileName(...)
.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
Per Nilsson wrote: GetModuleHadndle is available, but requires the path of the dllm which I don't have. Actually you do. First make a call to
GetModuleFileName(...)
.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
No This function returns the module name of the creating process, not the dll I am executing in. /Per
-
No This function returns the module name of the creating process, not the dll I am executing in. /Per
If you only have to run on Windows XP or Windows 2003 then look at this one
GetModuleHandleEx
using theGET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
flag. -
No This function returns the module name of the creating process, not the dll I am executing in. /Per
Are you sure? http://www.mvps.org/vcfaq/sdk/7.htm
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
Are you sure? http://www.mvps.org/vcfaq/sdk/7.htm
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Yes "The Win32 API GetModuleFileName() is what you need. If you pass NULL as the module handle parameter, the function returns the path of the module that created the process (in other words - the application's exe file)."
-
Yes "The Win32 API GetModuleFileName() is what you need. If you pass NULL as the module handle parameter, the function returns the path of the module that created the process (in other words - the application's exe file)."
Did you not read the last sentence for some reason?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow