reference c++ dll from c#
-
i have written a c++ application now i want to override virtual event handlers in the c++ app with c#. also i want to compile the c++ app - or part of it- as a dll that i can reference in c#. but i keep on getting an error saying it's not a com object... problem 1. what type of project do i need to create for c++ to be accesible in c# 2. how do i override an event handler. or how do i call a c# method from c++ (instead of overriding the event handler. i'll call a c# method in a different dll)
rather have something you don't need, than need something you don't have
-
i have written a c++ application now i want to override virtual event handlers in the c++ app with c#. also i want to compile the c++ app - or part of it- as a dll that i can reference in c#. but i keep on getting an error saying it's not a com object... problem 1. what type of project do i need to create for c++ to be accesible in c# 2. how do i override an event handler. or how do i call a c# method from c++ (instead of overriding the event handler. i'll call a c# method in a different dll)
rather have something you don't need, than need something you don't have
ok i compiled the c++ with /clr now c# adds the reference
rather have something you don't need, than need something you don't have
-
ok i compiled the c++ with /clr now c# adds the reference
rather have something you don't need, than need something you don't have
got it working with dllimport but cannot get it to call a c++ method c#code :
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int mine = tester(); Console.WriteLine(mine); } [DllImport("touchlib.dll", EntryPoint = "tester", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] static extern int tester(); } }
c++ codeint Touchable::tester() { return 5; }
rather have something you don't need, than need something you don't have
-
got it working with dllimport but cannot get it to call a c++ method c#code :
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int mine = tester(); Console.WriteLine(mine); } [DllImport("touchlib.dll", EntryPoint = "tester", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] static extern int tester(); } }
c++ codeint Touchable::tester() { return 5; }
rather have something you don't need, than need something you don't have
Hi, DllImport is used to call native code such as Win32 functions. if your C++ dll is .NET code, just call the C++ class as if it were C#. :)
Luc Pattyn [My Articles]
-
Hi, DllImport is used to call native code such as Win32 functions. if your C++ dll is .NET code, just call the C++ class as if it were C#. :)
Luc Pattyn [My Articles]
should i add a using ? and for functions in a class do i need to call Class::function()?
rather have something you don't need, than need something you don't have
-
should i add a using ? and for functions in a class do i need to call Class::function()?
rather have something you don't need, than need something you don't have
donsolms wrote:
should i add a using ?
yes
donsolms wrote:
for functions in a class do i need to call Class::function()?
no calling any CLR compliant language obeys the rules of the calling language, hence in C# you need a using statement, and call as class.method(args) or object.method(args). :)
Luc Pattyn [My Articles]
-
donsolms wrote:
should i add a using ?
yes
donsolms wrote:
for functions in a class do i need to call Class::function()?
no calling any CLR compliant language obeys the rules of the calling language, hence in C# you need a using statement, and call as class.method(args) or object.method(args). :)
Luc Pattyn [My Articles]
i can't get the using to work. i have the c++ dll in a namespace named touchlib and then a class named Touchable.
using touchlib;
doesn't work, i have added a reference to the dll. a i missing something, maybe in the compiling of the dll? how can i be sure that the dll is managed c++? what type of vc++ project is managed c++?rather have something you don't need, than need something you don't have
-
i can't get the using to work. i have the c++ dll in a namespace named touchlib and then a class named Touchable.
using touchlib;
doesn't work, i have added a reference to the dll. a i missing something, maybe in the compiling of the dll? how can i be sure that the dll is managed c++? what type of vc++ project is managed c++?rather have something you don't need, than need something you don't have
Hi, I dont remember the details for C++, but you did build the C++ dll, didnt you ? so you know it is/isnt managed code. if you were able to add a reference to it in your C# app, it must be managed code. now Intellisense should show the available classes (C# and managed C++). :)
Luc Pattyn [My Articles]
-
Hi, I dont remember the details for C++, but you did build the C++ dll, didnt you ? so you know it is/isnt managed code. if you were able to add a reference to it in your C# app, it must be managed code. now Intellisense should show the available classes (C# and managed C++). :)
Luc Pattyn [My Articles]
thanks a lot, it is working 100% now. i might have referenced an older version of the dll somehow, and after a simple clean solution for the c++ dll and c# project made it work. thanks again
rather have something you don't need, than need something you don't have