Solved

Unicode from resource dlls under Win9x

Posted on 2001-09-16
17
393 Views
Last Modified: 2013-12-03
I want to do this :
http://support.microsoft.com/support/kb/articles/Q196/8/99.asp

But instead of loading it from the exe itself, I need the Unicode text
resource from a dll.


I tried :

HINSTANCE DllHandle = LoadLibrary ("resource.dll")  ;

hRC = FindResourceEx(DllHandle,
         RT_STRING,
         MAKEINTRESOURCE(block) ,
         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));

hRC always seems to be NULL but DllHandle is a valid handle to the resource
dll.

Any ideas ???
0
Comment
Question by:sneeuw
  • 8
  • 7
  • 2
17 Comments
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
FindResourceEx requires that the language specified match *exactly*.

You might want to use FindResource instead.



0
 

Author Comment

by:sneeuw
Comment Utility
Same Problem !!!
0
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
Thats odd, I have used the same trick myself and it works.

I can only suggest you double check everything...

-  Are you sure the string is actually in the DLL?
   (Check this by opening the DLL "As Type : Resource")
-  Does the DLL load correctly?
-  Is the dll module hinstance valid?
-  Is the resource Id computed correctly (i.e. stringId/16+1 )





0
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
RE : "(Check this by opening the DLL "As Type : Resource")"
I refer to a feature on the "File | Open..." menu of Visual Studio if you have it.
0
 

Author Comment

by:sneeuw
Comment Utility
Here's the code :
(Tried several things already (commented out))

UINT block = (Identifier >> 4) + 1;   // Compute block number.
UINT num   =  Identifier & 0xf;       // Compute offset into block.

HMODULE DllHandle = LoadLibraryEx("D:\\Builder\\Projects\\IsoBuster\\Lang\\russian.dll", 0, LOAD_LIBRARY_AS_DATAFILE );
// HMODULE DllHandle = LoadLibrary ("D:\\Builder\\Projects\\IsoBuster\\Lang\\russian.dll") ;
// HMODULE DllHandle = NULL ;

HRSRC   hRC = FindResourceEx(DllHandle, RT_STRING, MAKEINTRESOURCE(block) , MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));

/*
hRC = FindResource(
    DllHandle,     // resource-module handle
    MAKEINTRESOURCE(block) ,     // pointer to resource name
    RT_STRING      // pointer to resource type
   );
*/

HGLOBAL hgl = LoadResource(DllHandle, hRC);
LPWSTR  str = (LPWSTR)LockResource(hgl);

int len = 0 ;      
if (str)
    {
    for (UINT i = 0; i < num; i++)
        {
        str += *str + 1 ;
        }
    xstring.assign(str + 1, *str) ;
    len = *str ;
    }
if (DllHandle) FreeLibrary(DllHandle) ;
return len ;
0
 

Author Comment

by:sneeuw
Comment Utility
But it already fails while trying to get the handle :

hRC

Using FindResource or FindResourceEx

I think computing the variables is OK because :
- It's the same as done in the MS example
- It works great IF DllHandle is NULL !!!!!

That is, I have build a piece of the resource in the exe to test.  When this is done and DllHandle is NULL, the exact text is found in the exe itself !

I use Borland cpp Builder 5
I compile under Win98
0
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
I'm affraid I have little else to add.
It should work!


What ever is preventing it from working is probably subtle and will cause you to kick your self when you stumble accross it.

BTW : There a useful resource viewer (PE Explorer) at http://www.heaventools.com

0
 

Author Comment

by:sneeuw
Comment Utility
How subtle can it be ?
There must something I don't know yet or something I'm missing ??

I mean ... if you copy the code in your project ... does it work ?

If so, why and not on my system ?

I work under Win98 but found no reference describing issues under Win98 ?

The resoure viewer looks nice indeed !
I don't know how this can help me though ?

Can it be that a dll needs to be build in a special for the function to succeed ??
LoadString() using these dlls works like a charm !
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Expert Comment

by:robpitt
Comment Utility
The only reason I pointed you at the resource viewer was to verify that the dll did indeed contain the strings resources in the appropriate language.

Anyway if you want... post the dll to robpitt@cyberdude.com and I'll have a go at loading a string using the sample code above.
0
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
Just took a quick look at the DLL you sent me... it would appear to contain strings marked as DUTCH [BELGIUM] ???

That hardly seems right - I think you should look closely at how this dll was made.

For a quick fix change the language in FindResourceEx to MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH_BELGIAN)

0
 

Author Comment

by:sneeuw
Comment Utility
The dll was made in Belgium all right !!
I had no idea that is automatically added ?

Anyway, I tried it but the result stays the same !!
0
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
Well I just compiled a test program and it worked - I even got a bunch of Cyrillic looking text on the screen!

The only significant change was:

hRC = FindResourceEx(hDll, RT_STRING, MAKEINTRESOURCE(block) , MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH_BELGIAN));



I say again you should look at how you are compiling your dll because its resources are being flaged as the wrong language.
0
 

Author Comment

by:sneeuw
Comment Utility
> I even got a bunch of Cyrillic looking text on the
screen!

Nice.  What OS and with what app did you build ?
Borland cpp Builder will still convert the Unicode to MBCS so that the CodePage has to match the language to get someting Cyrillic looking.

Frustrating it doesn't work here !?
I have no explanation why ?
0
 

Author Comment

by:sneeuw
Comment Utility
> I even got a bunch of Cyrillic looking text on the
screen!

Nice.  What OS and with what app did you build ?
Borland cpp Builder will still convert the Unicode to MBCS so that the CodePage has to match the language to get someting Cyrillic looking.

Frustrating it doesn't work here !?
I have no explanation why ?
0
 

Author Comment

by:sneeuw
Comment Utility
> will cause you to kick your self when  you stumble accross it.

Just fainted from kicking myself too hard !!!!
Damn ...

the block :
> MAKEINTRESOURCE(block)
was incorrect

Thanks
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
sneeuw,

These questions are still open and our records show you logged in recently. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days. Please note that the recommended minimum for an "Easy" question is 50 points.
http://experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20183446
http://experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20158806
http://experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20192985
http://experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20151309
http://experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20137274
http://experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20136466
http://experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20088277
http://experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20183228

EXPERTS: Please leave your thoughts on this question here.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
Comment Utility
Points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now