-
October 10th, 2009, 05:19 PM
#1
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
-
October 10th, 2009, 08:40 PM
#2
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
-
October 10th, 2009, 08:55 PM
#3
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
-
October 11th, 2009, 12:36 PM
#4
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
-
October 11th, 2009, 01:10 PM
#5
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.
-
October 11th, 2009, 01:14 PM
#6
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.
-
October 11th, 2009, 04:56 PM
#7
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
-
October 11th, 2009, 07:02 PM
#8
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") );
-
October 12th, 2009, 10:09 AM
#9
Re: LoadLibrary("*.dll") vs LoadLibraryA(".dll")
Originally Posted by 65dos
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|