Reputation: 2441
My program, where I work with Win API:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
using namespace std;
int _main(int argc, _TCHAR* argv[]) {
char *fileExt = NULL;
TCHAR szDir[MAX_PATH];
GetFullPathName(argv[0], MAX_PATH, szDir, &fileExt);
printf("Full path: %s\nFilename: %s\n", szDir, fileExt);
return 0;
}
I use example from here and here, but I've got an error message: Argument of type “char *” is incompatible with parameter of type “LPWSTR”.
Where is my mistake?
Upvotes: 0
Views: 70
Reputation: 12993
A string defined as below is called an ANSI string.
char* fileExt = NULL;
And a string defined as below can be an ANSI string or a Unicode string. Your project is compiled with the UNICODE/_UNICODE
macro, so it is a Unicode string.
TCHAR szDir[MAX_PATH];
You can't mix them together, for an introduction to the data type identifiers in VC++ like TCHAR
and LPCTSTR
, please refer to this article.
I made several modifications to your code, as following.
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR *fileExt = NULL;
TCHAR szDir[MAX_PATH];
GetFullPathName(argv[0], MAX_PATH, szDir, &fileExt);
_tprintf(_T("Full path: %s\nFilename: %s\n"), szDir, fileExt);
return 0;
}
Upvotes: 3