Importing MFC resources

Hi,

I have a very large project that consists of several MFC applications, all 
created with VS 7.1.  What I'd like to do now is create MFC resources that 
can be shared among these  different applications.  For example, I'd like 
to create a dialog resource, along with the code to handle that dialog's 
controls, and then bundle it up for use by all the other applications.

I've tried a few things with very little success.  I seem to always end up 
with resource ID conflicts when I import a resource into another project.  
I can manually patch this up in the resource.h file, but there will be many 
of these shared resources created by many different developers, so it is 
difficult to check all of the resource.h files against each other for 
conflicts.  I can do this if there is no other way, I'd be happy to hear of 
any alternatives.

Thanks in advance,
Pat
0
none2663 (41)
9/25/2007 5:47:22 AM
vc.mfc 33608 articles. 0 followers. Follow

28 Replies
1051 Views

Similar Articles

[PageSpeed] 35

"Pat" <none@none.none> ha scritto nel messaggio 
news:Xns99B5F214A5BE8none@140.99.99.130...

> I have a very large project that consists of several MFC applications, all
> created with VS 7.1.  What I'd like to do now is create MFC resources that
> can be shared among these  different applications.  For example, I'd like
> to create a dialog resource, along with the code to handle that dialog's
> controls, and then bundle it up for use by all the other applications.

You may consider MFC Extension DLLs...

Giovanni


0
9/25/2007 6:27:53 AM
Yes, this is a classic problem.  ActiveX and DLLs can solve this, but there's no way right
now to make resources modular.  The resource compiler philosophy hasn't changed since
1985.
The only other solution is to assign your shared resources with IDs in some known range,
e.g., > 20000, and just make sure that everyone knows these ranges are reserved.  Since a
resource typically can't have more than 256 controls, you can break the range in 256-value
segments, and just document what these ranges are.
				joe
On Tue, 25 Sep 2007 05:47:22 GMT, Pat <none@none.none> wrote:

>Hi,
>
>I have a very large project that consists of several MFC applications, all 
>created with VS 7.1.  What I'd like to do now is create MFC resources that 
>can be shared among these  different applications.  For example, I'd like 
>to create a dialog resource, along with the code to handle that dialog's 
>controls, and then bundle it up for use by all the other applications.
>
>I've tried a few things with very little success.  I seem to always end up 
>with resource ID conflicts when I import a resource into another project.  
>I can manually patch this up in the resource.h file, but there will be many 
>of these shared resources created by many different developers, so it is 
>difficult to check all of the resource.h files against each other for 
>conflicts.  I can do this if there is no other way, I'd be happy to hear of 
>any alternatives.
>
>Thanks in advance,
>Pat
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/25/2007 6:35:13 AM
There's technical note 35 that you may find useful

http://msdn2.microsoft.com/en-us/library/6t3612sk(VS.80).aspx

Pedro

Pat wrote:
> Hi,
> 
> I have a very large project that consists of several MFC applications, all 
> created with VS 7.1.  What I'd like to do now is create MFC resources that 
> can be shared among these  different applications.  For example, I'd like 
> to create a dialog resource, along with the code to handle that dialog's 
> controls, and then bundle it up for use by all the other applications.
> 
> I've tried a few things with very little success.  I seem to always end up 
> with resource ID conflicts when I import a resource into another project.  
> I can manually patch this up in the resource.h file, but there will be many 
> of these shared resources created by many different developers, so it is 
> difficult to check all of the resource.h files against each other for 
> conflicts.  I can do this if there is no other way, I'd be happy to hear of 
> any alternatives.
> 
> Thanks in advance,
> Pat
0
none89 (807)
9/25/2007 7:56:42 AM
Why do resources have to have numeric ids ?

> -----Original Message-----
> From: Joseph M. Newcomer [mailto:newcomer@flounder.com]
> Posted At: Tuesday, 25 September 2007 4:35 PM
> Posted To: microsoft.public.vc.mfc
> Conversation: Importing MFC resources
> Subject: Re: Importing MFC resources
> 
> Yes, this is a classic problem.  ActiveX and DLLs can solve this, but
> there's no way right
> now to make resources modular.  The resource compiler philosophy
hasn't
> changed since
> 1985.
> The only other solution is to assign your shared resources with IDs in
> some known range,
> e.g., > 20000, and just make sure that everyone knows these ranges are
> reserved.  Since a
> resource typically can't have more than 256 controls, you can break
the
> range in 256-value
> segments, and just document what these ranges are.
> 				joe
> On Tue, 25 Sep 2007 05:47:22 GMT, Pat <none@none.none> wrote:
> 
> >Hi,
> >
> >I have a very large project that consists of several MFC
applications,
> all
> >created with VS 7.1.  What I'd like to do now is create MFC resources
> that
> >can be shared among these  different applications.  For example, I'd
> like
> >to create a dialog resource, along with the code to handle that
> dialog's
> >controls, and then bundle it up for use by all the other
applications.
> >
> >I've tried a few things with very little success.  I seem to always
> end up
> >with resource ID conflicts when I import a resource into another
> project.
> >I can manually patch this up in the resource.h file, but there will
be
> many
> >of these shared resources created by many different developers, so it
> is
> >difficult to check all of the resource.h files against each other for
> >conflicts.  I can do this if there is no other way, I'd be happy to
> hear of
> >any alternatives.
> >
> >Thanks in advance,
> >Pat
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm

0
anyone3666 (139)
9/25/2007 9:14:14 PM
"Ian Semmel" <anyone@rocketcomp.com.au> wrote in 
news:401792FEA1D647648114AA0CC6698B67@DIMITY:

