/* luislib.c - Rutinas diversas Copyright (C) 1999-2002 Luis C. Castro Skertchly This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Octubre de 1999 13 Jun 2000 - Se agrego la funcion GetErrorMessage(); 21 Sep 2000 - Se arreglo el error que se poducia cuando el número de digitos era mayor al numero de # en la mascara. Se agrego la funcion NumericFormatL que soporta numeros de 64 bits. */ #define _CRT_SECURE_NO_DEPRECATE #define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN #include #include #include char *NumericFormat(char *format, unsigned long n, char*out) // 1234567 --> 1,234,567 { int i, o; char in[32]; sprintf(in, "%lu", n); i = strlen(in); o = strlen(format) + 1; memset(out, 0, o); do { if (format[o - 1] == '#') out[--o] = in[--i]; else out[--o] = format[o]; if (!o) break; } while(i); while(o) out[--o] = ' '; return out; } char *NumericFormatL(char *format, __int64 n, char*out) // 1234567 --> 1,234,567 { int i, o; char in[32]; sprintf(in, "%I64d", n); i = strlen(in); o = strlen(format) + 1; memset(out, 0, o); do { if (format[o - 1] == '#') out[--o] = in[--i]; else out[--o] = format[o]; if (!o) break; } while(i); while(o) out[--o] = ' '; return out; } char *NumericGeneral(unsigned long n, char* out) { return NumericFormat("###,###,###,###", n, out); } DWORD PutError(char *name, char *extra) { DWORD ErrorCode; LPVOID lpMsgBuf; char buffer[2 * sizeof(void *)]; char **args; ErrorCode = GetLastError(); if (!ErrorCode) return 0; args = (char **) buffer; args[0] = extra; args[1] = NULL; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, ErrorCode, 0, (LPSTR) &lpMsgBuf, 0, args); fprintf(stderr, "\n%s - %s\n", name, lpMsgBuf); return ErrorCode; } char *GetErrorMessage(DWORD code, LPTSTR szString, DWORD nSize) { char buffer[2 * sizeof(void *)]; char **args; args = (char **) buffer; args[0] = NULL; args[1] = NULL; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, code, 0, szString, nSize, args); return szString; }