Saturday, May 24, 2008

How can I insert location dependent information in my debugging messages?

Visual Studio defines the symbols __LINE__ and __FILE__ and __FUNCTION__ so you can access the line number, source file, and function where they are inserted.

Why is my message box invisible until I press the ALT key?

This means that there is a bug in your program. One possibility is that you may be returning prematurely from your WM_PAINT or WM_SYSCOMMAND message handlers.

How do I wait for a process to terminate?

Suppose you want to execute a command line utility and wait for it to finish before continuing. Then you can construct the command line including the executable path at the beginning and call the following function.
int ExecAndWait(char *cmdline, char *workingdir)
{
STARTUPINFO startupinfo = {0};
PROCESS_INFORMATION procinfo = {0};

startupinfo.cb = sizeof(startupinfo);
if(CreateProcess(NULL, cmdline, NULL, NULL, FALSE,
CREATE_NO_WINDOW, NULL, workingdir,
&startupinfo, &procinfo) == 0)
return 0;

WaitForSingleObject(procinfo.hProcess, INFINITE);
return 1;
}

How do I find the path of the temp directory?

There is a simple function called GetTempPath().
DWORD WINAPI GetTempPath(DWORD nBufferLength, LPTSTR lpBuffer);
If you need to obtain a unique filename, you can use GetTempFileName().