]>
Commit | Line | Data |
---|---|---|
b7301c43 RC |
1 | /* |
2 | * Copyright (c) 2001, Gary R. Van Sickle. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net> | |
13 | * | |
14 | */ | |
15 | ||
16 | // Yep, another string class | |
17 | ||
18 | #include "cistring.h" | |
19 | #include <stdlib.h> | |
20 | ||
21 | DWORD | |
22 | cistring::Format (UINT i, ...) | |
23 | { | |
24 | TCHAR FormatStringBuffer[256]; | |
25 | TCHAR *Buff; | |
26 | va_list arglist; | |
27 | DWORD numchars; | |
28 | ||
29 | // Get the string from the stringtable (FormatMessage() can only work with | |
30 | // literal strings or *message*table entries, which are different for some | |
31 | // inexplicable reason). | |
32 | LoadString (GetModuleHandle (NULL), i, FormatStringBuffer, 256); | |
33 | ||
34 | va_start (arglist, i); | |
35 | numchars =:: | |
36 | FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | | |
37 | FORMAT_MESSAGE_FROM_STRING, FormatStringBuffer, i, 0, | |
38 | (LPTSTR) & Buff, 0, &arglist); | |
39 | va_end (arglist); | |
40 | ||
41 | if (numchars == 0) | |
42 | { | |
43 | // Something went wrong. | |
44 | return 0; | |
45 | } | |
46 | ||
47 | buffer = new TCHAR[(numchars + 1) * sizeof (TCHAR)]; | |
48 | memcpy (buffer, Buff, (numchars + 1) * sizeof (TCHAR)); | |
49 | LocalFree (Buff); | |
50 | ||
51 | return numchars; | |
52 | } |