getErrorStr() for Windows platforms

This commit is contained in:
Alexey Pelykh 2013-02-02 10:14:47 +02:00
parent 41c7269896
commit 2362235b4c

View File

@ -74,25 +74,36 @@
namespace { namespace {
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
char* getErrorStr(DWORD err){
// The poor man's error string, just print the error code
char * errStr = (char*) malloc(9 * sizeof(char));
snprintf(errStr, 9, "%d", (int) err);
return errStr;
#pragma message("TODO") #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
// The better way to do this, if I could figure out how to convert LPTSTR to char* char* getErrorStr(DWORD err) {
//char* errStr; LPSTR errorStr = 0;
//LPTSTR s; if(!FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, LANG_SYSTEM_DEFAULT, (LPSTR)&errorStr, 0, 0))
//if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | {
// FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, &s, 0, NULL) == 0) char* errStr = (char*) malloc(9 * sizeof(char));
//{ snprintf(errStr, 9, "%d", (int) err);
// errStr.Format("Unknown error occurred (%08x)", err); return errStr;
//} else { }
// errStr = s; char* errStr = strdup(errorStr);
//} LocalFree(errorStr);
//return errStr; return errStr;
} }
#else
char* getErrorStr(DWORD err) {
LPSTR errorStr = (LPSTR)malloc(4096); //NOTE: something constant
if(!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, LANG_SYSTEM_DEFAULT, errorStr, 0, 0))
{
free(errorStr);
char* errStr = (char*) malloc(9 * sizeof(char));
snprintf(errStr, 9, "%d", (int) err);
return errStr;
}
char* errStr = strdup(errorStr);
free(errorStr);
return errStr;
}
#endif
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
void makePipe(JNIEnv* e, HANDLE p[2]) void makePipe(JNIEnv* e, HANDLE p[2])