How to solve this error

This is a discussion on How to solve this error within the Windows Programming forums, part of the Platform Specific Boards category; Dear Experts, i want to load a dll into my program and want to get the funcptr for some function ...

  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,139
    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
    1,597
    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.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

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, 03: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, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21