Error: cannot convert 'const WCHAR** to 'LPCWSTR ^



  • Hello Guys,

    I am trying to compile code taken from visual studio c++ with mingw but i keep on getting similar conversion problems

    @
    main.cpp:82: error: cannot convert 'const WCHAR** {aka const wchar_t**}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'int MessageBoxW(HWND, LPCWSTR, LPCWSTR, UINT)'
    MessageBox (appWindow, message,"Note to Developer", MB_OK | MB_ICONASTERISK)^;
    @

    this is my code so far

    @

    #include <stdio.h>
    #include <windows.h>
    #include "resource.h"
    #define UNICODE

    #include "eWebLibrary.h"
    #include "Validate.h"

    #define STRINGLENGTH 64

    enum Status {
    Unknowon,
    NoSerialNumber,
    NotActivated,
    NotCurrent,
    Okay
    };

    HINSTANCE appInstance;
    HWND appWindow;
    HMENU appMenu;

    char* windowClass = "eSellerateDemo";

    char* publisherID = "PUB775527079";
    char* activationID = "ACT757079729:XTHEXA-3GBR-A8U4R3-U2AB-VE1HPH-Y8PD6P-A97J-WUFG99-882A-E85NRB";

    char webstoreID [STRINGLENGTH] = "STR9885216359";
    char versionTitle [STRINGLENGTH] = "";
    char serialNumber [STRINGLENGTH] = "";
    char enteredValue [STRINGLENGTH] = "";

    Status ownership = Unknowon;

    //////////////////////////////////////////////////

    static
    void NoteToDeveloper (
    char* message
    ) {
    MessageBox (appWindow, message,"Note to Developer", MB_OK | MB_ICONASTERISK);
    }

    @



  • Update: This was solved by adding the following to the pro file

    DEFINES -= UNICODE



  • now i get the following, any help is appreciated
    @
    main.cpp:-1: error: undefined reference to _imp__SelectObject@8' main.cpp:-1: error: undefined reference to_imp__CreateDIBitmap@24'
    main.cpp:-1: error: undefined reference to _imp__CreateCompatibleDC@4' main.cpp:-1: error: undefined reference to_imp__BitBlt@36'
    main.cpp:-1: error: undefined reference to `_imp__DeleteDC@4'

    @



  • Looks like you are using windows sdk.
    Have you added a windows library that implements the undefined functions?
    I think MSDN docs have more info about windows sdk.



  • You might need to define 'UNCODE' before including the windows header. Some things might not be set right if unicode is not defined before the windows header is processed.

    @
    #define UNICODE

    #include <stdio.h>
    #include <windows.h>
    #include "resource.h"
    @

    You might need to wrap text sent to the Win32 api with the _T() macro so that literals are treated properly by the compiler. This is defined in <tchar.h>. You can cast directly if you don't want to use this macro (i.e. L"Some text" ) which is basically what _T() does when unicode is defined.

    @
    #define UNICODE

    #include <stdio.h>
    #include <windows.h>
    #include <tchar.h>

    #include "resource.h"
    ...
    MessageBox (appWindow, message,_T("Note to Developer"), MB_OK | MB_ICONASTERISK);
    @



  • Code is
    ^
    @
    #include "mainwindow.h"
    #include <QApplication>

    #define UNICODE
    static libraries version
    requires:
    eWebLibrary.h
    eWebClient.lib
    eWebClient.dll
    validate.h
    validateLibrary.lib

    *************************************************/

    #include <stdio.h>
    #include <windows.h>
    #include <tchar.h>
    #include "resource.h"

    #include "eWebLibrary.h"
    #include "Validate.h"

    #define STRINGLENGTH 64

    enum Status {
    Unknowon,
    NoSerialNumber,
    NotActivated,
    NotCurrent,
    Okay
    };

    HINSTANCE appInstance;
    HWND appWindow;
    HMENU appMenu;

    char* windowClass = "eSellerateDemo";

    char* publisherID = "PUB775527079";
    char* activationID = "ACT757079729:XTHEXA-3GBR-A8U4R3-U2AB-VE1HPH-Y8PD6P-A97J-WUFG99-882A-E85NRB";

    char webstoreID [STRINGLENGTH] = "STR9885216359";
    char versionTitle [STRINGLENGTH] = "";
    char serialNumber [STRINGLENGTH] = "";
    char enteredValue [STRINGLENGTH] = "";

    Status ownership = Unknowon;

    static
    void NoteToDeveloper (
    char* message
    ) {
    MessageBox (appWindow, message,_T("Note to Developer"), MB_OK | MB_ICONASTERISK);
    }
    @

    it says now
    main.cpp:82: error: cannot convert 'char*' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'int MessageBoxW(HWND, LPCWSTR, LPCWSTR, UINT)'
    MessageBox (appWindow, message,_T("Note to Developer"), MB_OK | MB_ICONASTERISK);

    I have many similar errors .. yes i am trying to compile a code that was depending on MSVS with MinGW ..
    The project is using esellerate dll with QT
    if you like to have the code, i can send it per email



  • try replacing all char with wchar_t and prefix every string with L:

    for example:

    char* publisherID = "PUB775527079";
    wchar_t* publisherID = L"PUB775527079";



  • for this part of the code

    @
    wchar_t message [256];
    wchar_t* format = L"%s returned:\r\n0xX (%s)";
    switch ( result ) {
    case E_SUCCESS:
    case E_SDK_INSTALLED_ENGINE:
    case E_SDK_LATEST_ENGINE_ALREADY_INSTALLED:
    case E_VALIDATEACTIVATION_MACHINE_MATCH:
    case E_ENGINE_SKU_UPDATE_AVAILABLE:
    sprintf(message, format, call, result, L"success");
    break;
    @

    I get

    @
    main.cpp:100: error: cannot convert 'wchar_t*' to 'char*' for argument '1' to 'int sprintf(char*, const char*, ...)'
    sprintf(message, format, call, result, L"success");
    ^
    @



  • When i disable the unicode i get the following with other undefined references

    @
    error: undefined reference to _imp__SelectObject@8' error: undefined reference to_imp__CreateDIBitmap@24'
    @



  • Try defining _UNICODE in addition to UNICODE. Scanning the header files for mingw I found some #defines that use both and others that only use the underscore version. I remember something about this back when I did use MSVC.

    @
    #define UNICODE
    #define _UNICODE
    @

    I checked in some of my old software and I did have the two define statements in there. There was some reason for doing this (or I was told to do this and never questioned it).





  • Hi, the code is kind of last century, what I mean, _T() L( and #define or undefine UNICODE, you can survive without them, since you are using Qt :-)

    For example: try switching from MessageBox to Qt's QMessageBox:
    @
    #include "QMessageBox" // <-- include this
    static
    void NoteToDeveloper (
    char* message
    ) {
    QMessageBox::information(QApplication::activeWindow(),"Note to Developer",message);
    }
    @



  • @rondog: Using _unicode did not make a change in the err output ..
    @hskoglund: I can not convert to QMessageBox because it is not only a messagebox problem but i ve other function as well such as @RegCreateKeyEx@

    For the following code, i get now

    @
    static
    void NoteToDeveloper (
    char* message
    ) {
    MessageBox (appWindow, message,"Note to Developer", MB_OK | MB_ICONASTERISK);
    }

    'MessageBoxW' : cannot convert parameter 2 from 'char *' to 'LPCWSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    @



  • I uploaded the code in the following link, any body like to have a try compiling it, please share with me your result
    I am using MinGW 4.8.3 (installed with QT5) and QT 4.8.2

    "http://www.file-upload.net/download-10250968/esellerate.zip.html]esellerate.zip":[URL=http://www.file-upload.net/download-10250968/esellerate.zip.html]esellerate.zip[/URL]



  • Replace ALL non-UNICODE-aware functions with UNICODE-awares ones:
    for example:

    use swprintf() instead of sprintf()
    "Your text to link here...":https://msdn.microsoft.com/en-us/library/ybk95axf.aspx

    Replace ALL char with wchar_t and prefix every string with L:

    for example:

    char* publisherID = “PUB775527079”;
    wchar_t* publisherID = L“PUB775527079”;


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.