Carl Daniel [VC++ MVP] wrote:
Amu wrote:
i have a dll ( template class) ready which is written in
VC++6. But presently i need to inherit its classes into my new C#.net
project.so if there is some better solution with u then please give me
the solution.
Strictly speaking, there's no way to "inherit C++ classes into C#" (whatever
that means). There are, however, several possible ways to make use of your
C++ classes in a C# program.
First, if the C++ classes are really COM objects, you can use tlbimp.exe
(.NET framekwork SDK) to generate a .NET wrapper assembly and then use the
classes from that wrapper assembly from your C# project to access your c++
classes.
Second, if the C++ classes are really just C code that exposes a C-friendly
API, you can use PInvoke to call functions in your DLL from C#.
Finally, for most other cases, you'll have to port your VC6 code to VC8,
then use C++/CLI to hard-craft a .NET interface for your C++ classes.
If you can give more details about exactly what the classes are and how you
intend to use them, I or someone else can help you find the right path for
your particular case.
-cd
The C++ classes which I mentioned are classes which are derived from
MFC standard classes like CPropertyPage and CPropertySheet.
These template classes are simple MFC classes which are packaged as a
DLL. Since the Implementation part of this DLL is huge, I can't think
of rewriting the whole code in C#.
I have attached the the class template code snippet for your reference.
I need to inherit from this class, DTMPOPropertyPage in C#.
How can I achieve this?
class AFX_EXT_CLASS DTMPOPropertyPage : public CPropertyPage
{
// Construction
public:
//DECLARE_DYNAMIC(DTMPOPropertyPage)
DTMPOPropertyPage(FDTXmtrDoc *doc, UINT nIDTemplate = 0,
UINT nCaption = 0);
~DTMPOPropertyPage();
//{{AFX_DATA(CXmtrPropertyPage)
// NOTE - ClassWizard will add data members
here.
// DO NOT EDIT what you see in these blocks
of generated code !
//}}AFX_DATA
// Attributes
public:
// Access to determine if performing CANCEL processing.
// Pages use this to avoid validation
//BOOL InCancelProcessing ();
// Overrides
// ClassWizard generate virtual function overrides
//{{AFX_VIRTUAL(CXmtrPropertyPage)
// Define a generic OnKillFocus handler for use by all
pages
//afx_msg void OnKillFocus();
virtual void DoDataExchange(CDataExchange* pDX); //
DDX/DDV support
//}}AFX_VIRTUAL
virtual BOOL OnInitDialog() { return
CPropertyPage::OnInitDialog(); }
virtual BOOL OnSetActive() { UpdateData(FALSE); return
CPropertyPage::OnSetActive(); }
//virtual BOOL OnKillActive();
// access to BO parameters
virtual void SetValues() = 0;
virtual void UpdateDocument() = 0;
// access to AppInfo
FDTAppInfo *GetAppInfo();
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CXmtrPropertyPage)
// NOTE: the ClassWizard will add member
functions here
//}}AFX_MSG
//afx_msg LRESULT OnCommandHelp(WPARAM, LPARAM lParam);
//afx_msg LRESULT OnShiftF1Help(WPARAM, LPARAM lParam);
//afx_msg void OnHelp( );
afx_msg BOOL OnHelpInfo( HELPINFO* lpHelpInfo );
//_DLLPROC DECLARE_MESSAGE_MAP()
DTMPOPropertySheet *GetSheet();
// pointer to document
FDTXmtrDoc *mDoc;
private:
void SetSheet( DTMPOPropertySheet *ps );
friend class DTMPOPropertySheet;
mDTMPOPropertyPage *m;
};