Typecasting
-
:((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth
-
:((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth
siddharthsan wrote:
"cannot convert parameter 1 from const char to LPCWSTR",
This is because in your project setting the _UNICODE is defined. So you must specify unicode string like LoadLibrary(_T("library.dll")) or LoadLibrary(L"library.dll").
siddharthsan wrote:
LoadLibrary((LPCWSTR)"library.dll"))
This is not the corrcect way. This casting dosent make the string unicode.
siddharthsan wrote:
library gives error as No such lib found.
This error may be because the dll is not in the path. try 1.Give full path of the dll in that function. 2.Add the path of the dll into the "PATH" environment variable. Restart msdev after this and try
nave
-
:((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth
siddharthsan wrote:
If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll"))
So the compiler is wrong and and you are making it listen by casting, right!! :|
Nibu thomas A Developer Code must be written to be read, not by the compiler, but by another human being. http:\\nibuthomas.wordpress.com
-
:((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth
Siddharth, Have you tried using
LoadLibraryA("library.dll")
? Your project is clearly set to use UNICODE by default and the API headers are defining LoadLibrary as LoadLibraryW. This is a bit of a strange one, I've never been quite sure what happens if you try to load a dll with the name in UNICODE (wide characters).:confused: Note:((LPCWSTR)"library.dll")
will never work as this just casts the pointer to narrow string to a pointer to wide string but doesn't change the string:wtf: If LoadLibraryA does not work then I guess it just can't find your dll. Is it in the normal search path, i.e. same dir as exe or Windows\System32 or somewhere mentioned in the PATH environemnt variable?Nothing is exactly what it seems but everything with seems can be unpicked.
-
:((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth
siddharthsan wrote:
LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found.
Try a fully-qualified path.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
:((Hi, I am using Visual studio 2005 for my application. In my application,Loadlibrary is used, LoadLibrary("library.dll"); If i simply give like this, it's showing error as "cannot convert parameter 1 from const char to LPCWSTR",so i typecasted it as, LoadLibrary(_T("library.dll")) or LoadLibrary((LPCWSTR)"library.dll")) if i give like this it is not taking or recognizing the library gives error as No such lib found. Please I need help... Siddharth
siddharthsan wrote:
LoadLibrary((LPCWSTR)"library.dll"))
This is wrong. If you get into the habbit of using
static_cast
instead of C-style casts this kind of mistake will produce compiler errors instead of runtime errors.Steve