-
December 16th, 2005, 06:24 AM
#1
Access Dialog from both VC++ Project and C# Project
Hi,
We have a requirement that requires to have some common dialogs which should be accessible from both VC++ Project and C# Project.
We tried to implement the common dialogs in MFC dll and export functions to call from client applications. So that exported function will be called from the client application (VC++ or C#) and dialog will be shown from the called function.
But text on the controls is disappearing when the function is called from C# Project.
It is appreciated if any body knows better idea or solution for the above problem.
Thanks,
HKM
-
December 16th, 2005, 01:02 PM
#2
Re: Access Dialog from both VC++ Project and C# Project
I am sure that there are many possibilities but here are a couple.
Scenario 1:
You can do it the way you are doing now, just make sure you call
AFX_MANAGE_STATE(AfxGetStaticModuleState());
before you display any dialogs.
Scenario 2:
You can create all the Dialogs in a C# Class Library and Register it for COM Interop. Then, in the C++ Application use a #import on the .tlb file and go. For a C# Applicaiton, simply add a reference to the Class Library. I would recommend this approach because you are writing managed code.
Just a couple of suggestions.
-
December 16th, 2005, 08:59 PM
#3
Re: Access Dialog from both VC++ Project and C# Project
I agree with Hoagers. However he neglected to say that you should use RegAsm.exe to register the .NET assemblies as COM objects.
Also if you were to go down this route I'd recommend using a GuidAttribute as well as ComVisible attribute attached to each class in the assembly e.g.
Code:
[ComVisible(true)]
[Guid(" - whatever - ")]
public class DialogWrapper
{
MyDialog _myDialog;
public void Show()
{
// whatever, this is just an example
}
}
[ComVisible(false)]
public class MyDialog : Form
{
// again - whatever
}
You should have a specific assembly which contains the dialogs which are designed to be used from VC++.
Bear in mind that the COM interface is based on the VB6 model : i.e. it uses IDispatch. VC++ will import these and create interface classes for you if you go to the menu item Project/Add class - select the "MFC class from TypeLib" or "MFC class from ActiveX control" items.
This of course is DevStudio 2002 or later. For VC++ 6 there's something similar but I can't remember at the moment.
Hope this helps,
Darwen.
Last edited by darwen; December 16th, 2005 at 09:01 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|