Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

relative paths

Status
Not open for further replies.

MonicaLong

Programmer
Sep 30, 2003
7
UY
I am so sorry to bother you with this but I just don´t know C++ and receive a work to do in C++.
I have a project that generates a dll.
I need that to recognize his own path, because I have an Txt archive with information there.
this is working, but with the full path to the archive..
can anyone help me pls??
Please be very clear because I really don´t understand half of the things i see in c++ (don't know how the project is working!!!!)
tnks, tnks, tnks,tnks!!!
 
Solution 1.
CFileFind finder;
CString fullPath = finder.GetFilePath("my.dll");
The fullPath string contains the path of the "my.dll" file.

Solution 2:
char buff[1024];

DWORD dw = GetModuleFikleName(NULL, buff, sizeof(buff));
The buff contains the full path of your dll.

-obislavu-
 
>>Solution 2

Not true:
GetModuleFileName() with a NULL handle will return the name of the module that contains the current process (which is the executable that loaded de dll). So, unless the dll is in the same path as this executable, it will NOT return the path of the dll.....

Greetings,
Rick
 
Sorry.... not complete:

If you want to use GetModuleFileName() you should pass the handle passed to your dll entry point as the first param, instead of NULL.

Greetings,
Rick
 
tnks LazyMe.... I had tried both solutions and no one worked as I needed.
From the beginning, I could never make the first one work, if I just get it into my code it didn´t recognize the object, if i made an include it said i couldn´t make includes from windows classes becouse they were alredy included...
And with the second solution it happened that, it returned the executing path as something else I hade tried before...
How can I pass the handle? I don´t exactly understand what you are talking about with handle... - sorry english is not my native language...- the name of the dll return
error types.
Thanks for everything, you have been very kind...
 
In the dll, there should be a DllMain function. Although I do believe it's actually optional to have this one present, but it's usually there. Its prototype is like this (copied straight from MSDN):

BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to the DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved // reserved
);


The handle to pass to GetModuleFileName() (first param) would be hinstDll....

Greetings,
Rick
 
Sorry, it´s an upload we downloded from the net and i have to make changes... it doesn´t have a main...¿?
 
then just implement it yourself:

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
BOOL bResult=TRUE;

switch(dwReason) {
case DLL_PROCESS_ATTACH:
g_hModule=hInstance; //Where g_hModule is a global handle variable.
}

return bResult;
}


Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top