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. Compile Error Newb: cannot convert char to lpcwstr
Forum Updated to NodeBB v4.3 + New Features

Compile Error Newb: cannot convert char to lpcwstr

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.5k 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.
  • C Offline
    C Offline
    chris0086
    wrote on 28 Nov 2014, 14:06 last edited by
    #1

    Hello Community,
    iam new in working with QT.
    I only want to compile some Code for my 64bit machine.
    I loaded the code but if i compile it i get the following failure in the code:
    @/**
    Opens the COMM Port.
    @param port Port number. COMM1 = 1, COMM2 = 2, etc.
    @param baud Baud rate, in BPS. Commonly 9600, 38400, etc.
    @param HwFc Set to non-zero to use hardware flow-control, or zero
    for no flow control.
    @param hwnd Window handle to recieve MESS_SERIAL messages. If set to NULL,
    you can still get characters using SerialGetChar().
    @return TRUE if port was opened, FALSE if opening failed.
    */
    BOOL OpenPort(int port,long baud,int HwFc, HWND hwnd)
    {
    HANDLE Comport;
    DCB myDCB;
    COMMTIMEOUTS CTout;
    char str[100];

    FlowControl = HwFc;

    // Open the serial port
    if (port > 9)
    sprintf(str,"\\.\COM%d",port);
    else
    sprintf(str,"COM%d",port);
    Comport = CreateFile(str,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
    if (Comport == INVALID_HANDLE_VALUE)
    return FALSE;
    // Configure Serial port (Setup Comm)
    if (!SetupComm(Comport,350,350)) // Buffer sizes
    return FALSE;

    // setup DCB using current values
    if (!GetCommState(Comport,&myDCB))
    return FALSE;
    myDCB.fInX = FALSE; // Turn off xon/xoff handler
    myDCB.fOutX = FALSE;
    myDCB.fOutxDsrFlow = FALSE;
    if (HwFc) // no flow control
    {
    myDCB.fOutxCtsFlow = TRUE; // no hardware flow control.
    myDCB.fRtsControl = RTS_CONTROL_HANDSHAKE;
    }
    else
    {
    myDCB.fOutxCtsFlow = FALSE; // no hardware flow control.
    }

    myDCB.BaudRate = baud;
    myDCB.DCBlength = sizeof(DCB);
    myDCB.fBinary = 1;
    myDCB.fParity = 0;
    myDCB.fDtrControl = DTR_CONTROL_DISABLE;
    myDCB.fDsrSensitivity = 0;
    myDCB.fTXContinueOnXoff = 1;
    myDCB.fNull = 0;
    myDCB.fRtsControl = RTS_CONTROL_DISABLE;
    myDCB.fDummy2 = 0;
    myDCB.wReserved = 0;
    myDCB.Parity = NOPARITY;
    myDCB.StopBits = ONESTOPBIT;
    myDCB.wReserved1 = 0;
    myDCB.ByteSize = 8;

    if (!SetCommState(Comport,&myDCB))
    {
    ShowLastError();
    return FALSE;
    }

        // Set timeouts
    

    //CTout.ReadIntervalTimeout = 0xffffffff;

    CTout.ReadIntervalTimeout = MAXDWORD;
    CTout.ReadTotalTimeoutMultiplier = 0;
    CTout.ReadTotalTimeoutConstant = 0;
    CTout.WriteTotalTimeoutMultiplier = 0;
    CTout.WriteTotalTimeoutConstant = 5000; // don't hang if CTS is locked, for example

    SetCommTimeouts(Comport,&CTout);

    EscapeCommFunction(Comport,SETDTR);
    PurgeComm(Comport,PURGE_TXCLEAR | PURGE_RXCLEAR);

    handle = hwnd;
    SerialPort = Comport;
    StartCommThread();

    return TRUE;
    }@

    Failure:

    C:\Qt\Tools\QtCreator\bin\untitled\serial.cpp:262: Fehler: cannot convert 'char*' to 'LPCWSTR {aka const wchar_t*}' for argument '1' to 'void* CreateFileW(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE)'
    Comport = CreateFile(str,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
    ^

    Can anybody say what can I change that it will work?
    The complete code is downloadable from "http://www.mikrocontroller.net/attachment/87079/fboot-win-devcpp-mod.zip":http://www.mikrocontroller.net/attachment/87079/fboot-win-devcpp-mod.zip

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Binary91
      wrote on 28 Nov 2014, 14:14 last edited by
      #2

      You try to pass a char 'str' to a function (createFile) that expects a LPCWSTR as type.

      Try it with C-cast:
      @CreateFile((LPCWSTR)str,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);@

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on 28 Nov 2014, 16:21 last edited by
        #3

        Just use CreateFileA .

        BTW: Look on

        • http://qt-project.org/wiki/QtSerialPort
        • http://qt-project.org/doc/qt-5/qtserialport-index.html
        1 Reply Last reply
        0

        1/3

        28 Nov 2014, 14:06

        • Login

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