FindResource() / LoadResource() return an invalid pointer




B"H

In
www.JewishContent.org/pda/pocket-pc/bavli/arm/bavli+rashi-Whole-Shas.exe -
which has 10,000+ RCDATA resources (starting from resource id 1001 through
11,999 - which is less than 0x7FFF) in the following routine:

char *GetRes(int res)
{
HRSRC hResource;
HGLOBAL glob;
int size;
char *txt;
if(!(hResource = FindResource(gInstance, res, RT_RCDATA)))
return 0;
if(!(size = SizeofResource(gInstance, hResource)) || !(glob =
LoadResource(gInstance, hResource)))
return 0;
txt = LockResource(glob);
return txt;
}

The pointer returned by FindResource() and/or LoadResource() seems to be
sporadic, when requesting a resource, sometimes the pointer is valid,
other times the pointer is invalid.

If I compile using DevStudio 5 - for Windows Desktop, under windows 2000
this error does not show up.

While debugging an "Windows Mobile 2003 SE" device I was able to see
sometimes this was an invalid pointer.

Furthermore, while debugging, I once got a valid pointer, but partially
through data (say SizeofResource() was 100, and at txt[73] was invalid
(while txt[72] was valid)! as it happened the address where the pointer
became invalid was at memory location 0x3360:0000 - which seems to point
at "page fault" or similar which Windows CE is not handling properly
within resource DATA.

- Chaim


.



Relevant Pages

  • Re: Problem with va_ macros and arrays of arrays
    ... > the arrays passed to a ... > specific char, somewhat similar to what the standard function ... that with an array of struct, or possibly a pointer to a dynamic array ... > As I'm still a beginner in C without a copy of the standard I ...
    (comp.lang.c)
  • Re: Insufficient guarantees for null pointers?
    ... will the compiler know what the bounds are after converting that char * ... to an int *, if it could point to either of two arrays which happen to ... compares equal to the original pointer. ...
    (comp.std.c)
  • Re: when is typecasting (unsigned char*) to (char*) dangerous?
    ... > When are they not consistent? ... patterns that are valid as `unsigned char' might be invalid ... treated as "trap representations" and could cause your program ... Given a pointer to any data object, ...
    (comp.lang.c)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... programmer is "free", o happy day, to use the stack copy, test itself, ... is the pointer that is being passed as the value ... static int matchhere(char *regexp, char *text) ...
    (comp.programming)
  • Re: Pointer initialization.
    ... getting at a character that's on an odd address involves ... The pointer itself doesn't need extra "helper/magic" bits. ... pointers to char and therefore pointers to void ... On my Sparc, If I build a 64-bit application, it's possible ...
    (comp.lang.c)

Loading