MinnisotaFreezing
Programmer
Hello,
Here is my program in its entirety, with the exception of stdafx.cpp, which is not used.
[ccode]
#include "stdafx.h"
#include <string.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char * pbuff = "C:/Documents and Settings/dynacom/Local Settings/Application Data/Microsoft/Outlook/";
char text[] = "The Outlook file was not transferd because:";
char * errortext = "ERROR";
BOOL ret;
ret = CopyFile(pbuff, "\\Mainroom/Outlook/Dave/Dave.pst", FALSE);
if (!ret)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0,(LPTSTR) &lpMsgBuf,0,NULL);
//strcat(text, (LPCTSTR)lpMsgBuf);
strcat(text, errortext);
MessageBox(NULL, text, NULL, 0);
MessageBox(NULL, text, "ERROR", 0);
}
return 0;
}
[/ccode]
The problem lies with the commented strcat line. When I uncommend the line, the program crashes on exit. I step through using the debugger, past the return 0;, to the last bracket, when it crashes with the "Memory could not be "read"" message. The strcat function does what I expect, in debug the variable text is appended as I wanted. Does anyone have any info about this? I have very little experience with LPVOID types, so I am sure my mistake lies there. I hope I explained this halfway decent, I've been wrestling with this for a while. I made the offending line red.
To me this seems very strange. If you want, you could copy the code right from here, past it into a new simple Win32 Application, and it should run. Uncomment the line, and it will crash not on the now uncommented line, but on exit.
Thank you for your help,
CJB
Here is my program in its entirety, with the exception of stdafx.cpp, which is not used.
[ccode]
#include "stdafx.h"
#include <string.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char * pbuff = "C:/Documents and Settings/dynacom/Local Settings/Application Data/Microsoft/Outlook/";
char text[] = "The Outlook file was not transferd because:";
char * errortext = "ERROR";
BOOL ret;
ret = CopyFile(pbuff, "\\Mainroom/Outlook/Dave/Dave.pst", FALSE);
if (!ret)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0,(LPTSTR) &lpMsgBuf,0,NULL);
//strcat(text, (LPCTSTR)lpMsgBuf);
strcat(text, errortext);
MessageBox(NULL, text, NULL, 0);
MessageBox(NULL, text, "ERROR", 0);
}
return 0;
}
[/ccode]
The problem lies with the commented strcat line. When I uncommend the line, the program crashes on exit. I step through using the debugger, past the return 0;, to the last bracket, when it crashes with the "Memory could not be "read"" message. The strcat function does what I expect, in debug the variable text is appended as I wanted. Does anyone have any info about this? I have very little experience with LPVOID types, so I am sure my mistake lies there. I hope I explained this halfway decent, I've been wrestling with this for a while. I made the offending line red.
To me this seems very strange. If you want, you could copy the code right from here, past it into a new simple Win32 Application, and it should run. Uncomment the line, and it will crash not on the now uncommented line, but on exit.
Thank you for your help,
CJB