Pinvoke LoadResource RT_HTML

S

Sonya

Hi,
I stuck reading HTML Resources from a library file. When I take look at
the result with debugger there is only junk in it. Need some help please...

// ----- Code -----

[DllImport("kernel32", SetLastError = true)]
static extern IntPtr LoadLibrary(string lpFileName);

[DllImport("kernel32", SetLastError = true)]
static extern IntPtr FindResource(IntPtr hModule, int lpName, int lpType);

[DllImport("kernel32", SetLastError = true)]
static extern IntPtr LoadResource(IntPtr hModule, IntPtr hResInfo);

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool FreeLibrary(IntPtr hModule);

[DllImport("kernel32.dll")]
static extern IntPtr LockResource(IntPtr hResData);

[DllImport("kernel32.dll", SetLastError = true)]
static extern int SizeofResource(IntPtr hModule, IntPtr hResInfo);

private const int RT_HTML = 0x00000017;
string Result = String.Empty;

IntPtr hModule = LoadLibrary(fileName);
if (hModule != IntPtr.Zero)
{
IntPtr hResInfo = FindResource(hModule, ids_name, RT_HTML);
if (hResInfo != IntPtr.Zero)
{
int size = SizeofResource(hModule, hResInfo);
if (size > 0)
{
IntPtr hGlobal = LoadResource(hModule, hResInfo);
if (hGlobal != IntPtr.Zero)
{
IntPtr pResource = LockResource(hGlobal);
if (pResource != null)
{
Result = Marshal.PtrToStringAnsi(pResource, size);
}
}
}
}
FreeLibrary(hModule);
return Result;
}
 
M

Mattias Sjögren

I stuck reading HTML Resources from a library file. When I take look at
the result with debugger there is only junk in it. Need some help please...

Have you tried reading the data into a byte[] instead (with
Marshal.Copy) and print out the content of that? Maybe the resource
uses an encoding other than ANSI?


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top