> Why do resources have to have numeric ids ?

Excellent question...  I'd love to know the answer.  Even in just a single 
application, I find myself having to clean up occaisional quirks in the 
resource.h file.  For example, sometimes deleting a resource doesn't delete 
the corresponding ID.  And even if the resource ID is deleted, it often 
leaves a hole in the numbering sequence.  Neither of these is really a bug, 
but it takes a certain degree of OCD to be a great programmer...  :) and 
things like this just bug me.
0
none2663 (41)
9/26/2007 12:13:00 AM
"Ian Semmel" <anyone@rocketcomp.com.au> wrote in message 
news:401792FEA1D647648114AA0CC6698B67@DIMITY...
> Why do resources have to have numeric ids ?
>

AFAIK, resources are in fact strings.  API's like FindResourceEx() takes a 
string parameter to specify the resource, not a UINT.  The MAKEINTRESOURCE() 
macro takes a UINT and casts it to a string, which you are supposed to use 
for API's like this.

I'm not sure historically why resource ID's are theoretically UINT's but are 
implemented as strings.

-- David 


0
dc2983 (3206)
9/26/2007 2:35:02 AM
Funny, I was having the same thought tonight driving down to see an opera.  Thought I'd
mention that when I got back, and I see you've beaten me to it.  

There are two limitations: as far as I know, you can't use symbolic names on STRINGTABLE
resources, and you can't use symbolic names for control IDs.

If Micorosoft put any effort into RC, it needs the ability to move away from the 1980s-era
"resource.h" model to one where we have truly modular concepts, such as names scoped by
dialog, the notion that the linker (not the compiler) binds values (this should be easy,
by the way; most linkers already have all the capabilities to do this), and so on.  .NET
avoids this by not using resources, but instead dumping raw code into the front of the
program (I wrote a C# program with a dozen dialogs and about 60 controls on the main
dialog, and the code was terrifying.  Also hard to maintain, and given the fact that the
IDE sucks for C#, I had to do a lot of hand-editing of the C# code.  I also learned to
truly detest the IDE editor--prior to this experience I had merely disliked it).  The
environment should support multiple .rc files in a project, and be capable of linking
multiple .res files.  Gee, it would be liking dragging the programming methodology out of
the 1950s to the 1960s!
					joe

On Wed, 26 Sep 2007 07:14:14 +1000, "Ian Semmel" <anyone@rocketcomp.com.au> wrote:

>Why do resources have to have numeric ids ?
>
>> -----Original Message-----
>> From: Joseph M. Newcomer [mailto:newcomer@flounder.com]
>> Posted At: Tuesday, 25 September 2007 4:35 PM
>> Posted To: microsoft.public.vc.mfc
>> Conversation: Importing MFC resources
>> Subject: Re: Importing MFC resources
>> 
>> Yes, this is a classic problem.  ActiveX and DLLs can solve this, but
>> there's no way right
>> now to make resources modular.  The resource compiler philosophy
>hasn't
>> changed since
>> 1985.
>> The only other solution is to assign your shared resources with IDs in
>> some known range,
>> e.g., > 20000, and just make sure that everyone knows these ranges are
>> reserved.  Since a
>> resource typically can't have more than 256 controls, you can break
>the
>> range in 256-value
>> segments, and just document what these ranges are.
>> 				joe
>> On Tue, 25 Sep 2007 05:47:22 GMT, Pat <none@none.none> wrote:
>> 
>> >Hi,
>> >
>> >I have a very large project that consists of several MFC
>applications,
>> all
>> >created with VS 7.1.  What I'd like to do now is create MFC resources
>> that
>> >can be shared among these  different applications.  For example, I'd
>> like
>> >to create a dialog resource, along with the code to handle that
>> dialog's
>> >controls, and then bundle it up for use by all the other
>applications.
>> >
>> >I've tried a few things with very little success.  I seem to always
>> end up
>> >with resource ID conflicts when I import a resource into another
>> project.
>> >I can manually patch this up in the resource.h file, but there will
>be
>> many
>> >of these shared resources created by many different developers, so it
>> is
>> >difficult to check all of the resource.h files against each other for
>> >conflicts.  I can do this if there is no other way, I'd be happy to
>> hear of
>> >any alternatives.
>> >
>> >Thanks in advance,
>> >Pat
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/26/2007 4:44:18 AM
If you have

IDD_WHATEVER DIALOG ...

you can't tell if you are using a string name or an integer to name the dialog.  If you
have

#define IDD_WHATEVER 200

preceding it.  The preprocessor converts it to

200 DIALOG ...

and now it is treated as a numeric ID.

If you do FindResourceEx, you must either use a string name, e.g.,

FindResourceEx(module, RT_DIALOG, _T("IDD_WHATEVER"), 0);

but if the #define IDD_WHATEVER 200 is done, you have to do

FindResourceEx(module, RT_DIALOG, MAKEINTRESOURCE(IDD_WHATEVER), 0);
or, if you like to live dangerously you could write
FindResourceEx(module, RT_DIALOG, _T("#200"), 0);

but this would not be able to track changes in the resource IDs, and is generaly not
recommended in this context.


Note that RT_DIALOG is MAKEINTRESOURCE(5)

I store an RTF resource as a set of names, 

HELP_NAME1 RTF res\name1.rtf
HELP_THING   RTF res\thing.rtf

and so on, and when I want to create a resource name from a string (the strings are
computed from various contexts)

