Thread: How to solve this error

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    99

    How to solve this error

    Dear Experts,

    i want to load a dll into my program and want to get the funcptr for some function while trying to do i am getting this error can you please tell me how to solve this i am using VS2005

    Code:
    error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [71]' to 'LPCWSTR'
    if i do type casting to LPCWSTR the error goes away but the dll does not load properly.

    please tell me what is the reason.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    You have set your project to use UNICODE or you are using the unicode version of LoadLibrary intentionally. Either pass a UNICODE string to the function or use the Ansi version of the function.

    Code:
    // ANSI version
    HMODULE hModule = LoadLibraryA( "test.dll" );
    Code:
    //UNICODE version
    HMODULE hModule = LoadLibraryW( L"test.dll" );
    Code:
    // Compile time flag version, will compile as UNICODE or ANSI depending on project settings
    HMODULE hModule = LoadLibrary( _T("test.dll") );
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    99
    Thanks for the reply,

    can you please tell me which is the setting for unicode character to be done,

    is it at the general->character set , there we have to select the setting,
    can you please explain .

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    You can turn Unicode off in your Project Settings.

    But you may not want to do this. Unless you have a good reason, you should use Unicode; that's why it's enabled by default. Just use the _T macro as nvoigt explained and you'll do fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM