Passing class through using P invoke

F

Feldaspar

Hi,

I'm trying to pass an object through to unmanaged code using P invoke.
My code for .net and unmanaged (visual objects) code is below.

The object properties are not coming through right. The address is
coming across as a garbled string and the postcode is not the right
number, any ideas what i am doing wrong?


..NET CODE
*************************************************************


[DllImport(@"C:\test\test.DLL")]
static extern string
PassObject([MarshalAs(UnmanagedType.LPStruct)]TestObject oobject);

[StructLayout(LayoutKind.Sequential)]
public class TestObject
{
[MarshalAs(UnmanagedType.LPTStr)]
public string address;

[MarshalAs(UnmanagedType.U4)]
public int postcode;
}


private void Call()
{
TestObject o = new TestObject();
o.address = "test";
o.postcode = 99;
PassObject(o);
}


VISUAL OBJECT CODE:
******************************************************************************

FUNCTION PassObject(oobject AS testobject)
WarningBox{,,oobject:blush:Address}:Show()
warningbox{,,AsString(oobject:blush:postcode)}:Show()
RETURN "what's up"

CLASS testobject
EXPORT oAddress AS STRING
EXPORT opostcode AS INT
 
M

Mattias Sjögren

I'm trying to pass an object through to unmanaged code using P invoke.
My code for .net and unmanaged (visual objects) code is below.

The object properties are not coming through right. The address is
coming across as a garbled string and the postcode is not the right
number, any ideas what i am doing wrong?

I'm not familiar with Visual Object so I don't know the details of its
data types. What's the size of its INT type? Which character encoding
is used in its STRING type? Does it guarantee to preserve member order
in memory of its classes.


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