CString s = _T("HELP_");
s += computed_name;

FindResourceEx(AfxGetInstanceHandle(), _T("RTF"), s, 0);

and it works very well.
				joe

On Tue, 25 Sep 2007 19:35:02 -0700, "David Ching" <dc@remove-this.dcsoft.com> wrote:

>"Ian Semmel" <anyone@rocketcomp.com.au> wrote in message 
>news:401792FEA1D647648114AA0CC6698B67@DIMITY...
>> Why do resources have to have numeric ids ?
>>
>
>AFAIK, resources are in fact strings.  API's like FindResourceEx() takes a 
>string parameter to specify the resource, not a UINT.  The MAKEINTRESOURCE() 
>macro takes a UINT and casts it to a string, which you are supposed to use 
>for API's like this.
>
>I'm not sure historically why resource ID's are theoretically UINT's but are 
>implemented as strings.
>
>-- David 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/26/2007 4:53:49 AM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:rtojf35j00fu0ac4o8r86eqbailec69i2e@4ax.com...
> If you have
>
> IDD_WHATEVER DIALOG ...
>
> you can't tell if you are using a string name or an integer to name the 
> dialog.  If you
> have
>
> #define IDD_WHATEVER 200
>
> preceding it.  The preprocessor converts it to
>
> 200 DIALOG ...
>
> and now it is treated as a numeric ID.
>
> If you do FindResourceEx, you must either use a string name, e.g.,
>
> FindResourceEx(module, RT_DIALOG, _T("IDD_WHATEVER"), 0);
>
> but if the #define IDD_WHATEVER 200 is done, you have to do
>
> FindResourceEx(module, RT_DIALOG, MAKEINTRESOURCE(IDD_WHATEVER), 0);
> or, if you like to live dangerously you could write
> FindResourceEx(module, RT_DIALOG, _T("#200"), 0);
>
> but this would not be able to track changes in the resource IDs, and is 
> generaly not
> recommended in this context.
>
>
> Note that RT_DIALOG is MAKEINTRESOURCE(5)
>
> I store an RTF resource as a set of names,
>
> HELP_NAME1 RTF res\name1.rtf
> HELP_THING   RTF res\thing.rtf
>
> and so on, and when I want to create a resource name from a string (the 
> strings are
> computed from various contexts)
>
> CString s = _T("HELP_");
> s += computed_name;
>
> FindResourceEx(AfxGetInstanceHandle(), _T("RTF"), s, 0);
>
> and it works very well.


I still don't see the advantage of using UINTs instead of strings, although 
in another post you said strings could not be used for certain kind of 
resource types like stringtables.

-- David 


0
dc2983 (3206)
9/26/2007 4:56:58 AM
> I still don't see the advantage of using UINTs instead of strings, although 
> in another post you said strings could not be used for certain kind of 
> resource types like stringtables.

1. If I do GetString( "idHelo" ) [typo], I get not compile time error if 
idHelo resource string is not defined, I get a runtime error.

If I do GetString( idHelo ), I get a compile time error (because the 
resource.h file defines idHello, not idHelo)

2. Speed: it is faster to do a numeric lookup than a string lookup

3. Size: a numeric ID takes 16 bytes. A string id takes more.


But you can still use string IDs for dialogs.



-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
9/26/2007 6:33:38 AM
> What I'd like to do now is create MFC resources that 
> can be shared among these  different applications.  For example, I'd like 
> to create a dialog resource, along with the code to handle that dialog's 
> controls, and then bundle it up for use by all the other applications.

Best option: DLLs. Not only good for resources, but for code. Very modular, 
you can really share the physical file.
In fact, this is what DLLs where created :-) Since the down of time code is 
shared using a library. And DLL means Dynamic Load Library :-)


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
9/26/2007 6:37:12 AM
"Mihai N." <nmihai_year_2000@yahoo.com> wrote in
news:Xns99B6F0536AFA6MihaiN@207.46.248.16: 

> Best option: DLLs. Not only good for resources, but for code. Very
> modular, you can really share the physical file.
> In fact, this is what DLLs where created :-) Since the down of time
> code is shared using a library. And DLL means Dynamic Load Library :-)


Thanks, someone else also suggested MFC extension DLLs.  I researched this 
a bit, but it looks like this does nothing to solve the resource ID 
conflict issue.  If the DLL has a dialog (for example) with the same ID as 
a dialog in the main application, the behavior will be incorrect.

While searching, I found this:
http://www.codeguru.com/cpp/w-p/dll/print.php/c107/

The language is a little rough, and I'm not sure I understand the comments 
about "MY_DLL_NAMEDLL", but it basically looks like he uses 
AfxSetResourceHandle() to manually update the resource "module."

Anyone tried a similar approach?
0
none2663 (41)
9/26/2007 6:59:55 AM
"Joseph M. Newcomer" <newcomer@flounder.com> ha scritto nel messaggio 
news:qhojf3pcuvk2km1hfsh46n1ilbtdd781e9@4ax.com...

