diff --git a/reactos/lib/user32/misc/stubsa.c b/reactos/lib/user32/misc/stubsa.c index 6ad83deb9c2..8587c964b4f 100644 --- a/reactos/lib/user32/misc/stubsa.c +++ b/reactos/lib/user32/misc/stubsa.c @@ -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; } \ No newline at end of file +DdeQueryStringA (DWORD dw, HSZ h, LPSTR str, DWORD t, int i) { return 0; } diff --git a/reactos/lib/user32/resources/sysres.c b/reactos/lib/user32/resources/sysres.c index 61db5f30be1..e050cf83753 100644 --- a/reactos/lib/user32/resources/sysres.c +++ b/reactos/lib/user32/resources/sysres.c @@ -1,5 +1,7 @@ #include +#include +#include /*********************************************************************** * SYSRES_GetResourcePtr @@ -12,4 +14,59 @@ LPCVOID SYSRES_GetResPtr( int id ) return NULL; -} \ No newline at end of file +} + +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; +} +