Domanda

I am creating a simple project with VC++ win32 console application and trying to load a dll file using function “LoadLibrary("D:\SRV\RFIDReader.dll");” and I am able load it this way. But when I try to do the same thing in a Smart Device application its giving me an error while compilation. Error says: “error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [22]' to 'LPCWSTR'”.

The solutions i have already tried are as follows: 1. On using "L" or "_T" or "TEXT" before the String (path of the dll), it compiles but on running the app, LoadLibrary returns NULL. 2. Changing the Character Set in Properties to "Use Multi Byte Character Set" also didnt help.

I am using Visual Studio 2008 and Windows Mobile SDK 6.0. Any idea regarding this issue? I am really new to both VC++ and Windows Mobile.

Thanks in advance

È stato utile?

Soluzione

Two issues!!

1) All Windows CE / Windows Mobile APIs are Unicode. So you need to compile the application for Unicode, and you need to wrap string constants in _T() macros. (Explicit L prefixes are possible by _T() is more robust.)

2) Windows CE / Windows Mobile devices do not have drive letters, so your path cannot be right.

So your call should be more like

LoadLibrary(_T("\SRV\RFIDReader.dll"));

Altri suggerimenti

Is this a real "windows ce" device or a "Windows Mobile"? I asked because you use cout which will not output anything to the screen on a Windows Mobile device.

All Windows CE and Mobile is UNICODE (also called WideCharString, WCS, every char is saved as two byte in memory).

Please start a new project from scratch and use C/C++-SmartDevice during the New Project Wizard.

#include <iostream> 
#include <windows.h> 
#include <stdio.h> 
#include <tchar.h> 
using namespace std;
 HINSTANCE hDLL_platform;
 HINSTANCE hDLL_stack;

 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
    DWORD err;
     hDLL_stack = LoadLibrary(_T("**\\SRV\\RFIDReader.dll**"));
     if (hDLL_stack != NULL) { 
        cout<<"done"<<endl;
    } else { 
        err = GetLastError();
         cout<<"failed\n"<<endl;
     } 
    FreeLibrary(hDLL_stack);
    return (1);
 }

A single \ in a string is a escape start char. For example \n is newline, \r is CR. You have to change your string to "\SRV\RFIDReader.dll".

Is the DLL really available locally on the device at \SRV?

Just check your code with a well known DLL, for example "\Windows\coredll.dll".

regards

Josef

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top