471,337 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Invoking C++ with pointer param from C#

If a C++ method takes a pointer to an int for output (for example), how
should C# pass the int into which it wants the result returned?

(I'll post some test code shortly. I'm writing the question from memory
after a meeting yesterday with a C# developer and need to recreate his two
test projects. I've got some C++ that he needs to invoke. I'm new to C# but
have dealt with low-level cross-language issues in other languages.)

In C++, the method signature would look like one of:

void fooptr(int* x);
void fooref(int& x);

How would C# invoke these?
Jun 27 '08 #1
1 1095
Kenneth Porter wrote:
If a C++ method takes a pointer to an int for output (for example), how
should C# pass the int into which it wants the result returned?
In C++, the method signature would look like one of:

void fooptr(int* x);
void fooref(int& x);

How would C# invoke these?
[DllImport(@"C:\ptr.dll")]
private static extern void fooptr(ref int x);
[DllImport(@"C:\ptr.dll")]
private static extern void fooref(ref int x);

seems to work for me.

Arne
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Chris Jankowski | last post: by
15 posts views Thread by Albert | last post: by
23 posts views Thread by bluejack | last post: by
4 posts views Thread by ma740988 | last post: by
8 posts views Thread by Martin Jørgensen | last post: by
5 posts views Thread by Joe Van Dyk | last post: by
8 posts views Thread by amirr | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.