> .NET
> avoids this by not using resources, but instead dumping raw code into the 
> front of the
> program (I wrote a C# program with a dozen dialogs and about 60 controls 
> on the main

You should consider WPF and XAML!
(I agree with you that it is better to keep resources separate from code.)

They seems great (and things get more interesting with the new release of 
SilverLight).

You may have a preview of WPF (with a designer - because without a proper 
designer WPF seems hard to me) downloading the Orcas beta2 Express Edition 
(or only the C# or VB.NET IDE), which is free.

http://msdn2.microsoft.com/en-us/express/future/bb421473.aspx

Giovanni


0
9/26/2007 9:06:07 AM
"Mihai N." <nmihai_year_2000@yahoo.com> wrote in message 
news:Xns99B6EFB86F721MihaiN@207.46.248.16...
>> I still don't see the advantage of using UINTs instead of strings, 
>> although
>> in another post you said strings could not be used for certain kind of
>> resource types like stringtables.
>
> 1. If I do GetString( "idHelo" ) [typo], I get not compile time error if
> idHelo resource string is not defined, I get a runtime error.
>
> If I do GetString( idHelo ), I get a compile time error (because the
> resource.h file defines idHello, not idHelo)
>

But resource.h could just as well have

#define ID_HELLO    _T("THIS_IS_THE RESOURCE_HANDLE_FOR_HELLO")

and the code could refererence ID_HELLO as it does today and get the 
compiler error.


> 2. Speed: it is faster to do a numeric lookup than a string lookup
>

True, but since the resource API's take string parameters as opposed to 
numeric ones (e.g. FindResourceEx), it would seem there is no speed 
advantage.


> 3. Size: a numeric ID takes 16 bytes. A string id takes more.
>

Actually, a numeric ID (UINT) takes 4 bytes, and you're right a string takes 
more.


> But you can still use string IDs for dialogs.
>

Why only for dialogs?

-- David



0
dc2983 (3206)
9/26/2007 11:05:56 AM
"Pat" <none@none.none> wrote in message 
news:Xns99B7A3D6BA01none@140.99.99.130...
> Thanks, someone else also suggested MFC extension DLLs.  I researched this
> a bit, but it looks like this does nothing to solve the resource ID
> conflict issue.  If the DLL has a dialog (for example) with the same ID as
> a dialog in the main application, the behavior will be incorrect.
>

Within your DLL, the code to display the dialog contained in the DLL 
resources could first call AfxSetResourceHandle() to specify the DLL 
instance prior to showing the dialog, and then call it again to reset the 
resource handle back to the original.  That would ensure the DLL (and only 
the DLL) could display it's own dialogs.

This could be accomplished by overriding CDialog::DoModal() for all derived 
classes exported by the DLL.

But the idea of storing resources and code together in a DLL like this is 
not compatible with the Satellite DLL model of creating a separate DLL per 
language for localization purposes.  The goal is to SEPARATE resources from 
code so the localizers only work with a DLL containing resources.  Your goal 
is the opposite, to COMBINE them!  :-)

-- David


0
dc2983 (3206)
9/26/2007 11:16:51 AM
See below...
On Wed, 26 Sep 2007 04:05:56 -0700, "David Ching" <dc@remove-this.dcsoft.com> wrote:

>"Mihai N." <nmihai_year_2000@yahoo.com> wrote in message 
>news:Xns99B6EFB86F721MihaiN@207.46.248.16...
>>> I still don't see the advantage of using UINTs instead of strings, 
>>> although
>>> in another post you said strings could not be used for certain kind of
>>> resource types like stringtables.
>>
>> 1. If I do GetString( "idHelo" ) [typo], I get not compile time error if
>> idHelo resource string is not defined, I get a runtime error.
>>
>> If I do GetString( idHelo ), I get a compile time error (because the
>> resource.h file defines idHello, not idHelo)
>>
>
>But resource.h could just as well have
>
>#define ID_HELLO    _T("THIS_IS_THE RESOURCE_HANDLE_FOR_HELLO")
>
>and the code could refererence ID_HELLO as it does today and get the 
>compiler error.
>
>
>> 2. Speed: it is faster to do a numeric lookup than a string lookup
>>
>
>True, but since the resource API's take string parameters as opposed to 
>numeric ones (e.g. FindResourceEx), it would seem there is no speed 
>advantage.
****
Not true.  The way it works is that the APIs look at the value; if it is < 65536, then it
is an integer, and an integer lookup is done.  This is faster.  Seriously.  But the other
point is that it hardly ever matters that it is faster.  You're about to launch a dialog,
which is going to take the user tens to hundreds of milliseconds to respond to, and a few
hundred microseconds spent doing the lookup just don't matter.
****
>
>
>> 3. Size: a numeric ID takes 16 bytes. A string id takes more.
>>
>
>Actually, a numeric ID (UINT) takes 4 bytes, and you're right a string takes 
>more.
>
>
>> But you can still use string IDs for dialogs.
>>
>
>Why only for dialogs?
****
As far as I know, you can use them for any resource other than STRINGTABLE.  You can use
them for menus, icons, bitmaps, etc.
				joe
****
>
>-- David
>
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/26/2007 4:00:33 PM
It should solve it.  The point being that if the dynamic resource lookup is done right,
the DLL will find the resource in its own resource segment first, and the fact that there
is another resource in the main .exe of the same name/number doesn't matter.
					joe

On Wed, 26 Sep 2007 06:59:55 GMT, Pat <none@none.none> wrote:

>"Mihai N." <nmihai_year_2000@yahoo.com> wrote in
>news:Xns99B6F0536AFA6MihaiN@207.46.248.16: 
>
>> Best option: DLLs. Not only good for resources, but for code. Very
>> modular, you can really share the physical file.
>> In fact, this is what DLLs where created :-) Since the down of time
>> code is shared using a library. And DLL means Dynamic Load Library :-)
>
>
>Thanks, someone else also suggested MFC extension DLLs.  I researched this 
>a bit, but it looks like this does nothing to solve the resource ID 
>conflict issue.  If the DLL has a dialog (for example) with the same ID as 
>a dialog in the main application, the behavior will be incorrect.
>
>While searching, I found this:
>http://www.codeguru.com/cpp/w-p/dll/print.php/c107/
>
>The language is a little rough, and I'm not sure I understand the comments 
>about "MY_DLL_NAMEDLL", but it basically looks like he uses 
>AfxSetResourceHandle() to manually update the resource "module."
>
>Anyone tried a similar approach?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/26/2007 4:02:27 PM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:rh0lf392e132pkd0l1g94ekkdh20t69j8v@4ax.com...
> It should solve it.  The point being that if the dynamic resource lookup 
> is done right,
> the DLL will find the resource in its own resource segment first, and the 
> fact that there
> is another resource in the main .exe of the same name/number doesn't 
> matter.

