49 retbuf[255] = '\0';
50 }
51 if (!FormatMessage(
52 FORMAT_MESSAGE_ALLOCATE_BUFFER |
53 FORMAT_MESSAGE_FROM_SYSTEM |
54 FORMAT_MESSAGE_IGNORE_INSERTS,
55 NULL,
56 GetLastError(),
57 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
58 (LPTSTR) &lpMsgBuf,
59 0,
60 NULL ))
61 {
62 PrintDebugString(" %s: FormatMessage failed", msg);
63 } else {
64 PrintDebugString(" %s: %s", msg, (char *)lpMsgBuf);
65 }
66 if (lpMsgBuf != NULL) {
67 strncat((char *)retbuf, ": ", sizeof(retbuf) - strlen(retbuf) - 1);
68 strncat((char *)retbuf, (char *)lpMsgBuf, sizeof(retbuf) - strlen(retbuf) - 1);
69 }
70 return (char *)retbuf;
71 }
72
73
74 /**
75 * Send debugging info to the appropriate place
76 */
77 void PrintDebugString(char *msg, ...) {
78 #ifdef DEBUGGING_ON
79 char buf[1024];
80 va_list argprt;
81
82 va_start(argprt, msg); // set up argptr
83 vsprintf(buf, msg, argprt);
84 #ifdef SEND_TO_OUTPUT_DEBUG_STRING
85 OutputDebugString(buf);
86 #endif
87 #ifdef SEND_TO_CONSOLE
88 printf(buf);
|
49 retbuf[255] = '\0';
50 }
51 if (!FormatMessage(
52 FORMAT_MESSAGE_ALLOCATE_BUFFER |
53 FORMAT_MESSAGE_FROM_SYSTEM |
54 FORMAT_MESSAGE_IGNORE_INSERTS,
55 NULL,
56 GetLastError(),
57 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
58 (LPTSTR) &lpMsgBuf,
59 0,
60 NULL ))
61 {
62 PrintDebugString(" %s: FormatMessage failed", msg);
63 } else {
64 PrintDebugString(" %s: %s", msg, (char *)lpMsgBuf);
65 }
66 if (lpMsgBuf != NULL) {
67 strncat((char *)retbuf, ": ", sizeof(retbuf) - strlen(retbuf) - 1);
68 strncat((char *)retbuf, (char *)lpMsgBuf, sizeof(retbuf) - strlen(retbuf) - 1);
69 LocalFree(lpMsgBuf);
70 }
71 return (char *)retbuf;
72 }
73
74
75 /**
76 * Send debugging info to the appropriate place
77 */
78 void PrintDebugString(char *msg, ...) {
79 #ifdef DEBUGGING_ON
80 char buf[1024];
81 va_list argprt;
82
83 va_start(argprt, msg); // set up argptr
84 vsprintf(buf, msg, argprt);
85 #ifdef SEND_TO_OUTPUT_DEBUG_STRING
86 OutputDebugString(buf);
87 #endif
88 #ifdef SEND_TO_CONSOLE
89 printf(buf);
|