Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing C# class between C++ functions

Tags:

c++

c#

c++-cli

I am wondering if it is possible to pass my invoked C# object between c++ functions? I can already call my C# dlls from my native code, but now I need to pass a object between c++ functions which also means that I need to declare it in the header file...

When defining it in my header file I get the following error:

BOOL Exists(Api ^api);

Error   60  error C3395: 'ApiBase' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention

Does anyone know how I should handle this in my header?

like image 801
James Ford Avatar asked Jan 18 '26 13:01

James Ford


1 Answers

You use __declspec(dllexport) to export a native C++ class. But it sounds like your class is a managed .net ref class. If you wish to export the functionality for both managed clients and unmanaged clients you need to declare two classes. One a managed ref class, and one a native class.

Or perhaps the issue is that you are trying to export a function that has managed parameters with __declspec(dllexport). Again that is not possible.

like image 135
David Heffernan Avatar answered Jan 21 '26 02:01

David Heffernan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!