|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Passing class through using P invokeI'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:oAddress}:Show() warningbox{,,AsString(oobject:opostcode)}: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. I'm not familiar with Visual Object so I don't know the details of its>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? 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 -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. |
|||||||||||||||||||||||