473,799 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to instantiate a class for a C++ DLL in C#

I'm having a lot of trouble trying to instantiate a C++ classfrom a DLL in a C# application. The DLL was written in C++(Visual Studio 6.0).

I have the full source code, as well as the compiled DLL. I washoping I'd be able to use it using the DllImport attribute, andcreating empty function declarations. I've done that before andit works well. The problem is that DllImport requires that allfunctions be static. This particular DLL requires that youcreate an instance of this object, then call methods on thatinstance. I haven't been able to figure out how you instantiatea class that is defined in a .DLL.

I suspect that it's possible to recompile the DLL in Managed C++,and then Visual Studio will be able to gather whateverinforma tion it needs for me to instantiate it like a normalclass - however, there's a bit of a learning curve to usingManaged C++ and I haven't been able to figure out how to makethat work yet.

Thanks!
Jason Lopez
Here is the header file for the DLL I'm trying to instantiate inC#:

#ifdef VIDVIEW_EXPORTS
#define DLL_ENTRY __declspec( dllexport )
#else
#define DLL_ENTRY __declspec( dllimport )
#endif

class DLL_ENTRY IVidView
{
public:
virtual ~IVidView() {};
virtual BOOL Retune() = 0;
virtual BOOL SetAddress(char * src_ip,unsigned short port, char*interface_ ip) = 0;
virtual void Play() = 0;
virtual void Stop() = 0;
virtual void AssignVideo(uns igned short pid,int channel) = 0;
virtual void AssignAudio(uns igned short pid,int channel) = 0;
virtual void UnassignVideo(i nt channel = VV_ALL) = 0;
virtual void UnassignAudio(i nt channel = VV_ALL) = 0;
};

DLL_ENTRY IVidView* CreateVidView(H WND hWndParent,RECT *pRect); // Call delete after finished with pointer returned bythis call.

--------------------------------
From: Jason Lopez

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>sx+IvDMk6U6 g1RmJpF+GpA==</Id>
Nov 17 '05 #1
1 2983
>I'm having a lot of trouble trying to instantiate a C++ class from a DLL in
a C# application. The DLL was written in C++ (Visual Studio 6.0).

If I understand correctly, you try to load a VC++ 6.0 dll into a C#
application?
If this is the case then I doubt it will work since VC++ 6.0 has no clue
about .NET (managed code).

Recompiling this VC++ 6.0 dll as a VC++ 2003 mixed mode managed/unmaned
dll and then adding a managed to unmanaged class wrapper should make it
possible to let a c# program access the unmanaged funtionality.

A little information about "managed" and "unmanaged" words:

"Unmanaged code" means that the binary execution code is pure old style code
that is fully understood by your main processor (Pentium, 80486,...).
"Managed code" means that the binary execution code is a virtual processor
code, that must be translated by the CLR into unmanaged code during the load
process of the .NET class.

In C# you have no chouce between unmanaged or managed code, everything is
managed code.
In the case of C++ you have a choice or even mix them.

I hope this helps?
Nov 17 '05 #2

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

Similar topics

2
2482
by: jerrygarciuh | last post by:
Hello, Is it possible to instantiate a child class within the constructor of its parent? eg Class DBI extends DB { function DBI() { // explicit parent constructor call
2
4718
by: Colin Mc Mahon | last post by:
Hi all, I currently use a class to interface with my databases, allowing me to insert, update, delete and retrieve records from the database as methods of the class. I have now created a recordset class and want to in some way instantiate this class via the database class i.e. Set objDbase = New cDatabase
5
2377
by: Glenn Serpas | last post by:
I have Class A and Class B .. Class B has a private member that is a pointer to a Class A object. private: B *mypointer ; I instantiate the A object A* myobject new = A();
4
5059
by: A. Gonzalez | last post by:
Hi everyone, Does anyone know how to instantiate, or create an XML document file (either using DOM or Readers) from an XML schema (xsd) file? I'm trying to develop an application that can handle different xml doc structures, but at the same time I need to create these documents, even if there's no content. So I was planning to drive it with schema files (xsd), but I haven't figured out from looking at the .net SOM how to create the...
2
1343
by: Pyenos | last post by:
class model:pass class view: model() class controller: model() I can instantiate clsss model from inside class view but I can't instantiate class model from inside controller, due to the nature of python interpreter.
5
4539
by: Pyenos | last post by:
class One: Two() #can't instantiate class Two: Three() #can't instantiate class Three:pass
4
3666
by: Tomas | last post by:
A newbie question: How can I instantiate objects dynamically in VB.NET. E.g. I have the object 'Player' and I would like to instantiate it with the several instances (James, Gunner, etc.), without in advance knowing how many objects (employee1, employee2, etc) Dim player1 As New Persons.Players Dim player2 As New Persons.Players Dim player3 As New Persons.Players ....
3
3584
by: Fei Liu | last post by:
Hello, We all know that a template function can automatically deduce its parameter type and instantiate, e.g. template <tpyename T> void func(T a); func(0.f); This will cause func<floatto be instantiated. The user does not have
7
3243
by: Joe Strout | last post by:
I have a function that takes a reference to a class, and then instantiates that class (and then does several other things with the new instance). This is easy enough: item = cls(self, **itemArgs) where "cls" is the class reference, and itemArgs is obviously a set of keyword arguments for its __init__ method. But now I want to generalize this to handle a set of mix-in classes.
0
9538
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10249
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10025
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6804
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.