From: davejohansen@gmail.com on
I am creating a CDialog in a DLL using a Dialog template resource in
the DLL. It seems to be working just fine but I was wondering if there
was something wrong with the method I was using or if there was a
better way to do what I was doing. Here's my function that creates the
dialog:

CDialog *NewDialog(CWnd *parent)
{
ASSERT(parent != NULL);

//Store the current resource handle
HINSTANCE hClientResources = AfxGetResourceHandle();

//Tell the client to use the .DLL's resources
AfxSetResourceHandle(g_dllHandle);

HSVDialog *dialog = new HSVDialog();
VERIFY(dialog->Create(IDD_HSV_DIALOG, parent));

//Restore the client application resource handle
AfxSetResourceHandle(hClientResources);

return dialog;
}

g_dllHandle is a global HINSTANCE that is assigned to the HINSTANCE
passed in to DLLMain(). Is there anything wrong with this or is there a
better way to do this?

Thanks,
Dave Johansen

From: Ajay Kalra on
What sort of DLL is it(Extension or Regular)? If you use MFC extension DLL,
you dont need to worry about resource handle stuff. The code to create a
Dialog in a DLL is identical to what it would be in a EXE if you use
extension DLL. You will just need to export the class.

--
Ajay Kalra [MVP - VC++]
ajaykalra(a)yahoo.com


<davejohansen(a)gmail.com> wrote in message
news:1138849573.819271.7410(a)g43g2000cwa.googlegroups.com...
> I am creating a CDialog in a DLL using a Dialog template resource in
> the DLL. It seems to be working just fine but I was wondering if there
> was something wrong with the method I was using or if there was a
> better way to do what I was doing. Here's my function that creates the
> dialog:
>
> CDialog *NewDialog(CWnd *parent)
> {
> ASSERT(parent != NULL);
>
> //Store the current resource handle
> HINSTANCE hClientResources = AfxGetResourceHandle();
>
> //Tell the client to use the .DLL's resources
> AfxSetResourceHandle(g_dllHandle);
>
> HSVDialog *dialog = new HSVDialog();
> VERIFY(dialog->Create(IDD_HSV_DIALOG, parent));
>
> //Restore the client application resource handle
> AfxSetResourceHandle(hClientResources);
>
> return dialog;
> }
>
> g_dllHandle is a global HINSTANCE that is assigned to the HINSTANCE
> passed in to DLLMain(). Is there anything wrong with this or is there a
> better way to do this?
>
> Thanks,
> Dave Johansen
>


From: Joseph M. Newcomer on
Looks pretty good to me. However, the exportation of a pure CDialog * pointer has
implications, such as not knowing what to cast it to. Usually I use an MFC Extension DLL
for this purpose, which exports the CDialog class and therefore returns a specific class
pointer.
joe

On 1 Feb 2006 19:06:13 -0800, "davejohansen(a)gmail.com" <davejohansen(a)gmail.com> wrote:

>I am creating a CDialog in a DLL using a Dialog template resource in
>the DLL. It seems to be working just fine but I was wondering if there
>was something wrong with the method I was using or if there was a
>better way to do what I was doing. Here's my function that creates the
>dialog:
>
>CDialog *NewDialog(CWnd *parent)
>{
> ASSERT(parent != NULL);
>
> //Store the current resource handle
> HINSTANCE hClientResources = AfxGetResourceHandle();
>
> //Tell the client to use the .DLL's resources
> AfxSetResourceHandle(g_dllHandle);
>
> HSVDialog *dialog = new HSVDialog();
> VERIFY(dialog->Create(IDD_HSV_DIALOG, parent));
>
> //Restore the client application resource handle
> AfxSetResourceHandle(hClientResources);
>
> return dialog;
>}
>
>g_dllHandle is a global HINSTANCE that is assigned to the HINSTANCE
>passed in to DLLMain(). Is there anything wrong with this or is there a
>better way to do this?
>
>Thanks,
>Dave Johansen
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: davejohansen@gmail.com on
Thanks for the advice. I am making this as sort of a plug-in system and
so there will be different types of Dialogs that the original
application will know nothing about before hand. If that's the case,
can I still use an MFC Extension DLL and export the CDialog class for
use in my main application? Because that definitely sounds like the
better method.
Also, is there an example or tutorial that you could point me to? I
found this article:
http://www.codeguru.com/Cpp/Cpp/cpp_mfc/tutorials/article.php/c4023
but it's pretty sparse on the details and there's no real example to
show how it really works.
Thanks a ton,
Dave Johansen

From: Ajay Kalra on
(My earlier post did not show up).

If you are using it as a plug in in another MFC module, you should
*not* make it a MFC Extension DLL. This is because of possible
conflicts of resource IDs with other modules. Other alternative is to
make it a MFC Regular DLL. Here you get your own set of IDs without any
possibility of conflict. YOu will need to use AFX_MANAGE_STATE to
switch state as needed(eg using AfxGetMainWnd will not work unless you
change to proper state).

--------
Ajay Kalra
ajaykalra(a)yahoo.com