Bit long and rambly but here goes:-
I have a number of API's (about 300), they tend to use structures pretty much like this.
<StructLayout(LayoutKind.Sequential)> _
Friend Structure SomeReturnedData
Friend f1 As SomeField1
Friend f2 As SomeField2
Friend f3 As SomeField3
.....
.....
End Structure
<StructLayout(LayoutKind.Sequential)> _
Friend Structure SomeField1
Friend day As byte
Friend month As byte
Friend year As byte
End Structure
Now some field is the representation of a date at the other end (and there are a couple of hundred different types like this). Marshalling SomeReturnedData is not a problem, off it goes as a byte array and back it comes.
My problem arises when I want to do this:-
<StructLayout(LayoutKind.Sequential)> _
Friend Structure SomeField1
Friend day As byte
Friend month As byte
Friend year As byte
'Now some internal stuff which I don't want marshalled say:
Friend dt as DateTime
End Structure
The problem now of course is that the length changes from that expected. There is no <MarshalAs(IgnoreThisPlease)> type attribute.
Obviously I have to ensure that I ensure the integrity of the internal data structures after the structure has been marshalled - a nuisance but easily enough achievable (though not automatically of course since the constructor isn't run or anything).
Equally I can write wrappers for all the damn things, but what I want to do is encapsulate both the external and CLR representations in the structure.
Any suggestions as to how I can do that without resorting to a custom marshaller?
I have a number of API's (about 300), they tend to use structures pretty much like this.
<StructLayout(LayoutKind.Sequential)> _
Friend Structure SomeReturnedData
Friend f1 As SomeField1
Friend f2 As SomeField2
Friend f3 As SomeField3
.....
.....
End Structure
<StructLayout(LayoutKind.Sequential)> _
Friend Structure SomeField1
Friend day As byte
Friend month As byte
Friend year As byte
End Structure
Now some field is the representation of a date at the other end (and there are a couple of hundred different types like this). Marshalling SomeReturnedData is not a problem, off it goes as a byte array and back it comes.
My problem arises when I want to do this:-
<StructLayout(LayoutKind.Sequential)> _
Friend Structure SomeField1
Friend day As byte
Friend month As byte
Friend year As byte
'Now some internal stuff which I don't want marshalled say:
Friend dt as DateTime
End Structure
The problem now of course is that the length changes from that expected. There is no <MarshalAs(IgnoreThisPlease)> type attribute.
Obviously I have to ensure that I ensure the integrity of the internal data structures after the structure has been marshalled - a nuisance but easily enough achievable (though not automatically of course since the constructor isn't run or anything).
Equally I can write wrappers for all the damn things, but what I want to do is encapsulate both the external and CLR representations in the structure.
Any suggestions as to how I can do that without resorting to a custom marshaller?

Comment