Home » Category » Microsoft Visual C & C++

Microsoft Visual C & C++: Why is my DLL not able to contain any resource (dialog resource)

200| Wed, 07 May 2008 14:56:00 GMT| jigar_mehta| Comments (6)
Hi,

Let me explain my project. I had one project which had client GUI and
CORE and some my GUI (like about screen) part. Now, I wanted to
separate the client GUI from my coding so that I can deliver client a
compiling application.

Now, I created MFC Extended DLL. Which had only VERSION in resource
tab. I have some dialog which I need to put in DLL. I have moved all
the classes from my previous workspace to DLL (code is moved to DLL).
But If I move dialog template to DLL, it is not workign properly. It
does not show any dialog. even I moved IDD_MYDIALOG define from exe's
resource.h to DLL's resource.h file. I debugged the code. It creates
dialog class's object but dont go into OnInitDialog function. So,
currently my dialog template is there in my application project. Class
for that dialog is there in my DLL project and it is working properly.
But I want to move dialog template too in my DLL project.

So, is it so that I need to have some special settings for DLL having
resources ? Why would my resources not getting embedded in my DLL ?

Keywords & Tags: dll, able, contain, resource, dialog, microsoft, visual c++, vc

URL: http://www.7prog.com/visual-c-c++/326389/
 
«« Prev - Next »» 6 helpful answers below.
Its not clear how your dialog resource is split up. Try a simply test by
creating a resource DLL, add it to resource chain (Use CDynLinkLibrary) and
then create the dialog. The dialog resource should be found by Exe (where
you create it) and dialog should be created as expected. I suspect whats
happening to you is that the resoruce is not found when you try to create
the dialog. Step in the code where you create the dialog and see where the
problem is. IDD_MYDIALOG should be in DLL as you have designed it and not in
any other module.
Ajay Kalra [MVP - VC++]
ajaykalra...yahoo.com

"Jigar Mehta" <jigar.programmer...gmail.com> wrote in message
news:1146922938.371861.44930...i39g2000cwa.googlegroups.com...
> Hi,
> Let me explain my project. I had one project which had client GUI and
> CORE and some my GUI (like about screen) part. Now, I wanted to
> separate the client GUI from my coding so that I can deliver client a
> compiling application.
> Now, I created MFC Extended DLL. Which had only VERSION in resource
> tab. I have some dialog which I need to put in DLL. I have moved all
> the classes from my previous workspace to DLL (code is moved to DLL).
> But If I move dialog template to DLL, it is not workign properly. It
> does not show any dialog. even I moved IDD_MYDIALOG define from exe's
> resource.h to DLL's resource.h file. I debugged the code. It creates
> dialog class's object but dont go into OnInitDialog function. So,
> currently my dialog template is there in my application project. Class
> for that dialog is there in my DLL project and it is working properly.
> But I want to move dialog template too in my DLL project.
> So, is it so that I need to have some special settings for DLL having
> resources ? Why would my resources not getting embedded in my DLL ?
>

ajaykalra | Wed, 07 May 2008 14:57:00 GMT |

Hi Ajay,

Exactly.. This is what I am thinking. As per you, DIALOG resource must
be there in the DLL (where I am creating the dialog, that is, I have
class for dialog in DLL). But whats happening is exactly reverse. If I
put dialog resource in Application module and class for that in DLL
module, it runs perfectly. Just for your information, I am programming
with WinCE 4.2 and using eVC++ 4.0. But I dont think that matters.

And about CDynLinkLibrary I dont know much. How to use that ? Any
sample for that in MSDN ?

Regards,
Jigar Mehta

jigarmehta | Wed, 07 May 2008 14:58:00 GMT |

> Try a simply test by
> creating a resource DLL, add it to resource chain (Use CDynLinkLibrary) an
d
> then create the dialog.

The "standard" way of handling this is a resource only DLL (no code),
loaded, then call AfxSetResourceHandle.
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
---
Replace _year_ with _ to get the real email

mihain_ | Wed, 07 May 2008 14:59:00 GMT |

I have never used AfxSetResourceHandle. We had multiple Resource DLLs
in a large MFC project. Each of these DLLs were in resource chain using
CDynLinkLibray. A client of these resources did not need to know where
the resource is coming from. I am not sure if AfxSetResourceHandle
would give this flexibility. Its sounds more like its useful if you
have one resource DLL or if you know which DLL has a specific resource
in a multiple Resource DLL project.
Ajay

ajaykalra | Wed, 07 May 2008 15:00:00 GMT |

"Ajay Kalra" <ajaykalra...yahoo.com> wrote in
news:1147093658.891009.30340...g10g2000cwb.googlegroups.com:

> I have never used AfxSetResourceHandle. We had multiple Resource DLLs
> in a large MFC project. Each of these DLLs were in resource chain using
> CDynLinkLibray. A client of these resources did not need to know where
> the resource is coming from. I am not sure if AfxSetResourceHandle
> would give this flexibility. Its sounds more like its useful if you
> have one resource DLL or if you know which DLL has a specific resource
> in a multiple Resource DLL project.

If you manualy play with CDynLinkLibray, then you have to pass a HMODULE,
same as AfxSetResourceHandle.
If you let the MFC magic, then you have no control.
The idea with resource only DLLs is that I can change the language of the UI
.
This means that depending on the language I have to manually load the proper
DLLs anyway.

See some other drawbacks with CDynLinkLibray:
http://www.codeproject.com/dll/dlli...mihai-nita.net
---
Replace _year_ with _ to get the real email

mihain_ | Wed, 07 May 2008 15:01:00 GMT |

> The idea with resource only DLLs is that I can change the language of the UI.
> This means that depending on the language I have to manually load the prop
er
> DLLs anyway.


We didnt do it this way. We had multiple resource DLLs and there was a
version of each of these in other languages, such as Chinese, German
etc. Code was never aware of what language is being used. We simply
shipped the appropriate resource DLLs. As mentioned we used
CDynLinkLibrary and put all resoruces in resource chain and never had
to know which DLL to look for to get any resource.

The only thing which was kind of pain initially about this design was
that each resource DLL had to have distinct resource IDs. I had to edit
the resource.h files and change these numbers when the project was
initially created.

I saw the link that you provided. That is a good trick. That will work
as long as projects dont go across modules (generally a safe
assumption) for resources.
Ajay

ajaykalra | Wed, 07 May 2008 15:02:00 GMT |

Microsoft Visual C & C++ Hot Answers

Microsoft Visual C & C++ New questions

Microsoft Visual C & C++ Related Categories