MFC has a concept such as this?  I never knew that.  I thought all the 
resources came from the current AfxGetResourceHandle() module instance no 
matter whether the call that uses the resource is in a DLL or not.

-- David 


0
dc2983 (3206)
9/26/2007 11:02:40 PM
> #define ID_HELLO    _T("THIS_IS_THE RESOURCE_HANDLE_FOR_HELLO")
Then what's the point to use string IDs?
:-)


> True, but since the resource API's take string parameters as opposed to 
> numeric ones (e.g. FindResourceEx), it would seem there is no speed 
> advantage.
The parameter is not really a string. Just declared as a string.
Basically if the value is above 2^16, then it is interpreted as pointer
to string, otherwise is cast to an int.
(see IS_INTRESOURCE and MAKEINTRESOURCE(A/W) in WinUser.h)

See also
    http://support.microsoft.com/kb/q196774/
and
    http://blogs.msdn.com/oldnewthing/archive/2004/01/30/65013.aspx


>> But you can still use string IDs for dialogs.
> Why only for dialogs?
Don't ask me :-)
I can only guess: the size/performance penalty is lower for dialogs.
Compared to loading and creating a full dialog (create all the controls, set 
coordinates, text, color, font, etc.), the lookup is nothing.
And you have wey less dialogs than strings, so size penalty is also lower.
But, again, this is just a guess :-)



-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
9/27/2007 5:46:15 AM
MFC Extension DLLs are supposed to add their resource segment to a list structure which is
searched starting in the current DLL's resources and working upward to the .exe file.  The
core idea being that a DLL is supposed to be a true "extension" of the existing
environment.  This is different from a non-extension DLL where AFX_MANAGE_STATE is used to
control the handle.  

Frankly, I think both of these are design errors.  Note that in VS.NET and beyond,
LoadString allows specification of a resource handle.  I see no reason that we couldn't
use this technique for all types of resource loads.
				joe
On Wed, 26 Sep 2007 16:02:40 -0700, "David Ching" <dc@remove-this.dcsoft.com> wrote:

>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:rh0lf392e132pkd0l1g94ekkdh20t69j8v@4ax.com...
>> It should solve it.  The point being that if the dynamic resource lookup 
>> is done right,
>> the DLL will find the resource in its own resource segment first, and the 
>> fact that there
>> is another resource in the main .exe of the same name/number doesn't 
>> matter.
>
>MFC has a concept such as this?  I never knew that.  I thought all the 
>resources came from the current AfxGetResourceHandle() module instance no 
>matter whether the call that uses the resource is in a DLL or not.
>
>-- David 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/27/2007 5:52:17 AM
Joseph M. Newcomer <newcomer@flounder.com> wrote in
news:m4hmf3lln1h61kh9kuq44mbkudl084dfu7@4ax.com: 

> Frankly, I think both of these are design errors.  Note that in VS.NET
> and beyond, LoadString allows specification of a resource handle.  I
> see no reason that we couldn't use this technique for all types of
> resource loads. 
>                     joe

Agreed...  Or better yet, why doesn't any code in CDialog that touches a 
resource ID just call AfxSetResourceHandle()?  Why would you ever want to 
load the *wrong* resource?

Pat
0
none2663 (41)
9/27/2007 7:32:21 AM
I have used string IDs for all kinds of resources.  Just not STRINGTABLE entries.  There
is no limitation to use them just for dialogs.
					joe

On Wed, 26 Sep 2007 22:46:15 -0700, "Mihai N." <nmihai_year_2000@yahoo.com> wrote:

>> #define ID_HELLO    _T("THIS_IS_THE RESOURCE_HANDLE_FOR_HELLO")
>Then what's the point to use string IDs?
>:-)
>
>
>> True, but since the resource API's take string parameters as opposed to 
>> numeric ones (e.g. FindResourceEx), it would seem there is no speed 
>> advantage.
>The parameter is not really a string. Just declared as a string.
>Basically if the value is above 2^16, then it is interpreted as pointer
>to string, otherwise is cast to an int.
>(see IS_INTRESOURCE and MAKEINTRESOURCE(A/W) in WinUser.h)
>
>See also
>    http://support.microsoft.com/kb/q196774/
>and
>    http://blogs.msdn.com/oldnewthing/archive/2004/01/30/65013.aspx
>
>
>>> But you can still use string IDs for dialogs.
>> Why only for dialogs?
>Don't ask me :-)
>I can only guess: the size/performance penalty is lower for dialogs.
>Compared to loading and creating a full dialog (create all the controls, set 
>coordinates, text, color, font, etc.), the lookup is nothing.
>And you have wey less dialogs than strings, so size penalty is also lower.
>But, again, this is just a guess :-)
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/27/2007 5:27:56 PM
> I have used string IDs for all kinds of resources.  Just not STRINGTABLE
> entries.  There
> is no limitation to use them just for dialogs.

