> it is not working.
two reasons:
a. strcat(buffer,"\\root1\\root2\\test.dll") ; causes a buffer overflow
b. LoadLibrary((LPTSTR)buffer) ; casting is not the way to convert narrow char strings to wide char strings.
wchar_t wbuffer[ MAX_PATH ] ;
wchar_t* result = _wgetcwd( wbuffer, MAX_PATH ) ;
assert( result ) ;
wcscat( wbuffer, L"\\root1\\root2\\test.dll" ) ;
result = LoadLibrary( wbuffer ) ;
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
you can not use strcat() on the pointer returned by getcwd () because _getcwd() allocates a buffer only large enough to hold the path. You need to allocate a second buffer that is large enough to hold the string returned by _getcwd() and the string you need to add.
The second problem with the solution you have is that depending on the current directory the final string may contain the wrong path too if _getcwd() returns "c:\debug\root1\root2" then your strcat() will result in "c:\debug\root1\root2\root1\root2\test.dll". Your program needs to verify the string that was returned by _getcwd() to make sure you don't strcat() duplicate text.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343