We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to use C++ class with C#

Thread ID:

Created:

Updated:

Platform:

Replies:

294 May 27,2002 04:15 PM May 16,2003 08:10 PM Windows Forms 3
loading
Tags: FAQ
Mukesh Motwani
Asked On May 27, 2002 04:15 PM

I have a class library written in C++ which I intend to use in a program whose interface is designed in C#. I understand that I need to create an unmanaged DLL and use the DLL in the program. Are there any resources which show how to create a unmanaged C++ DLL in .NET environment without using MFC and how I could use the DLL with C#? MSDN site suggests wrapping the unmanaged DLL function in a managed class but doesnt give any much useful information. Thanks Mukesh

Clay Burch [Syncfusion]
Replied On May 28, 2002 02:17 AM

Here is a Microsoft link explaining how to use P/Invoke with DLLImport to access functions in unmanaged DLLs. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconconsumingunmanageddllfunctions.asp If you have a active X library (an OCX or ATL DLL)you are trying to use, then you can create the .NET wrapper class using the tool aximp.exe.

Mukesh Motwani
Replied On June 4, 2002 02:36 AM

I created an unmanaged DLL which has a C++ class. PInvoke is able to access global exported DLL functions but it CANNOT import class methods from an unmanged DLL. Thus, I get an error "Object reference not set to an instance of an object" because I am not able to create an object of my class. In VC++ 6 I could use the header file and create an instance. But C# doesnt allow that. In fact, [DllImport("mywin32.dll")] public static extern Cwin32class(); is not compiled because the compiler thinks that method has no return type! But constructors are not supposed to have return types. Thus I cant find any way of using my unmanaged object oriented classes with the C# UI. Can anyone help me please? Thanks Mukesh

Michael
Replied On May 16, 2003 08:10 PM

Mukesh, I have the same problem when I try to use a C++ DLL. Have you found out what the problem could be and how to instantiate the wrapper class or the object? Regards. Michael. > I created an unmanaged DLL which has a C++ class. > PInvoke is able to access global exported DLL functions but it CANNOT import class methods from an unmanged DLL. Thus, I get an error "Object reference not set to an instance of an object" because I am not able to create an object of my class. In VC++ 6 I could use the header file and create an instance. But C# doesnt allow that. In fact, > > [DllImport("mywin32.dll")] > public static extern Cwin32class(); > > is not compiled because the compiler thinks that method has no return type! But constructors are not supposed to have return types. Thus I cant find any way of using my unmanaged object oriented classes with the C# UI. Can anyone help me please? > > Thanks > Mukesh

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;