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{,,oobjectAddress}:Show()
warningbox{,,AsString(oobjectpostcode)}:Show()
RETURN "what's up"
CLASS testobject
EXPORT oAddress AS STRING
EXPORT opostcode AS INT
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{,,oobjectAddress}:Show()
warningbox{,,AsString(oobjectpostcode)}:Show()
RETURN "what's up"
CLASS testobject
EXPORT oAddress AS STRING
EXPORT opostcode AS INT