2

I'm trying to integrate with a windows based api using c-sharp and I've run into this issue.

The api sends me a pointer to a struct that holds a bunch of virtual methods

struct CApiInterface
{
   virtual int __stdcall Version(void);
   ...
}

My question is, how can I call methods off this in C#? I'd like to do something like:

CApiInterface _api;

public void Start(CApiInterface* api)
{
_api = api;
}

...

public void SomeOtherMethod()
{
_api.version();
}

I would like to stay out of CLI/C++ if at all possible, if this is even possible to begin with.

hmakholm left over Monica
  • 23,074
  • 3
  • 51
  • 73
Noah
  • 13,821
  • 4
  • 36
  • 45

1 Answers1

2

Check out this question for an example of someone else who did the same thing. It seems to revolve around using delegates marked with the UmanagedFunctionPointerAttribute.

Community
  • 1
  • 1
Ken Wayne VanderLinde
  • 18,915
  • 3
  • 47
  • 72