Import a C++ class to C#
-
Hi, I have a C++ class that is compiled as a DLL. now I would like to import it to my C# program. I know how to import function, but what should I do for importing the class so I can in my C# program create an instance of this class? Thanks,
Unless it is managed C++ you cannot import the class. If it is managed C++ then what you have as an Assembly which can be added by adding a reference to it in the project and by putting a
using myNamespace
at the top of the C# file you want to use the managed C++ class in.*Developer Day Scotland - Free community conference *Colin Angus Mackay's Blog *Latest Scottish Developers Newsletter
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Remember that the force of gravity can go up as well as down.
-
Unless it is managed C++ you cannot import the class. If it is managed C++ then what you have as an Assembly which can be added by adding a reference to it in the project and by putting a
using myNamespace
at the top of the C# file you want to use the managed C++ class in.*Developer Day Scotland - Free community conference *Colin Angus Mackay's Blog *Latest Scottish Developers Newsletter
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Remember that the force of gravity can go up as well as down.
-
hi, You could try adding a reference to the dll to your c# project. It will fail if it is not a managed assembly or COM component. Another way would be to try to open the dll with the MSIL disassembler. Again this will fail if there is no CLR header. Alan.
-
Unless it is managed C++ you cannot import the class. If it is managed C++ then what you have as an Assembly which can be added by adding a reference to it in the project and by putting a
using myNamespace
at the top of the C# file you want to use the managed C++ class in.*Developer Day Scotland - Free community conference *Colin Angus Mackay's Blog *Latest Scottish Developers Newsletter
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Remember that the force of gravity can go up as well as down.
Something which just came to mind. Would it be possible to have a function which returns a pointer to an instantiation of the class? So would something like this work? //C++ extern "C" MyClass *GetInstantiation(void); //C# [DllImport("MyFile.dll")] public static extern IntPtr GetInstantiation();
-
Something which just came to mind. Would it be possible to have a function which returns a pointer to an instantiation of the class? So would something like this work? //C++ extern "C" MyClass *GetInstantiation(void); //C# [DllImport("MyFile.dll")] public static extern IntPtr GetInstantiation();
yes its possible ;)
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
Hi, I have a C++ class that is compiled as a DLL. now I would like to import it to my C# program. I know how to import function, but what should I do for importing the class so I can in my C# program create an instance of this class? Thanks,
I usually create a bridge written in C++ managed which creates one managed class and namespace that could be later imported into C#, but underneath this managed C++ class works with that actual and normal C++ class any way it is expected to work with this class, either I compile them together or I import dll and call this class internally. This bridge serves several good purposes: to test what actually I need in C# from that C++ class. Only those things pass the bridge. Second the bridge is an excellent place to check if parameters are passed correctly and if some of them have to be arranged differently: pointers, arrays... all need different treatment in C# and C++. If you don't have this bridge, but you directly call a C++ procedure from C# then you have to think about this inside C# code every time you call a specific C++ function. And then if you want to use the same C++ class again, the same problem. With bridge you just import it and everything is tested.
-
yes its possible ;)
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can