Re: LoadLibrary() in eVC

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Michael J. Salamone [eMVP] (mikesa#at#entrek#dot#com)
Date: 12/23/04


Date: Thu, 23 Dec 2004 07:01:32 -0800

System APIs in CE take wide char, not char. Casting doesn't convert char to
wide-char, just fools the compiler.

Use TCHAR, TEXT(), etc.

For your specific problem, either LoadLibrary(TEXT("mydll.dll")) or
LoadLibrary(L"mydll.dll").

Actually, my personal philosophy (and what I practice) is to forget about
TCHAR - always use WCHAR, L"", L''. This if you're Windows
NT/XP/CE-centric. Mitigates usage of #ifdef UNICODE/#ifdef MBCS and using
WideCharToMultiByte and MultiByteToWideChar (and associated bugs that arise
when you compile it the "other" way - "other" being MBCS defined when
normally UNICODE is defined).

-- 
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com
"Naveen Mukkelli" <NaveenMukkelli@discussions.microsoft.com> wrote in 
message news:D018721E-6286-41A9-A550-66C47947D73C@microsoft.com...
> Hi,
>
> I'm trying to load a dll in my eVC application using "LoadLibrary()".
> I'm developing a dll for Pocket PC 2003 with help of another third party 
> dll.
> I've downloaded the third party dll in "\Windows " directory of my PDA.
>
> When I tried
> HINSTANCE hwd = LoadLibrary("mydll.dll"), the following error is 
> occurring,
> "error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'char [10]'
> to 'const unsigned short *".
>
> However, When I tried
>   HINSTANCE hwd = LoadLibrary((LPCTSTR)"mydll.dll") program is compiling
>   properly. But  it is not loading the dll. I found that "hwd" is NULL 
> after
>  the method call to LoadLibrary.
>
> could any one let me know the correct way of using "LoadLibrary" please.
>
> Cheers,
>
> Naveen Mukkelli. 


Relevant Pages

  • Re: TCHAR Copying
    ... You said you have a CString, and a library that takes a TCHAR*. ... It wants a const WCHAR* ... It is MUCH more difficult if you want char*, because although the same techniques as shown ... Debug, WCHAR, DLL, 32-bit ...
    (microsoft.public.vc.mfc)
  • Re: Calling a dll from VC++ 6.0
    ... Check Abdoul [VC++ MVP] ... > char * getProcList; ... > TCHAR * blah = ConvertFileExt; ... > inside of the dll or on the attempt to call the function in the dll. ...
    (microsoft.public.vc.mfc)
  • Re: Problem with calling a managed C++ function from managed C#
    ... A char* is a pointer to whatever 'char' may be, ... > this function is compiled to an DLL and this DLL is referenced in my ... > The compiler always give me an compileerror that it cannot convert ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Overloading of operator names - opinions sought
    ... possible, but it is more likely that the known cases will be known to the compiler implementer, and hence will be better optimized. ... char and bool are also special integer types. ... would either require some special stropping syntax, context dependence, ... with the realization that I would need multiple casts due to differences in semantics. ...
    (comp.lang.misc)
  • Re: Exposing bool to non-MS, non-C++ callers
    ... the functions in this DLL accept a structure as an argument. ... The compiler doesn't help catch places where I neglect ... the C++ bool type is defined as one byte. ... depends on whether the Exe caller will push a value larger than 1 byte. ...
    (microsoft.public.dotnet.languages.vc)