Home > Archive > Smartphone Developer Forum > January 2006 > Need help with FindResource
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Need help with FindResource
|
|
| Norman Diamond 2006-01-23, 4:00 am |
| Running in the Smartphone emulator under eVC++4 SP4.
HMODULE hModule;
HRSRC hResInfo;
DWORD ResSize;
hModule = GetModuleHandle(NULL);
hResInfo = FindResource(hModule, MAKEINTRESOURCE(IDS_SPMOUSE_MESSAGE),
RT_STRING);
hResInfo is NULL. Additional code assigns the result of GetLastError to a
variable that can be viewed in the debugger, value 1814. The VC++6 error
code viewer says 1814 means that the resource ID is not found.
Resource ID IDS_SPMOUSE_MESSAGE does exist in the executing module. A call
to LoadString with IDS_SPMOUSE_MESSAGE in an appropriate argument works just
fine.
MSDN says that hModule can't be NULL in CE, well it sure isn't, I looked at
that in the debugger too.
For some silly reason I thought that calling GetModuleHandle, FindResource,
and SizeofResource would let me compute a sufficient buffer size in one go.
Can FindResource be persuaded to find an existing resource?
| |
| Alex Feinman [MVP] 2006-01-24, 7:07 pm |
| This works fine with a boilerplate application built with VS2005 for
SP2003SE emulator. Unfortunately my eVC4 is cooked and I don't want to
reinstall it. I suggest to rty these 2 things:
1) Build a default smartphone project (create a new one) and in it try
replacing
LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
ARRAYSIZE(g_szMessage))
with
HRSRC hRsrc = FindResource(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDS_HELLO_MESSAGE), RT_STRING);
int size = SizeofResource(GetModuleHandle(NULL), hRsrc);
etc
2) Test on a real device - the eVC emulator is not the most reliable piece
of software
"Norman Diamond" <ndiamond@community.nospam> wrote in message
news:%23g%23qyCAIGHA.1760@TK2MSFTNGP10.phx.gbl...
> Running in the Smartphone emulator under eVC++4 SP4.
>
> HMODULE hModule;
> HRSRC hResInfo;
> DWORD ResSize;
> hModule = GetModuleHandle(NULL);
> hResInfo = FindResource(hModule, MAKEINTRESOURCE(IDS_SPMOUSE_MESSAGE),
> RT_STRING);
>
> hResInfo is NULL. Additional code assigns the result of GetLastError to a
> variable that can be viewed in the debugger, value 1814. The VC++6 error
> code viewer says 1814 means that the resource ID is not found.
>
> Resource ID IDS_SPMOUSE_MESSAGE does exist in the executing module. A
> call
> to LoadString with IDS_SPMOUSE_MESSAGE in an appropriate argument works
> just
> fine.
>
> MSDN says that hModule can't be NULL in CE, well it sure isn't, I looked
> at
> that in the debugger too.
>
> For some silly reason I thought that calling GetModuleHandle,
> FindResource,
> and SizeofResource would let me compute a sufficient buffer size in one
> go.
>
> Can FindResource be persuaded to find an existing resource?
>
| |
| Norman Diamond 2006-01-24, 7:07 pm |
| (1) That is essentially what I did, I did create a default smartphone Hello
Word project, and then I renamed IDS_HELLO_MESSAGE to IDS_SPMOUSE_MESSAGE
and changed its text value. To repeat, LoadString retrieves the result
properly. With LoadString, I only have to code a loop to keep retrieving it
until I can be sure I got all of it (buffer at least 2 characters longer
than the retrieved text). I tried to use FindResource and SizeofResource in
order to avoid the loop, but FindResource doesn't want to work.
(2) When we get to borrow a real device again from our customer, I bet it
still won't be unlocked. I'm stuck with the emulator.
"Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
news:e35yFOUIGHA.528@TK2MSFTNGP12.phx.gbl...
> This works fine with a boilerplate application built with VS2005 for
> SP2003SE emulator. Unfortunately my eVC4 is cooked and I don't want to
> reinstall it. I suggest to rty these 2 things:
> 1) Build a default smartphone project (create a new one) and in it try
> replacing
> LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
> ARRAYSIZE(g_szMessage))
> with
> HRSRC hRsrc = FindResource(GetModuleHandle(NULL),
> MAKEINTRESOURCE(IDS_HELLO_MESSAGE), RT_STRING);
> int size = SizeofResource(GetModuleHandle(NULL), hRsrc);
> etc
>
> 2) Test on a real device - the eVC emulator is not the most reliable piece
> of software
>
>
> "Norman Diamond" <ndiamond@community.nospam> wrote in message
> news:%23g%23qyCAIGHA.1760@TK2MSFTNGP10.phx.gbl...
>
| |
| Norman Diamond 2006-01-25, 4:15 am |
| "Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
news:e35yFOUIGHA.528@TK2MSFTNGP12.phx.gbl...
> 1) Build a default smartphone project (create a new one) and in it try
> replacing
> LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
> ARRAYSIZE(g_szMessage))
> with
> HRSRC hRsrc = FindResource(GetModuleHandle(NULL),
> MAKEINTRESOURCE(IDS_HELLO_MESSAGE), RT_STRING);
Your code will never work, for the same reason my code will never work.
FindResource really doesn't work that way on strings.
http://support.microsoft.com/defaul...=kb;en-us;20011
http://support.microsoft.com/defaul...kb;en-us;196774
http://blogs.msdn.com/oldnewthing/a...1/30/65013.aspx
Even MFC's internals (unavailable on Smartphone but observed in Win32) runs
a loop until it thinks LoadString got the entire string, instead of trying
to compute the necessary length in one go.
MSDN sure makes it easy to discover that FindResource and RT_STRING don't
mix well, NOT.
| |
| Alex Feinman [MVP] 2006-01-26, 4:01 am |
| Aha! It worked for me because my string just happened to have an id that was
a multiple of 16. And the funny thing - I've read Raymond Chen;s explanation
before, but totally forgot about it
"Norman Diamond" <ndiamond@community.nospam> wrote in message
news:uGHT8SXIGHA.2668@tk2msftngp13.phx.gbl...
> "Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
> news:e35yFOUIGHA.528@TK2MSFTNGP12.phx.gbl...
>
>
> Your code will never work, for the same reason my code will never work.
> FindResource really doesn't work that way on strings.
>
> http://support.microsoft.com/defaul...=kb;en-us;20011
> http://support.microsoft.com/defaul...kb;en-us;196774
> http://blogs.msdn.com/oldnewthing/a...1/30/65013.aspx
>
> Even MFC's internals (unavailable on Smartphone but observed in Win32)
> runs
> a loop until it thinks LoadString got the entire string, instead of trying
> to compute the necessary length in one go.
>
> MSDN sure makes it easy to discover that FindResource and RT_STRING don't
> mix well, NOT.
>
| |
| Norman Diamond 2006-01-26, 9:57 pm |
| I have a very strong suspicion that your program just happened to appear to
work because your string just happened to have an id that was a multiple of
16. I think you probably obtained the size of a different string than the
one you wanted, and by unfortunate accident it happened to be adequate
during the times that you were testing.
Raymond Chen's explanation mentioned groups of 16 but I think the
manipulations of the ids aren't quite, um, obvious.
"Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
news:%23M2bcxlIGHA.740@TK2MSFTNGP12.phx.gbl...
> Aha! It worked for me because my string just happened to have an id that
> was a multiple of 16. And the funny thing - I've read Raymond Chen;s
> explanation before, but totally forgot about it
>
> "Norman Diamond" <ndiamond@community.nospam> wrote in message
> news:uGHT8SXIGHA.2668@tk2msftngp13.phx.gbl...
>
|
|
|
|
|