Added LoadString() stringtable resource support

svn path=/trunk/; revision=1567
This commit is contained in:
Phillip Susi 2001-01-25 05:39:31 +00:00
parent 74e0c4a781
commit dee175afca
2 changed files with 59 additions and 11 deletions

View file

@ -207,15 +207,6 @@ LoadImageA(
int j,
UINT k) { return 0; }
int
STDCALL
LoadStringA(
HINSTANCE hInstance,
UINT uID,
LPSTR lpBuffer,
int nBufferMax) { return 0; }
int
STDCALL
DlgDirListA(
@ -315,4 +306,4 @@ UINT WINAPI
DdeInitializeA (DWORD *dw, CALLB c, DWORD x, DWORD y) { return 0; }
DWORD WINAPI
DdeQueryStringA (DWORD dw, HSZ h, LPSTR str, DWORD t, int i) { return 0; }
DdeQueryStringA (DWORD dw, HSZ h, LPSTR str, DWORD t, int i) { return 0; }

View file

@ -1,5 +1,7 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <kernel32/error.h>
/***********************************************************************
* SYSRES_GetResourcePtr
@ -12,4 +14,59 @@ LPCVOID SYSRES_GetResPtr( int id )
return NULL;
}
}
int
STDCALL
LoadStringA( HINSTANCE hInstance,
UINT uID,
LPSTR lpBuffer,
int nBufferMax)
{
HRSRC rsc;
PBYTE ptr;
int len;
int count, dest = uID % 16;
PWSTR pwstr;
UNICODE_STRING UString;
ANSI_STRING AString;
NTSTATUS Status;
rsc = FindResource( (HMODULE)hInstance,
MAKEINTRESOURCE( (uID / 16) + 1 ),
RT_STRING );
if( rsc == NULL )
return 0;
// get pointer to string table
ptr = (PBYTE)LoadResource( (HMODULE)hInstance, rsc );
if( ptr == NULL )
return 0;
for( count = 0; count <= dest; count++ )
{
// walk each of the 16 string slots in the string table
len = (*(USHORT *)ptr) * 2; // length is in unicode chars, convert to bytes
ptr += 2; // first 2 bytes are length, string follows
pwstr = (PWSTR)ptr;
ptr += len;
}
if( !len )
return 0; // zero means no string is there
// convert unitocde to ansi, and copy string to caller buffer
UString.Length = UString.MaximumLength = len;
UString.Buffer = pwstr;
memset( &AString, 0, sizeof AString );
Status = RtlUnicodeStringToAnsiString( &AString, &UString, TRUE );
if( !NT_SUCCESS( Status ) )
{
SetLastErrorByStatus( Status );
return 0;
}
if( nBufferMax > AString.Length )
nBufferMax = AString.Length;
nBufferMax--; // save room for the null
memcpy( lpBuffer, AString.Buffer, nBufferMax );
lpBuffer[nBufferMax] = 0;
RtlFreeAnsiString( &AString );
return nBufferMax;
}