Passing a pointer to an unmanaged method

  • Thread starter Lois Spangenberg via DotNetMonster.com
  • Start date
L

Lois Spangenberg via DotNetMonster.com

I have an external method that includes a pointer to a struct as one of its
arguments.

The struct definition is managed, and contains both value and reference
(float arrays) members.

What I'm trying to do is instantiate an instance of the struct and pass it
to the method to be populated.

I tried creating a pointer to the struct, but the compiler complains with
the message that I can't take the address of a managed object.

I can compile using the keyword 'ref' rather than creating a pointer, but
the struct doesn't get populated when I pass it to the method; however, it
doesn't generate an exception either.

What is the correct syntax for handling this situation
 
M

Mattias Sjögren

I can compile using the keyword 'ref' rather than creating a pointer, but
the struct doesn't get populated when I pass it to the method; however, it
doesn't generate an exception either.

Are you sure the managed struct definition matches what the native
function expects?

What is the correct syntax for handling this situation

Use a ref parameter.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top