Solved

Unicode from resource dlls under Win9x

Posted on 2001-09-16
17
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 2
17 Comments
 
LVL 5

Expert Comment

by:robpitt
ID: 6488180
FindResourceEx requires that the language specified match *exactly*.

You might want to use FindResource instead.



0
 

Author Comment

by:sneeuw
ID: 6488228
Same Problem !!!
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6488449
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 5

Expert Comment

by:robpitt
ID: 6488451
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
ID: 6488493
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
ID: 6488501
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
ID: 6488533
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
ID: 6488602
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
 
LVL 5

Expert Comment

by:robpitt
ID: 6488744
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
ID: 6488843
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
ID: 6488919
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
ID: 6488975
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
ID: 6488994
> 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
ID: 6489006
> 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
ID: 6491250
> 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
ID: 6806049
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
ID: 6826271
Points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio Exe Issue, 12 38
WPF MainWindow update textbox from another class... 6 175
Example of WebAPI 7 35
SSIS 2010 Convert to SSIS 2013 On Different Box 3 63
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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