Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmisc.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS Management Console 00003 * Copyright (C) 2006 - 2007 Thomas Weidenmueller 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #include "precomp.h" 00021 00022 INT 00023 LengthOfStrResource(IN HINSTANCE hInst, 00024 IN UINT uID) 00025 { 00026 HRSRC hrSrc; 00027 HGLOBAL hRes; 00028 LPWSTR lpName, lpStr; 00029 00030 if (hInst == NULL) 00031 { 00032 return -1; 00033 } 00034 00035 /* There are always blocks of 16 strings */ 00036 lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1); 00037 00038 /* Find the string table block */ 00039 if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) && 00040 (hRes = LoadResource(hInst, hrSrc)) && 00041 (lpStr = LockResource(hRes))) 00042 { 00043 UINT x; 00044 00045 /* Find the string we're looking for */ 00046 uID &= 0xF; /* position in the block, same as % 16 */ 00047 for (x = 0; x < uID; x++) 00048 { 00049 lpStr += (*lpStr) + 1; 00050 } 00051 00052 /* Found the string */ 00053 return (int)(*lpStr); 00054 } 00055 return -1; 00056 } 00057 00058 00059 static INT 00060 AllocAndLoadString(OUT LPTSTR *lpTarget, 00061 IN HINSTANCE hInst, 00062 IN UINT uID) 00063 { 00064 INT ln; 00065 00066 ln = LengthOfStrResource(hInst, 00067 uID); 00068 if (ln++ > 0) 00069 { 00070 (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED, 00071 ln * sizeof(TCHAR)); 00072 if ((*lpTarget) != NULL) 00073 { 00074 INT Ret; 00075 if (!(Ret = LoadString(hInst, uID, *lpTarget, ln))) 00076 { 00077 LocalFree((HLOCAL)(*lpTarget)); 00078 } 00079 return Ret; 00080 } 00081 } 00082 return 0; 00083 } 00084 00085 DWORD 00086 LoadAndFormatString(IN HINSTANCE hInstance, 00087 IN UINT uID, 00088 OUT LPTSTR *lpTarget, 00089 ...) 00090 { 00091 DWORD Ret = 0; 00092 LPWSTR lpFormat; 00093 va_list lArgs; 00094 00095 if (AllocAndLoadString(&lpFormat, 00096 hInstance, 00097 uID) != 0) 00098 { 00099 va_start(lArgs, lpTarget); 00100 /* let's use FormatMessage to format it because it has the ability to allocate 00101 memory automatically */ 00102 Ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING, 00103 lpFormat, 00104 0, 00105 0, 00106 (LPTSTR)lpTarget, 00107 0, 00108 &lArgs); 00109 va_end(lArgs); 00110 00111 LocalFree((HLOCAL)lpFormat); 00112 } 00113 00114 return Ret; 00115 } Generated on Sun May 27 2012 04:16:45 for ReactOS by
1.7.6.1
|