CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2009
    Posts
    5

    LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    hey,
    I am programming an ansi C application that needs to load a .dll.
    My line of code is the next:
    hCodigo = LoadLibrary("zlib1.dll");

    when I try to run the program that way it doesnt find the dll, I started searching and find that exists LoadLibraryA, the program works using that function,

    but why it doesnt work with LoadLibrary("dll")??

    also, are there any differences in those functions?
    I know that the last A is for Ansi, this is the only i found about LoadLibrary, hehe.

    Btw, I read somewhere that i should use _T("dll") but that didnt work.
    the dll is in both folders system and system32.
    Thanks,
    65dos

  2. #2
    Join Date
    Oct 2008
    Posts
    116

    Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    First you could try to use :

    hCodigo = LoadLibrary(TEXT("zlib1.dll"));

    If it don't work, you can use GetLastError() to find what problem is.

    (zlib1.dll) should place at the same folder with your exe file.
    My English is very bad. So tell me if Something I talked make u confuse.
    My Ebook Store: www.coding.vn/book.php

  3. #3
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    Are you compiling in unicode format?
    A is for ASCII
    If you are compiling in unicode, LoadLibrary calls LoadLibraryW

    http://www.codeproject.com/Messages/...dLibraryW.aspx

    This says that LoadLibraryW actually looks in C:\Windows for the file

  4. #4
    Join Date
    Oct 2009
    Posts
    5

    Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    thanks guys

    the problem was the character set: Unicode

    so I need to use LoadLibrary( L"zlib1.dll")

    or change the character set to multibyte

  5. #5
    Join Date
    Feb 2005
    Posts
    2,160

    Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    Beware though, LoadLibrary can expand to either LoadLibraryA or LoadLibraryW depending on the UNICODE settings, but GetProcAddress() always takes a ANSI string (char *) for some weird resason.

  6. #6
    Join Date
    Jul 2002
    Posts
    2,543

    Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    Interesting, how did you manage to compile the line
    LoadLibrary("zlib1.dll");
    in Unicode configuration? It should not compile.

  7. #7
    Join Date
    Oct 2009
    Posts
    5

    Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    well, it compiles but the compiler sends an incompatible type warning:
    char[10] is incompatible to type LPCWSTR.

    but when I used 'L' on LoadLibrary( L"zlib1.dll") it removed the warning.

    on unicode it calls LoadLibraryW
    while multibyte calls LoadLibraryA

    good to know these things know hehe

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    It's rare that you should ever explicitly call A or W versions of the api's. Just use the _T("") macros and let the compiler and environment do its job.

    ie.
    Code:
    LoadLibrary( _T("zlib1.dll") );

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")

    Quote Originally Posted by 65dos View Post
    well, it compiles but the compiler sends an incompatible type warning:
    char[10] is incompatible to type LPCWSTR.

    but when I used 'L' on LoadLibrary( L"zlib1.dll") it removed the warning.

    on unicode it calls LoadLibraryW
    while multibyte calls LoadLibraryA

    good to know these things know hehe
    Ignoring compiler warnings is always a good way to get stable code.

    Asking in a forum about a function not working even though your compiler gave you a warning about it and then not even bothering to mention on the forum you're getting that compiler warning... Tsk...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured