473,791 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# uses C++ managed DLL

Is it possible to use / integrate a C++ DLL from C# code
like it is possible with JNI at Java?
Is there any technology like that?
Nov 15 '05 #1
2 1327
You can use the DllImportAttrib ute to enable you to call methods in the C++
DLL. All you need to know is the signature of the method you wish to call.

For example..

(C++ DLL)

int MyMethod(int foo, short bar);

(C#)

class dllWrapper
{
[DllImport("mydl l.dll")]
public static external Int32 MyMethod(Int32 foo, Int16 bar);
}

class MyCSharpClass
{

public void UsesDLL()
{
Int32 x = dllWrapper.MyMe thod(10,100); // calls C++ DLL
}
}

--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Falk" <an*******@disc ussions.microso ft.com> wrote in message
news:05******** *************** *****@phx.gbl.. .
Is it possible to use / integrate a C++ DLL from C# code
like it is possible with JNI at Java?
Is there any technology like that?

Nov 15 '05 #2
There are a couple ways you can do this.

If the C++ DLL merely has global functions (ie no class objects), you can
use PInvoke in C# to call them directly.

If you need to deal with C++ objects, you'll need to use Managed C++ to wrap
your C++ class.

Try these articles:

http://msdn.microsoft.com/library/de...rp09192002.asp
http://msdn.microsoft.com/library/de...rp12192002.asp

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Falk" <an*******@disc ussions.microso ft.com> wrote in message
news:05******** *************** *****@phx.gbl.. .
Is it possible to use / integrate a C++ DLL from C# code
like it is possible with JNI at Java?
Is there any technology like that?

Nov 15 '05 #3

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

Similar topics

20
6173
by: | last post by:
Back in the Old days, I compile a C++ executable, copy the dll's used by this executable to the same folder. Go to another computer, copy that folder locally, double click on the exe file and off we go.... Today, I have a C# .NET executable, I copied the used .NET dll into the same folder. Went to the other computer copied the folder locally. I double click on the exe file and a lot of errors that looks like Access violations except it...
2
3008
by: Thomas | last post by:
I can't call a method with managed(__gc) c++ class arguments. e.g. c++: public __gc class Point { ... } public __gc class Line { Line(Point *p0, Point *p1) { ... } }
4
2527
by: 0to60 | last post by:
I'm trying to create a .dll with VS.NET 2003 Architect that contains a math computational component. I need the guts of the thing to be in native code, as performance is key for that part. But, I need a .net wrapper because this "calculator" is actually a component used by an enterprise app written entirely in .net. What I want to do is have one project. I've created an MC++ .dll project. Its got a __gc class (the wrapper) and a...
0
1145
by: Anna | last post by:
Hi, (Initial info: .Net 2003 on Win2000) I'm developing a .Net App that uses a dll (say, dll_1) created in VC6 and _successfully_ recompiled in .Net 2003 (unmanaged, no wrappers). The dll_1 is set as a dependency in the application project properties (Linker->Input- >Additional Dependencies).
4
2182
by: | last post by:
I am stuck in a situation and I do believe that this should work, but it doesn't. I have a unmanaged dll, that uses MFC. This works great. Now I recompile the unmanaged dll so it contains mixed mode managed/unmanaged code, but only use unmanaged code, but this gives a error the moment I want to display a MFC dialog box: Something like unreferenced object,... during runtime.
5
2010
by: | last post by:
We have this situation: We have a unmanaged c++ executable located in a certain folder (a.exe) It loads a mixed mode managed/unmanaged dll using MFC dynamically from a completely different path (b.dll) This last dll, uses other pure managed and mixed managed/unmanaged dll's that uses MFC. (c.dll, d.dll,...) What works is a.exe loading b.dll. But once I want to use a functions in c.dll I get an exception indicating that c.dll is not...
5
1821
by: dk | last post by:
a very small system tray vb.net app built using a vb.net component form goes up to 18K for memory usage in the task manager. any idea why so much memory is being used for a very small application? explorer uses only 7.6k tia,
4
4894
by: chaz | last post by:
here is the html : <br> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="<%=LABEL_WIDTH%>" class="formtext"><%= HTEXT("Connection type:")%></td> <td class="formtext"> <input type="radio" class="inputRadio" id="dbStatus" name="dbStatus" value="1" onclick="changeDbStatus(1)" <%if dbStatus=1 then%checked
1
1055
by: =?Utf-8?B?RXZhbks=?= | last post by:
Is there a problem linking a .net C++ dll that relies on .net framework with an application that is developed and compiled in VS6 C?
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10428
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...
1
10156
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
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...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
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
5435
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
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.