Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error: cannot convert 'const WCHAR** to 'LPCWSTR ^
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
15 Posts 5 Posters 29.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rondog
    wrote on last edited by
    #5

    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);
    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SherifOmran
      wrote on last edited by
      #6

      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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        freeDNA
        wrote on last edited by
        #7

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

        for example:

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SherifOmran
          wrote on last edited by
          #8

          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");
          ^
          @

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SherifOmran
            wrote on last edited by
            #9

            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'
            @

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rondog
              wrote on last edited by
              #10

              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).

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rondog
                wrote on last edited by
                #11

                Yeah, that might do it

                "#define UNICODE":http://stackoverflow.com/questions/7953025/why-both-unicode-and-unicode

                1 Reply Last reply
                0
                • hskoglundH Online
                  hskoglundH Online
                  hskoglund
                  wrote on last edited by
                  #12

                  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);
                  }
                  @

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SherifOmran
                    wrote on last edited by
                    #13

                    @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
                    @

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SherifOmran
                      wrote on last edited by
                      #14

                      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]

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        freeDNA
                        wrote on last edited by
                        #15

                        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”;

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved