On Thu, 27 Nov 2008, Pritpal Bedi wrote: Hi Pritpal,
> The next day I was struggling with this code: > char szLibName[ MAX_PATH + 1 ] = { 0 }; > GetSystemDirectory( szLibName, MAX_PATH ); > hb_strncat( szLibName, "\\atl.dll", sizeof( szLibName ) - 1 ); > hLib = LoadLibrary( ( LPCSTR ) szLibName ); > it works flawless without UNICODE. Yes because it operates on char types. If you want to write the above code which will work with and without UNICODE macro then you should change it to use TCHAR. TCHAR is single bute char when UNICODE macro is not set and two bytes (USHORT) when it's set. Pointer to TCHAR (TCHAR*) is defined as LPTSTR. LPCTSTR is pointer to const TCHAR array. The following code may look like: TCHAR szLibName[ MAX_PATH + 1 ] = { 0 }; /* please always check if given function need size in TCHARs or bytes * in MS documentation. */ GetSystemDirectory( szLibName, MAX_PATH ); /* TEXT() macro can be used for literal (and only for literal) string * values. It creates array of TCHAR items with given text. It cannot * be used to ecapsulate non literal values. In different [x]Harbour * source code you may find things like TEXT( hb_parc( 1 ) ) - it's * a technical nonsense written by someone who has no idea what this * macro does. * Use new string functions (StringCchCat() in this case) which always * set trailing 0 in the given buffer just like hb_strn*() functions. * [l]str[n]cat() is absolute and should not be used by new code. It does * not guarantee buffer overflow protection and/or setting trailing 0. * StringCch*() functions operate on TCHAR types. */ StringCchCat( szLibName, TEXT( "\\atl.dll" ), MAX_PATH + 1 ); /* Please note that I intentionally removed any casting when szLibName * is passed to WinAPI functions. Such casting can pacify warnings so * program will be compiled but code will be still wrong so it does not * fix anything and only makes much harder later fixing when someone * will look for wrong code which is not UNICODE ready. The wrong casting * related to different character representations used only to pacify * warnings is the biggest problem in MS-Win 3-rd party code written * for [x]Harbour because it only hides bugs and then people have to * look for the code line by line to fix it. I dedicated above note to * developers of few well known MS-Win GUI projects for [x]Harbour. * Please remember about it. */ hLib = LoadLibrary( szLibName ); > Then for UNICODE I tried various ways to get it working but failed, > always errors or suspicious pointers warnings appeared. Yes, Just simply it was not code which can be compiled with UNICDE macro. > Then I settled with this code: > LPTSTR cDll = HB_TCHAR_CONVTO( "atl.dll" ); > hLib = LoadLibrary( cDll ); > HB_TCHAR_FREE( cDll ); > It loads the library but I am afraid under circumstances where 'system32' is > not defined under 'PATH' envvar, it is bound to fail. The simpler varsion of the above is: hLib = LoadLibrary( TEXT( "atl.dll" ) ); I also think that you should read MSDN documentation for LoadLibrary() and SetDLLDirectory(). GetSystemDirectory() is one of default search PATH with higher priority then PATH. > My request is some functions where I send two strings, one TCHAR another > just a text as: > TCHAR szLibName[ MAX_PATH + 1 ]; > GetSystemDirectory( szLibName, MAX_PATH ); > hb_strncat_ex( szLibName, "\\atl.dll", sizeof( szLibName ) - 1 ); // > imaginary > I mean a few C level functions which make the string conversion tasks > easier, at least for poor C programmers like me. > I can expect those are already there is Harbour... See above in the 1-st example. You have everything in Windows API. Harbour only helps in basic conversion between Harbour and parameters and MS-Windows ones. best regards, Przemek _______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour