HINSTANCE hRes = (hResource) ? hResource :
VGetResourceHandle();
HRSRC hItem = FindResource(hRes,
MAKEINTRESOURCE((nStringID >> 4) + 1), RT_STRING);
if ( hItem )
{
HGLOBAL hMem = LoadResource(hRes, hItem);
if ( hMem )
{
LPCTSTR lpsz = (LPCTSTR)LockResource(hMem);
if ( lpsz )
return AllocCopy(lpsz, TRUE);
}
}
return FALSE;
The problem is at LPCTSTR lpsz = (LPCTSTR)LockResource(hMem);
lpsz is not NULL, but rather contains a pointer to a string with a
single space in it, not the sting (700 in my case) that I have passed
as nStringID. Does anyone have any working code that will load a
RT_STRING resource like this, or that can shed some light on the
problem? Thanks a bunch.
Todd Osborne
osbo...@bellsouth.net
If Win32 is like OS/2, then strings are stored in 'string tables' not as
separate strings. Each table contains the strings whose ids fall in its
16 value range. So strings 0 to 15 are in string table 1, strings 16 to
31 are in string table 2, etc...
So take your string id and divide it by 16 and add 1 and that's the id
of the table you want to load. Once you load it up, you walk through it
up to the (id mod 16) offset of the string you actually want. Here is an
example of that logic from my class libraries. Its from the OS/2 version
but might be exactly the same.
tCIDLib::TCard4 c4Tmp;
tCIDLib::TErrCode errcRes;
PBYTE pByte;
BYTE bTmp;
PVOID pRes;
// Load the string table with this message in it
if (errcRes = DosGetResource
(
hmodSrc
, RT_STRING
, (c4StrId / 16UL)+1
, (PVOID*)&pRes))
{
return errcRes;
}
// Get a pointer to the buffer as a byte pointer,
// skipping the 1st 2 bytes
pByte = tCIDLib::TCard1(pRes)+2;
// Loop up to the correct entry
c4Tmp = c4StrId;
c4Tmp %= 16;
for (tCIDLib::TCard4 c4Ind = 0; c4Ind < c4Tmp; c4Ind++)
{
// Get the byte length of the next string
bTmp = *pByte;
// Add it to our pointer to get to that string
pByte += bTmp+1;
}
// Get a pointer to the text
tCIDLib::Tch* pszTmp = (tCIDLib::Tch*)(pByte+1);
------------------------------------
Dean Roddey
Sr. Software Engineer
Taligent, Inc
dro...@taligent.com
int LoadString (HINSTANCE hInst, UINT uID, LPTSTR lpBuffer, int
nBufferMax);
Jason Boehle
jbo...@lawrence.ks.us
http://www.sunflower.com/~jboehle/