I have a C++ function, that I want to expose to C# for consumption. The catch is that the C++ code declaration is wrapped in namespace:
namespace OhYeahNameSpace
{
extern "C" __declspec(dllexport) void Dummy();
}
My question is, how to define the corresponding C# structure? I believe that C# code must be made aware of the existence of OhYeahNameSpace
, am I right?
Edit: I think a lot of people misunderstand my point ( no thanks due to a typo in my original example; fixed). I am asking about how to go by if there is a namespace for which the exported function is dwell on. One answer are missing on this part, another one says this can't be done and ask me to wrap it around, and another one is now currently with -1 vote.
Why not wrap in C++/CLI?
//ohyeah.h
namespace OhYeahNameSpace
{
public ref class MyClass
{
void Dummy();
}
}
//ohyeah.cpp
#include "ohyeah.h"
namespace OhYeahNameSpace
{
void MyClass::Dummy()
{
// call the real dummy in the DLL
}
}
Wrap as C and use P/Invoke:
--- OhYeahNameSpace_C.h ---
#ifdef __cplusplus
extern "C" {
#endif
void _declspec(dllexport) OhYeahNameSpace_Dummy();
#ifdef __cplusplus
}
#endif
--- OhYeahNameSpace_C.c ---
#include "OhYeahNameSpace_C.h"
#include <OhYeahNameSpace.h>
void OhYeahNameSpace_Dummy()
{
::OhYeahNameSpace::Dummy();
}
The example isn't 100% complete, but you get the gist of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With