Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incompatible with parameter of type "LPCWSTR"

Tags:

c++

visual-c++

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <dos.h>
using namespace std;

class Dir
{
public:
    char* cat;
    Dir()
    {
        cout << "(C:/*)\n";
        cat = new char[50];
        cin >> cat;
    }

    void virtual ShowFiles()
    {
    }

};


class Inside : public Dir
{
public:
    void virtual ShowFiles()
    {
        HANDLE hSearch;
        WIN32_FIND_DATA pFileData;

        hSearch = FindFirstFile(cat, &pFileData);
        if (hSearch != INVALID_HANDLE_VALUE)
            do
            {
                //  if ((pFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
                cout << pFileData.cFileName << "\n";
            } while (FindNextFile(hSearch, &pFileData));
            FindClose(hSearch);
    }
};
int main()
{
    Dir *obj1[2];
    obj1[1] = new Inside;
    obj1[1]->ShowFiles();
    return 0;
}

So I have a program, I need to show with dynamic char cat all file in directory, but it is compilable in Borland C++ but in Visual Studio 15 + Resharper it doesn't work. Severity Code Description Project File Line Error (active) argument of type "char *" is incompatible with parameter of type "LPCWSTR"

like image 787
Bogdan Tkachenko Avatar asked Oct 07 '15 19:10

Bogdan Tkachenko


People also ask

What is Lptstr C++?

LPTSTR is a pointer to a (non-const) TCHAR string. In practice when talking about these in the past, we've left out the "pointer to a" phrase for simplicity, but as mentioned by lightness-races-in-orbit they are all pointers.

What is Lpcwstr?

An LPCWSTR is a 32-bit pointer to a constant string of 16-bit Unicode characters, which MAY be null-terminated.

What is Lpcstr?

An LPCSTR is a 32-bit pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.


1 Answers

To compile your code in Visual C++ you need to use Multi-Byte char WinAPI functions instead of Wide char ones.

Set Project -> Properties -> Advanced (or. General for older versions) -> Character Set option to Use Multi-Byte Character Set

also see the screenshot

like image 85
Anton Malyshev Avatar answered Sep 19 '22 19:09

Anton Malyshev