When I compile this code in Visual C++, I got the below error. Can help me solve this issue..
DWORD nBufferLength = MAX_PATH;
char szCurrentDirectory[MAX_PATH + 1];
GetCurrentDirectory(nBufferLength, szCurrentDirectory);
szCurrentDirectory[MAX_PATH +1 ] = '\0';
Error message:
Error 5 error C2664: 'GetCurrentDirectoryW' : cannot convert parameter 2 from 'char [261]' to 'LPWSTR' c:\car.cpp
Your program is configured to be compiled as unicode. Thats why GetCurrentDirectory is GetCurrentDirectoryW, which expects a
LPWSTR(wchar_t*).GetCurrentDirectoryW expects a
wchar_tinstead ofchararray. You can do this usingTCHAR, which – like GetCurrentDirectory – depends on the unicode setting and always represents the appropriate character type.Don’t forget to prepend your
'\0'with anLin order to make the char literal unicode, too!