2

I'm trying to get the current directory under win7 with VS c++ but

TCHAR pBuf[MAX_PATH];
int bytes = GetModuleFileName(NULL, pBuf, MAX_PATH);
std::cout << bytes << "   " << pBuf << "   " <<   GetLastError() << std::endl;

returns length 58 and what I believe to be a pointer in pBuf pointing to 68. Errorcode is 0.

Thank you!

user3049681
  • 397
  • 4
  • 12

1 Answers1

3

Your << operator does not accept const TCHAR* as a string argument, and you have it printed out as a generic pointer.

One of the ways to fix the problem is to use A version of the API (CHAR buffer and GetModuleFileNameA function):

CHAR pBuf[MAX_PATH];
int bytes = GetModuleFileNameA(NULL, pBuf, MAX_PATH);
std::cout << bytes << "   " << pBuf << "   " <<   GetLastError() << std::endl;
Roman R.
  • 68,205
  • 6
  • 94
  • 158