True. I don't know why the limitation, but this is it.
Maybe the same explanation is valid for other resources:
 - many strings vs. few bitmaps/icons/dialogs/menus
 - the size report between id and the object identified
   (a string id is much smaller than a dialog/bitmap/menu
   but can be close to a string length)
   So the overhead is too big for strings.

Anyway, this is just pointless guessing :-)
Right now the real answer to "why" is probably "because MS says so" :-)


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
9/28/2007 6:56:17 AM
Strings are stored 16 strings to a block, so the way a block is computed is to take the
index / 16, then find elements in the block based on the index % 16.
				joe

On Thu, 27 Sep 2007 23:56:17 -0700, "Mihai N." <nmihai_year_2000@yahoo.com> wrote:

>> I have used string IDs for all kinds of resources.  Just not STRINGTABLE
>> entries.  There
>> is no limitation to use them just for dialogs.
>
>True. I don't know why the limitation, but this is it.
>Maybe the same explanation is valid for other resources:
> - many strings vs. few bitmaps/icons/dialogs/menus
> - the size report between id and the object identified
>   (a string id is much smaller than a dialog/bitmap/menu
>   but can be close to a string length)
>   So the overhead is too big for strings.
>
>Anyway, this is just pointless guessing :-)
>Right now the real answer to "why" is probably "because MS says so" :-)
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/28/2007 2:02:21 PM
> But resource.h could just as well have
> 
> #define ID_HELLO    _T("THIS_IS_THE RESOURCE_HANDLE_FOR_HELLO")
> 
> and the code could refererence ID_HELLO as it does today and get the 
> compiler error.

1. But you are back to square one: keeping in sync 3 files
   (c, rc, h)

2. And it still does not solve the compile time error detection
  c:  LoadString( ID_HELLO, ... )
  h:  #define ID_HELLO _T("THIS_IS_THE RESOURCE_HANDLE_FOR_HELLO")
  rc: "THIS_IS_THE RESOURCE_HANDLE_FOR_HELO" "The Id has a typo!"

The nice part with numeric Id is that the same header file defines
the IDs both for the C and the RC.


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
9/29/2007 7:53:35 AM
> Strings are stored 16 strings to a block, so the way a block is computed
> is to take the
> index / 16, then find elements in the block based on the index % 16.
Exactly.
Which means that in fact you spend less than 16 bits per string.
Imagine having a string Id for each string.

This might not be relevant these days, but at the time when it was
designed was important.

The speed/size limitations are not that important now, but I
still don't see any major advantage with using a string ID.


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
9/29/2007 7:56:51 AM
But you can't create a resource with a string name for a string resource.  There isn't a
syntax for it.  STRINGTABLE is its own weird little world unlike all the rest of the
resources that can exist.
					joe

On Sat, 29 Sep 2007 00:53:35 -0700, "Mihai N." <nmihai_year_2000@yahoo.com> wrote:

>> But resource.h could just as well have
>> 
>> #define ID_HELLO    _T("THIS_IS_THE RESOURCE_HANDLE_FOR_HELLO")
>> 
>> and the code could refererence ID_HELLO as it does today and get the 
>> compiler error.
>
>1. But you are back to square one: keeping in sync 3 files
>   (c, rc, h)
>
>2. And it still does not solve the compile time error detection
>  c:  LoadString( ID_HELLO, ... )
>  h:  #define ID_HELLO _T("THIS_IS_THE RESOURCE_HANDLE_FOR_HELLO")
>  rc: "THIS_IS_THE RESOURCE_HANDLE_FOR_HELO" "The Id has a typo!"
>
>The nice part with numeric Id is that the same header file defines
>the IDs both for the C and the RC.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/30/2007 4:56:24 AM
> But you can't create a resource with a string name for a string resource.  
There isn't a
> syntax for it.  STRINGTABLE is its own weird little world unlike all the 
rest of the
> resources that can exist.

I know.
This is was an aswer to David explaining why in fact there is benefit
from a string ID even if the stringtable would allow such a thing.


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
10/5/2007 5:03:54 AM
Reply:

Similar Artilces:

Importing messages #6
I have a backup disk that I would like to impport from, but obviously I do not know how. When I double-click a message, it does not recognize which program to use to open it and takes me to an MS site. All of these have a ..dbx extension. Thank you. "Jennifer" <Jennifer@discussions.microsoft.com> wrote in message news:3398C3D3-FDD8-41CB-8F73-C445B56F6CF7@microsoft.com... >I have a backup disk that I would like to impport from, but obviously I do > not know how. When I double-click a message, it does not recognize which > program to use to open it and takes me...

Import and export
Trying to salvage my data and it was suggestd I import and export files, do I need to import and export closed accounts as well? Only if you want them in the new file. In order to export a closed account, you'll need to first specify that it is open in Money. "Mike" <anonymous@discussions.microsoft.com> wrote in message news:269701c3fc78$9f29fcf0$a301280a@phx.gbl... > Trying to salvage my data and it was suggestd I import and > export files, do I need to import and export closed > accounts as well? ...

