free hit counter

Thursday, December 29, 2005

How to Access Serial Ports Greater Than COM9 Using C/C

All I can say is, what a pain in the ass.

char* portName= "\\\\.\\COM17";

COM ports greater than 10 must be accessed using their full path. But in all the create file documentation around comports it doesn't say anything about this. You have to stumble upon KDB-227.

linkage

Ok, and while I'm bitching about windows, why should it be so damn hard to format an error message?

void ErrorExit(LPTSTR lpszFunction)
{
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );

lpDisplayBuf = LocalAlloc(LMEM_ZEROINIT,
strlen(lpMsgBuf)+strlen(lpszFunction)+40);
wsprintf(lpDisplayBuf,
"%s failed with error %d: %s",
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, lpDisplayBuf, "Error", MB_OK);

LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}

0 Comments:

Post a Comment

<< Home