473,549 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inheriting the VC++ template classes into C#.net

Amu
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .

Jan 16 '07 #1
7 2491
Amu a écrit :
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .
I may be wrong, but I really believe that composition
(http://en.wikipedia.org/wiki/Object_composition) is the only way to
achieve what you are trying to.

Mathieu
Jan 16 '07 #2
Amu

Mathieu Cartoixa wrote:
Amu a écrit :
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .
I may be wrong, but I really believe that composition
(http://en.wikipedia.org/wiki/Object_composition) is the only way to
achieve what you are trying to.

Mathieu
i read the solution but can u give me some clear idea regarding
it.actually 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.
:Amu

Jan 16 '07 #3
Amu wrote:
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .
Hi,

best solution IMHO would be to use VC++ 2005 and write some wrapper
classes in C++/CLI. Which then can be directly used from C#.
You can use generics and map them to the associated template class.
Though generics are more restricted than templates, so you possibly
can't directly wrap the template classes by using generics.

Another solution would be wrapping the template classes in COM
interfaces or by using flat functions. Surely with this method you can't
use template / generic parameters.

VC++ 2005 Express Edition, can be downloaded from Microsoft.

Hope that helps,
Andre
Jan 16 '07 #4
Amu

Andre Kaufmann wrote:
Amu wrote:
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .

Hi,

best solution IMHO would be to use VC++ 2005 and write some wrapper
classes in C++/CLI. Which then can be directly used from C#.
You can use generics and map them to the associated template class.
Though generics are more restricted than templates, so you possibly
can't directly wrap the template classes by using generics.

Another solution would be wrapping the template classes in COM
interfaces or by using flat functions. Surely with this method you can't
use template / generic parameters.

VC++ 2005 Express Edition, can be downloaded from Microsoft.

Hope that helps,
Andre


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, DTMPOPropertyPa ge in C#.

How can I achieve this?

class AFX_EXT_CLASS DTMPOPropertyPa ge : public CPropertyPage

{

// Construction

public:

//DECLARE_DYNAMIC (DTMPOPropertyP age)

DTMPOPropertyPa ge(FDTXmtrDoc *doc, UINT nIDTemplate = 0,
UINT nCaption = 0);

~DTMPOPropertyP age();

//{{AFX_DATA(CXmt rPropertyPage)

// 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 InCancelProcess ing ();

// Overrides

// ClassWizard generate virtual function overrides

//{{AFX_VIRTUAL(C XmtrPropertyPag e)

// 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(FALS E); 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(CXmtr PropertyPage)

// NOTE: the ClassWizard will add member
functions here

//}}AFX_MSG

//afx_msg LRESULT OnCommandHelp(W PARAM, LPARAM lParam);

//afx_msg LRESULT OnShiftF1Help(W PARAM, LPARAM lParam);

//afx_msg void OnHelp( );

afx_msg BOOL OnHelpInfo( HELPINFO* lpHelpInfo );

//_DLLPROC DECLARE_MESSAGE _MAP()

DTMPOPropertySh eet *GetSheet();

// pointer to document

FDTXmtrDoc *mDoc;

private:

void SetSheet( DTMPOPropertySh eet *ps );

friend class DTMPOPropertySh eet;

mDTMPOPropertyP age *m;

};

Jan 17 '07 #5
Amu

Andre Kaufmann wrote:
Amu wrote:
Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .

Hi,

best solution IMHO would be to use VC++ 2005 and write some wrapper
classes in C++/CLI. Which then can be directly used from C#.
You can use generics and map them to the associated template class.
Though generics are more restricted than templates, so you possibly
can't directly wrap the template classes by using generics.

Another solution would be wrapping the template classes in COM
interfaces or by using flat functions. Surely with this method you can't
use template / generic parameters.

VC++ 2005 Express Edition, can be downloaded from Microsoft.

Hope that helps,
Andre
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, DTMPOPropertyPa ge in C#.

How can I achieve this?

class AFX_EXT_CLASS DTMPOPropertyPa ge : public CPropertyPage

{

// Construction

public:

//DECLARE_DYNAMIC (DTMPOPropertyP age)

DTMPOPropertyPa ge(FDTXmtrDoc *doc, UINT nIDTemplate = 0,
UINT nCaption = 0);

~DTMPOPropertyP age();

//{{AFX_DATA(CXmt rPropertyPage)

// 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 InCancelProcess ing ();

// Overrides

// ClassWizard generate virtual function overrides

//{{AFX_VIRTUAL(C XmtrPropertyPag e)

// 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(FALS E); 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(CXmtr PropertyPage)

// NOTE: the ClassWizard will add member
functions here

//}}AFX_MSG

//afx_msg LRESULT OnCommandHelp(W PARAM, LPARAM lParam);

//afx_msg LRESULT OnShiftF1Help(W PARAM, LPARAM lParam);

//afx_msg void OnHelp( );

afx_msg BOOL OnHelpInfo( HELPINFO* lpHelpInfo );

//_DLLPROC DECLARE_MESSAGE _MAP()

DTMPOPropertySh eet *GetSheet();

// pointer to document

FDTXmtrDoc *mDoc;

private:

void SetSheet( DTMPOPropertySh eet *ps );

friend class DTMPOPropertySh eet;

mDTMPOPropertyP age *m;

};

Jan 17 '07 #6
Amu a écrit :
Andre Kaufmann wrote:
>Amu wrote:
>>Hi i am stuck up in a part of project where i have to inherit the VC++
template classes into C#.net. Please provide me the solution for this .

best solution IMHO would be to use VC++ 2005 and write some wrapper
classes in C++/CLI. Which then can be directly used from C#.

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, DTMPOPropertyPa ge in C#.

How can I achieve this?

class AFX_EXT_CLASS DTMPOPropertyPa ge : public CPropertyPage

{
// Construction
public:
//DECLARE_DYNAMIC (DTMPOPropertyP age)
DTMPOPropertyPa ge(FDTXmtrDoc *doc, UINT nIDTemplate = 0,
UINT nCaption = 0);
~DTMPOPropertyP age();
//{{AFX_DATA(CXmt rPropertyPage)
// 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 InCancelProcess ing ();
// Overrides
// ClassWizard generate virtual function overrides
//{{AFX_VIRTUAL(C XmtrPropertyPag e)
// 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(FALS E); 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(CXmtr PropertyPage)
// NOTE: the ClassWizard will add member
functions here
//}}AFX_MSG
//afx_msg LRESULT OnCommandHelp(W PARAM, LPARAM lParam);
//afx_msg LRESULT OnShiftF1Help(W PARAM, LPARAM lParam);
//afx_msg void OnHelp( );
afx_msg BOOL OnHelpInfo( HELPINFO* lpHelpInfo );
//_DLLPROC DECLARE_MESSAGE _MAP()
DTMPOPropertySh eet *GetSheet();
// pointer to document
FDTXmtrDoc *mDoc;
private:
void SetSheet( DTMPOPropertySh eet *ps );
friend class DTMPOPropertySh eet;
mDTMPOPropertyP age *m;
};
I am sorry to write that you will have to forget about inheriting from
this class.
I'm far from being fluent in Managed C++, so I redirect you to these
resources about implementing a wrapper (i.e. a class that uses
composition) :
http://www.ondotnet.com/pub/a/dotnet...cpp_part3.html
http://www.codeguru.com/Cpp/Cpp/cpp_...cle.php/c6867/

Mathieu
Jan 17 '07 #7
Amu wrote:
Andre Kaufmann wrote:
>Amu wrote:
[...]
I have attached the the class template code snippet for your reference.
I need to inherit from this class, DTMPOPropertyPa ge in C#.

How can I achieve this?
As some posters already have mentioned, you can't derive directly from a
native C++ class in C#. You can wrap the class in a managed one and
embed the native class in the managed as a pointer. Directly embedding,
meaning mixing managed and native classes is not (yet) possible.

A short example gives you the idea:

(Create for example a class library in VC++ 2005,
or a CLR console application for testing):
using namespace System;

// Native C++ class - that's for example your DTMPOPropertyPa ge class
class Native
{
public: void Method() {}
};

// You can create and inherit from this class in C#
// It's a managed class and should be visible in a C#
// project if you add a reference to the DLL.
public ref class Managed
{
public:

Managed() { native = new Native(); }
~Managed() { delete native; }

// Function callable from C#
void External() { native->Method(); }

private:
Native* native;
};
[...]
Anyways mixing MFC code and C++/CLI (managed) code is not that simple,
especially if GUI components / classes are involved. There are some
examples for this type of application in the MSDN library.

You have no chance to do the above in VC6. If you must use VC6 your only
chance (IMHO) is to wrap your classes by using handles and flat
functions (just the way Win32 is doing it) and use DLLImport to call the
functions - though IMHO to much work. Or wrap your native classes in COM
objects - but IMHO quite too much work.

So you should give VC++ 2005 a try.

Andre
Jan 17 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1685
by: Drew McCormack | last post by:
Does operator() get inherited? I would have thought so, but I can't get the following to work: I have a base class that takes its derived class as a template template parameter (the Barton-Nackmann trick). It has a operator() defined. template <typename NumType, template <typename T> class DerivedType> class Matrix { public:
3
1410
by: N4M | last post by:
Dear, I have codes as follows: template<class T> class A { public: // embedded class class E; public: // types typedef E TE; public:// member functions TE somefunc();
4
2949
by: Anthony Gallagher | last post by:
I have a bunch of libraries compiled using VC++ 6.0, and I am trying to recompile one of our projects using VC++ .NET. I get all kind of linker errors (specially in STL calls). How do I get rid of these errors?? Anthony
5
2327
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and run this works fine. but if build in unicode release or release this does't work. IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
12
6477
by: jarradw | last post by:
I am trying to figure out if this will work. I have a template base class that I want to be able to inherit from, the classes that will need to inherit from this also need to be tamplates. Is this possible or do i need to think of another way to do it?
1
2265
by: siva.isukapalli | last post by:
Hi, We are involved in a porting project (from VC++ 6.0 to .Net VC++ 7.1). ** NOT C# or VB..NET. We have a custom app wizard written in 6.0. This basically creates a project with a set of template based classes. We have to port it. But there is a significant change in the way custom app wizards are created in both the versions of vc++.
24
2920
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public vector<Corres>{ public: void addCorres(Corres& c); //it do little more than push_back function. }
2
1908
by: Amu | last post by:
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.
4
1685
by: AalaarDB | last post by:
struct base { int x, y, z; base() {x = 0; y = 0; z = 0;}; base(int x1, int y1, int z1) {x = x1; y = y1; z = z1;}; }; struct intermediate1 : public virtual base {}; struct intermediate2 : public virtual base
0
7459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7967
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7819
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.