diablo_alex
diablo_alex

Reputation: 37

Calling a C++ Function that takes pointers from C#

I have a function in C++ that returns pointer values​​:

fPosFirst( int &aId, char *aNname, char *aDirectory );

But I have to pass this to C#. How can I do that?

Upvotes: 1

Views: 201

Answers (2)

Joshua
Joshua

Reputation: 43188

This is VB.NET syntax, but you should be able to convert this to C# easily enough.

Private Declare Ansi Sub fPosFirst lib "libraryname" (ByRef aId as Integer, byval aName as StringBuilder, byval aDirectory as StringBuilder)

Now if aNname and aDirectory should have been const char *, you can use String instead of StringBuilder and it gets a lot easier.

Upvotes: 1

abelenky
abelenky

Reputation: 64672

You need to examine P/Invoke (Platform Invoke), a way to call native-code functions (C and C++) from .Net/Managed Code (C#).

Upvotes: 3

Related Questions