Issue
I'm attempting to print out an error buffer on a WINAPI GUI. As writtin, my code attempts to read or write memory which has not been allocated causing an error to be thrown.
There must be some way to elegantly convert from a character array to a LPCTSTR. What is that way?
Code
char errBuff[2048] = { '\0' };
and later
Error:
if (DAQmxFailed(error))
DAQmxGetExtendedErrorInfo(errBuff, 2048);
if (taskHandle1 != 0) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle1);
DAQmxClearTask(taskHandle1);
}
if (DAQmxFailed(error)) //TODO: Test this
printf("DAQmx Error: %s\n", errBuff);
printf("End of program, press Enter key to quit\n");
AppendText(hOut, L"NIDAQmx Error\n");
wchar_t myErrBuff = (wchar_t)errBuff;
AppendText(hOut, (LPCTSTR) myErrBuff);
break;
And the contents of AppendText
void AppendText(HWND hEditWnd, LPCTSTR Text) {
int idx = GetWindowTextLength(hEditWnd);
SendMessageW(hEditWnd, EM_SETSEL, (WPARAM)idx, (LPARAM)idx);
SendMessageW(hEditWnd, EM_REPLACESEL, 0, (LPARAM)Text);
}