J
Jason Lopez via .NET 247
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 whateverinformation 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(unsigned short pid,int channel) = 0;
virtual void AssignAudio(unsigned short pid,int channel) = 0;
virtual void UnassignVideo(int channel = VV_ALL) = 0;
virtual void UnassignAudio(int channel = VV_ALL) = 0;
};
DLL_ENTRY IVidView* CreateVidView(HWND hWndParent,RECT*pRect); // Call delete after finished with pointer returned bythis call.
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 whateverinformation 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(unsigned short pid,int channel) = 0;
virtual void AssignAudio(unsigned short pid,int channel) = 0;
virtual void UnassignVideo(int channel = VV_ALL) = 0;
virtual void UnassignAudio(int channel = VV_ALL) = 0;
};
DLL_ENTRY IVidView* CreateVidView(HWND hWndParent,RECT*pRect); // Call delete after finished with pointer returned bythis call.