473,785 Members | 2,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple c++ dll caling from c# dll

does anybody could tell me how can i do a 'simple c++ dll I compiled'
- calling
from my c# code (when I try adding this dll to references' it ays that
it should be com) ?

T I A
jS

Aug 7 '07 #1
5 1531
Koliber,

If you want to call classes in a C++ dll, you have one of two options.
The first is to expose the classes through COM, and use COM interop. The
other is to create a managed wrapper for the classes in the dll, and then
add a reference to the managed wrapper.

Regardless, you can't just add a reference to a C++ dll and use the
classes.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Koliber (js)" <pr************ **@poczta.onet. plwrote in message
news:11******** **************@ r34g2000hsd.goo glegroups.com.. .
does anybody could tell me how can i do a 'simple c++ dll I compiled'
- calling
from my c# code (when I try adding this dll to references' it ays that
it should be com) ?

T I A
jS

Aug 7 '07 #2
Koliber (js) wrote:
does anybody could tell me how can i do a 'simple c++ dll I compiled'
- calling
from my c# code (when I try adding this dll to references' it ays that
it should be com) ?
If the DLL is a normal Win32 DLL and not a COM/ActiveX DLL, then
you need to DllImport the functions you want to use.

Note that I said functions not classes and methods.

Arne
Aug 7 '07 #3
You can use C++/CLI to create a managed wrapper DLL for your C++ DLL

--
Sheng Jiang
Microsoft MVP in VC++
"Koliber (js)" <pr************ **@poczta.onet. plwrote in message
news:11******** **************@ r34g2000hsd.goo glegroups.com.. .
does anybody could tell me how can i do a 'simple c++ dll I compiled'
- calling
from my c# code (when I try adding this dll to references' it ays that
it should be com) ?

T I A
jS

Aug 7 '07 #4
On 7 Sie, 19:19, Arne Vajhøj <a...@vajhoej.d kwrote:
Koliber (js) wrote:
does anybody could tell me how can i do a 'simple c++ dll I compiled'
- calling
from my c# code (when I try adding this dll to references' it ays that
it should be com) ?

If the DLL is a normal Win32 DLL and not a COM/ActiveX DLL, then
you need to DllImport the functions you want to use.

Note that I said functions not classes and methods.
Arne

I tried some like this in cpp dll

#define DllExport __declspec( dllexport )

/DllExport extern void test();
DllExport extern int a();
DllExport extern int b();

/
*************** *************** *************** *************** *************** **/

void test()
{
}
int a()
{
return 6;
}
int b()
{
return -6; //676k6
}
and in c# code:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Runtime. InteropServices ;
namespace ConsoleApplicat ionTest
{
class Program
{
[DllImport("dng_ validate.dll")]
public extern static void test();
[DllImport("dng_ validate.dll")]
public extern static int a();
[DllImport("dng_ validate.dll")]
public extern static int b();

static void Main(string[] args)
{
test();
b();
a();
}
}
}

but in runtime there is an error that in my dll there is no entry
point test
(also a b tried) There is if i check it with total commander plugin
exported functions are:

int __cdecl a(void)
int __cdecl b(void)
int __cdecl test(void)

:( ?

T I A
JS

Aug 8 '07 #5
You need to be very specific about name mangling and calling convention
options. On the C++ side, you probably want:

#define FOREXPORT __declspec( dllexport ) __stdcall extern "C"

Use Dependency Walker (www.dependencywalker.com) to view the export table,
then you have the option of viewing the raw names or the decoded C++ names.

You will probably also want a linker definition file (.def) to avoid name
mangling completely.
"Koliber (js)" <pr************ **@poczta.onet. plwrote in message
news:11******** **************@ o61g2000hsh.goo glegroups.com.. .
On 7 Sie, 19:19, Arne Vajhøj <a...@vajhoej.d kwrote:
Koliber (js) wrote:
does anybody could tell me how can i do a 'simple c++ dll I compiled'
- calling
from my c# code (when I try adding this dll to references' it ays that
it should be com) ?

If the DLL is a normal Win32 DLL and not a COM/ActiveX DLL, then
you need to DllImport the functions you want to use.

Note that I said functions not classes and methods.
Arne

I tried some like this in cpp dll

#define DllExport __declspec( dllexport )

/DllExport extern void test();
DllExport extern int a();
DllExport extern int b();

/
*************** *************** *************** *************** *************** **/

void test()
{
}
int a()
{
return 6;
}
int b()
{
return -6; //676k6
}
and in c# code:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Runtime. InteropServices ;
namespace ConsoleApplicat ionTest
{
class Program
{
[DllImport("dng_ validate.dll")]
public extern static void test();
[DllImport("dng_ validate.dll")]
public extern static int a();
[DllImport("dng_ validate.dll")]
public extern static int b();

static void Main(string[] args)
{
test();
b();
a();
}
}
}

but in runtime there is an error that in my dll there is no entry
point test
(also a b tried) There is if i check it with total commander plugin
exported functions are:

int __cdecl a(void)
int __cdecl b(void)
int __cdecl test(void)

:( ?

T I A
JS
Aug 8 '07 #6

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

Similar topics

2
6081
by: delisonews | last post by:
I'm looking for a simple, filesystem-based message board. (No MySQL!) Something that I could include easily in my code: include '../inc/messageboard.php'; .... so that the board shows up at the bottom of every PHP page. The board should have just the basic features, like: - posting capability
3
3699
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example program #include <list>
8
6507
by: Dan | last post by:
Using XML::Simple in perl is extreemly slow to parse big XML files (can be up to 250M, taking ~1h). How can I increase my performance / reduce my memory usage? Is SAX the way forward?
6
2069
by: Manuel Collado | last post by:
I would like to write simple, yet well structured documents with a really simple XML DTD (or schema). Either Docbook or SDocbook are overkill for this simple case. XHTML is simpler, but unstructured (no nested sections). And is not really very simple. Before trying to setup a stripped-down document format by myself, I would like to know if there are simple XML document structure proposals ready to be used (I dislike to reinvent the...
11
2715
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
13
5744
by: Michael B Allen | last post by:
Hi, I've tried to write the *simplest* memory allocator possible. I think it would be useful in many cases such as allocating memory on stack as a poor man's garbage collection perhaps. I was hoping the clc crowd had some ideas for making it even simpler! In-lined below the full program (132 lines). It's a circular singular linked list of "cells" inspired by the one in Plauger's text
7
2289
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request that page like http://machinename/dir1/hellp.aspx instead of running that page it starts downloding ...whats missing here ....why the aspx engine not running the page....
14
2989
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
10
2139
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel <System.Web.Services.WebService(Namespace:="http:// wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
0
9645
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
9480
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
10153
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...
1
7500
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
6740
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
5381
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
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.