cancel
Showing results for 
Search instead for 
Did you mean: 

Get full path of current running internal DLL (C/C++)

Valued Contributor
Valued Contributor

Is there any API available which can provide the full path of running DLL in C/C++ ?

3 REPLIES

Re: Get full path of current running internal DLL (C/C++)

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Normally we don't provide special NXOpen methods for things that you can do with the native language routines.  A good place to look for information about normal C/C++ utilities is stackoverflow, or the MSDN docs.  A Google search for "parth to current .dll" will find some pages that demonstrate how to do this.

Re: Get full path of current running internal DLL (C/C++)

Genius
Genius

I'm not aware of any NX API Method to report the current custom dll, but with Windows the following works for me (C11):

 

#if defined (_WIN32)
#include <Windows.h>
#include <WinBase.h>
#endif

...

namespace {
	char dummyChar;
}

...

#if defined (_WIN32)
	char path[_MAX_PATH];
	HMODULE phModule = NULL;

	if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | 
		GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
		(LPCSTR) &dummyChar, 
		&phModule))
	{
		//Some error
	}
	GetModuleFileNameA(phModule, path, sizeof(path));
	//path contails dll path
#endif

I use the dummyChar only to have an address within the module with static storage duration.

 

Regards

Jan

 

Jan Böttcher

Re: Get full path of current running internal DLL (C/C++)

Experimenter
Experimenter
Hi The below code works,
TCHAR path[_MAX_PATH+1]; GetModuleFileName(GetModuleHandle(_T("Test.dll")), path, sizeof(path)/sizeof(path[0]));
The above is windows code. you will get the full details in the "http://www.cplusplus.com/forum/windows/6457/" path.
Thank you,
Harsha