mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 20:53:02 +00:00
* Create a branch for USB experiments.
svn path=/branches/usb-experiments/; revision=72629
This commit is contained in:
parent
28d8ba0d3e
commit
0ee830d7a4
23049 changed files with 0 additions and 1313991 deletions
115
base/applications/mmc/misc.c
Normal file
115
base/applications/mmc/misc.c
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* ReactOS Management Console
|
||||
* Copyright (C) 2006 - 2007 Thomas Weidenmueller
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
INT
|
||||
LengthOfStrResource(IN HINSTANCE hInst,
|
||||
IN UINT uID)
|
||||
{
|
||||
HRSRC hrSrc;
|
||||
HGLOBAL hRes;
|
||||
LPWSTR lpName, lpStr;
|
||||
|
||||
if (hInst == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* There are always blocks of 16 strings */
|
||||
lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
|
||||
|
||||
/* Find the string table block */
|
||||
if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
|
||||
(hRes = LoadResource(hInst, hrSrc)) &&
|
||||
(lpStr = LockResource(hRes)))
|
||||
{
|
||||
UINT x;
|
||||
|
||||
/* Find the string we're looking for */
|
||||
uID &= 0xF; /* position in the block, same as % 16 */
|
||||
for (x = 0; x < uID; x++)
|
||||
{
|
||||
lpStr += (*lpStr) + 1;
|
||||
}
|
||||
|
||||
/* Found the string */
|
||||
return (int)(*lpStr);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static INT
|
||||
AllocAndLoadString(OUT LPTSTR *lpTarget,
|
||||
IN HINSTANCE hInst,
|
||||
IN UINT uID)
|
||||
{
|
||||
INT ln;
|
||||
|
||||
ln = LengthOfStrResource(hInst,
|
||||
uID);
|
||||
if (ln++ > 0)
|
||||
{
|
||||
(*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
|
||||
ln * sizeof(TCHAR));
|
||||
if ((*lpTarget) != NULL)
|
||||
{
|
||||
INT Ret;
|
||||
if (!(Ret = LoadString(hInst, uID, *lpTarget, ln)))
|
||||
{
|
||||
LocalFree((HLOCAL)(*lpTarget));
|
||||
}
|
||||
return Ret;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD
|
||||
LoadAndFormatString(IN HINSTANCE hInstance,
|
||||
IN UINT uID,
|
||||
OUT LPTSTR *lpTarget,
|
||||
...)
|
||||
{
|
||||
DWORD Ret = 0;
|
||||
LPWSTR lpFormat;
|
||||
va_list lArgs;
|
||||
|
||||
if (AllocAndLoadString(&lpFormat,
|
||||
hInstance,
|
||||
uID) != 0)
|
||||
{
|
||||
va_start(lArgs, lpTarget);
|
||||
/* let's use FormatMessage to format it because it has the ability to allocate
|
||||
memory automatically */
|
||||
Ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
|
||||
lpFormat,
|
||||
0,
|
||||
0,
|
||||
(LPTSTR)lpTarget,
|
||||
0,
|
||||
&lArgs);
|
||||
va_end(lArgs);
|
||||
|
||||
LocalFree((HLOCAL)lpFormat);
|
||||
}
|
||||
|
||||
return Ret;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue