Reputation: 11399
Can somebody please tell me how I can output szFileName in a messagebox?
My attempt below does not work
//Retrieve the path to the data.dat in the same dir as our app.dll is located
TCHAR szFileName[MAX_PATH+1];
GetModuleFileName(_Module.m_hInst, szFileName, MAX_PATH+1);
StrCpy(PathFindFileName(szFileName), _T("data.dat"));
FILE *file =fopen(szFileName,"rb");
if (file)
{
fseek( file,iFirstByteToReadPos, SEEK_SET);
fread(bytes,sizeof(unsigned char), iLenCompressedBytes, file);
fclose(file);
}
else
{
MessageBox(NULL, szFileName + " not found", NULL, MB_OK);
DebugBreak();
}
Upvotes: 0
Views: 4479
Reputation: 7127
C++ does not support '+' to concatenate char or TCHAR arrays. You need to use a string class for that, or do it the C-style way with strcat and a buffer on the stack.
Since you're using C++, you can use CString if you are using ATL/mfc, or you can use something like:
typedef std::basic_string<TCHAR> tstring;
...
MessageBox(NULL, tstring(szFileName) + " not found", NULL, MB_OK);
The usual C++ plumbing has been left as an exercise to the reader.
Upvotes: 1
Reputation: 3571
You cannt add:
szFileName + " not found",
Simple fix:
MessageBox(NULL, szFileName, L"File not found", MB_OK);
Upvotes: 1