// Gets a pointer to a struct, and converts it // into a structure. public MyDllStruct GetStruct() { IntPtr structPtr = MyDllInterface.get_a_pointer_struct(); return((MyDllStruct)Marshal.PtrToStructure( structPtr, typeof(MyDllStruct))); }
// Calls the MyDllInterface.MyDllFunction and returns // the resulting struct. If an error occured, an // exception is thrown. public MyDllStruct CallFunction(int param1, bool param2) { MyDllStruct result = new MyDllStruct(); int errorCode = MyDllInterface.MyDllFunction( param1, param2, result); if (errorCode < 0) { throw new Exception(String.Format( "We got an error with code {0}. Message: ", errorCode, MyDllInterface.mydll_get_errormsg())); } return(result); }