Importing data
When I import sales data through 3CDaemon, I get cells that I of data that I cannot use in formulas. It is like they are corrupted. But can copy the info from cell to cell, just cannot use in formula (ex. =if(dd04="N",1,0. Formula does not error out, but it makes no difference if N, U, or anything else is in dd04. It answers back 0. How can I fix this ? Just a couple of guesses (I have no idea what 3CDaemon is). First, Get a copy of Chip Pearson's CellView Addin so that you can really determine what's in DD04): http://www.cpearson.com/excel/CellView.htm Second, ...

excel 97 xml import
I have Excel 97 and need to import a XML file. I don't know vba. Slinger XL97 was written way before XML therefore it will not handle it. Only XL2003 (Individual product or from Office Pro) will recognise and handle XML import/export -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS "Slinger" <Slinger@discussions.microsoft.com> wrote in message news:D1D9952E-F741-4B11-8040-B27B34F382BE@microsoft.com... >I have Excel 97 and need to import a XML file. I don't know vba. ...

Import TransferIN into TransferOUT... its possible?
Hi, I have RMS 1.3, its possible to import a transfer in of one store into transfer out on my store? Thanks in advance. Aldo, If you are running HQ, it does this for you, on the next connect to HQ. -- * Get Secure! - www.microsoft.com/security You must be using Outlook Express or some other type of newsgroup reader to see and download the file attachment. If you are not using a reader, follow the link below to setup Outlook Express. Click on "Open with newsreader" under the MS Retail Management System on the right. http://tinyurl.com/75bgz ********** "Aldo" <...

COleDateTimeSpan
I noticed problem in Visual Studio.NET 7.0.9466, don't know if something wrong with my VC source code. the bug could cause data corruption if you use serialization of COleDatTimeSpan object, the problem is in file olevar.cpp, one line of code is missing (at least on my mashine ============= CArchive& AFXAPI operator<<(CArchive& ar, COleDateTimeSpan dateSpanSrc return ar << dateSpanSrc.m_span CArchive& AFXAPI operator>>(CArchive& ar, COleDateTimeSpan& dateSpanSrc ar >> (long&)dateSpanSrc.m_status return ar >> dateSpanSrc.m_span ...

Importing JEs through the Table Import
Is there a way to import JEs throught the table import. If so, how is this accomplished? Please help! Thank you! If you have access to table import you must also own integration manager. either way, yes, you can import transactions. please give me a call at 214-373-8550 and we can walk through the process. Leslie "Christina" wrote: > Is there a way to import JEs throught the table import. If so, how is this > accomplished? Please help! Thank you! You can use Table Import but Integration Manager is much, much easier to use. If you can use Table Import, you own Inte...

How I import data without truncating zero in the beginning
I am importing data from text file to access database but it is truncating all the zeros if they come in the starting.... please help me to resolve this problem as there is a field name telephone number and I need zero in the starting to distinguish between local and international calls. Remplace them by "+" (normaly it's the same) "Mohsin Habib" <MohsinHabib@discussions.microsoft.com> a écrit dans le message de news:8B32A18C-E88B-4259-8CAE-332EB821883C@microsoft.com... >I am importing data from text file to access database but it is truncating > ...

how to add controls to a group control in mfc?
Hii .. I have a really simple question, Im trying to add some controls (e.g edit boxes and radio buttons) to a group box in MFC in visual studio 2003. What I want is that in the Dialog editor when I move the group box with my mouse, all the controls inside the group box move along with it too. Also I want to enable / disable all the controls inside the group box on the fly by just enabling/disabling the groupbox Is it possible to do that? Thanks Arfeen arfeengodil@gmail.com wrote: > Hii .. > > I have a really simple question, Im trying to add some controls (e.g > edit boxes an...

Importing Dynamic data
Hi I have some tables in various xl files, call the files a,b and c. I want to import all these into a single xl file called e. If changes are made to a,b or c I want it to automatically update e. I have used the import function in d but if I change a,b or c to see the change I have to select the data in d and press refresh. Furthermore when I refresh d i have to have files a,b and c open otherwise it says connection lossed and is unable to refresh the data. Can someone explain to me in simple terms what I have to do in order to get the data automatically updated without having to alway...

GP Report Writer Resources
Can anyone recommend any resources for getting up to speed with Report Writer and all the idiosyncrasies? The help documentation is quite vague on detail. Thanks, Colin ...

MFC controls & "????????????"
Hello I have a SDI MFC unicode application. In a messagebox ( AfxMessageBox(_T("some text")) ) "some text" can be in different languages (japanese or russian for example) and the text is displayed correctly. The text is also displayed correctly in a CListView. However in MFC controls (like CStatic or CTreeCtrl) in a CDialog derived dialogbox in the application only latin characters are displayed correctly - other languages are displayed as ??????. The dialog template has settings: STYLE DS_SHELLFONT | DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP FONT 8, "MS...

Importing a CSV file
Hi, When I try to import a CSV file into Outlook, it says I have to first install the DATA1.MSI file from my windows XP installation disk. I looked at my installation disk and here doesn't seem to be such a file. How can I import? Thanks, Randy If you have the correct installation disk, then all you need do is run the Office setup - Add/Remove options and add the Outlook import filters. Karl -- ____________________________________________________________ Karl Timmermans - The Claxton Group ContactGenie - QuickPort/DataPort/Exporter/Toolkit/Duplicate Contact M...

why are my important emails going into junk email
I posted on outlook general and didn't get a response. so I looked here and there was no clue as to what is happening. I am using outlook 2007 on the desktop. now any mail coming in from facebook is going to junk email. also my zdnet newsletter is going there also. I have added their domain to the safe list but they are still going to junk. this probably started the other day when I got outlook 2003 going on my laptop so I could see my emails when I am away from home. I did lower the category for junk mail one item but that didn't help either. don't know what...

Import DB from CRM 1.2 to 3.0
Hi to all, How can I import the DB or data from CRM 1.2 to new CRM 3.0? Now my CRM DB are on SQL2000 server. Thank and regards. Augusto You should really upgrade CRM1.2 to 3.0. The data structutres are different enough that doing a migration would be pretty painful. Any reason not to upgrade? "IGBA75" <a.crippa@ieti.biz> wrote in message news:%23c97ZdkXGHA.3660@TK2MSFTNGP04.phx.gbl... > Hi to all, > > How can I import the DB or data from CRM 1.2 to new CRM 3.0? > Now my CRM DB are on SQL2000 server. > > Thank and regards. > Augusto > ...

how can i import worksheets from multiple workbooks
Hi, I have a bunch of workbooks that all used the same template and were filled out for each week of the year. They all have a "totals" sheet the collects all the important data within. What i want to do is create a macro that imports that totals page, or a section of it from a bunch of these different workbooks, say all the ones in january or maybe the entire years worth so i can do some more analysis. my VBA skills are terrible but i am learning slowly. Any help would be appreciated. Hi David You can start here http://www.rondebruin.nl/copy3.htm -- Regards Ron de Bruin h...

importing email
Can you import an email into Outlook from Aol.com using high speed internet cable? No. AOL uses proprietary mail format and does not play nicely with others. -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Having searched the archives, Ben <mysanity@att.net> typed: | Can you import an email into Outlook from Aol.com using | high speed internet cable? ...

import pdf table
What is the best way to inmport a table in a pdf document into excel? Check out: http://www.library.mcgill.ca/edrs/services/publications/how to/PDFtoXLS/PDFtoExcel.html#basicexports HTH Jason Atlanta, GA >-----Original Message----- >What is the best way to inmport a table in a pdf document >into excel? >. > Those directions are for university students that have Adobe Acrobat installed (not just the reader). Though there is a reference immediately above that does refer to the acrobat reader Most people do not have the full Adobe Acrobat software. With just the Acrob...

Excel 2003
I have a user in a remote location which I am not at with a new Dell pc with Office 2003. He claims excel 2003 won't open his older lotus.123 files. I'm guessing he needs to rerun setup and do either a complete install or install the lotus converters. Can anyone confirm that Excel 2003 can still read lotus 123 files? You may know the last 1-2-3 user alive <g> On Tue, 9 Dec 2003 06:50:20 -0800, "TJD" <anonymous@discussions.microsoft.com> wrote: >I have a user in a remote location which I am not at with >a new Dell pc with Office 2003. He claims ...

Field missing upon XML import
I'm attempting to import an XML file into an Access table. However, if a field name doesn't appear in the first handful of records (not sure of the breaking point), any subsequent instances of the field that may appear later in the file is not imported. For example, let's say there's a field called 'FieldX', but there's no FieldX value (nor tags) for the first 100 rows, but there is in row #101. The result is FieldX is NOT imported. Is this a known issue? Is there a workaround? Phil How are you setting up the import initially. Unless Access has a schema...

Import / date questions
Hi I have imported a lot of email (15,000) from Thunderbird > converted from mbox > .eml - dragged the email into Outlook express and then imported into Outlook2003. All has worked fine ish- but a lot of messages have the "received" field set as todays date / time. If I select the "sent" field that is correct. Is there anyway to reset the date on an email message in outlook (ideally on mass) - what is the difference between the Sent field and the received field ? Thanks Hi Just did a check, and the data in outlook express is correct. Its when I did the impor...

importing a cell value
I need to import a cell values from an un-opened .xls using a variable address ie cell A34 = the location of the .xls on our server (j:\121213\Drafting\Quants\) "105 White Ant" = the name of the .xls B3 = the cell I need to import C6 = value(A34+"105 White Ant"+B3) Any help or advice would be hugely appriciated Sorry I should also have specified that I want to avoid the use of macros. "Kristian G" wrote: > I need to import a cell values from an un-opened .xls using a variable address > ie > cell A34 = the location of the .xls on our ...

Need a utility to import mail to Outlook via print dialog... or some other way to import proprietary messages into Outlook.
Hello, We need to migrate 100s of proprietary PSTs from a little-known mail system to Outlook/Exchange but the file format of the PSTs is binary, proprietary and undocumented. One option is to leave the PSTs and let the users consult them in offline mode forever. The problem there is that they wouldn't be able to reply to or forward the messages, only read or print them. Not very user-friendly, they have GBs of mail in them. Has anyone seen an application which lets you print a message into an Outlook mail message, much like you print to a PDF file? Any other suggestions for workarounds...

Incorrect import of decimal point placement.
I'm using Money 2004 Deluxe. This past week when I imported a QIF file into Money from my financial institution and the decimal point shifted 2 spaces to left in all but 2 entries. Instead of 400.00, the result was 4.00. Has this occurred to anyone? Iv'e been using the software for the past 3 months and this is the first time it had occured. Money or Financial institution problem?? In microsoft.public.money, Martin wrote: >I'm using Money 2004 Deluxe. >This past week when I imported a QIF file into Money from my financial >institution and the decimal point shifted 2 ...

Excel-Based Budgeting-print an exception report after the import
When importing a budget into GP from Excel (using Excel-Based Budgeting), if any account numbers are entered in Excel that are not in GP, the import drops them without any warning or notification. In our case, we have 5500 lines of information to manually review to find the problem. A solution is to have an exception report print after the import to list any accounts in Excel that were not imported into GP. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree"...