PrajwalBhat
PrajwalBhat

Reputation: 51

IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR"

I get the following error :

argument of type "const char *" is incompatible with parameter of type "LPCWSTR"

Here is my code :

static char *getFmuPath(const char *fileName) {
    char pathName[MAX_PATH];
    int n = GetFullPathName(fileName, MAX_PATH, pathName, NULL);
    return n ? strdup(pathName) : NULL;
}

I have declared MAX_PATH but it still shows error in pathname

#define MAX_PATH 4096

What is the problem ?

Upvotes: 2

Views: 12170

Answers (3)

Eric
Eric

Reputation: 1

I was having the same problem (VS2017). Changed the project to compile 32-bit and it compiled great! My problem was that I deleted all the extra files in the directory to clean it up and it defaulted to 64-bit because I was building on a 64-bit machine.

Upvotes: 0

rkellerm
rkellerm

Reputation: 5522

I agree with @tenfour, if you would still like to enforce your system work with ANSI chars so char* would work, change your code to call directly GetFullPathNameA
Or, better yet, use unicode character set under Project->Properties->Configuration Properties->General->Character Set.

Upvotes: 0

tenfour
tenfour

Reputation: 36896

GetFullPathName doesn't take a char *. Look at the docs, it takes LPTSTR and LPCTSTR.

Depending on your build settings, LPTSTR and related types will become either char* (ANSI builds) or wchar_t* (Unicode builds). You are building as Unicode.

Also, I don't know why you are defining MAX_PATH. That is a Windows constant so you should not re-define it.

Upvotes: 5

Related Questions