T
Tony Cox
Hi. I'm new to VB.NET, so please be gentle ;-)
I'm trying to transfer VB.NET structures to a shared memory area
at a fixed location in process memory space. The structures themselves
consist of simple data types (integers, shorts, etc.), and the data transfer
to/from the shared memory area is handled with the Marshalling routines
from System.Runtime.InteropServices. All seems to work ok.
I've implemented a class "MMVb" to handle the details of the data transfer,
and to simplify the end-user interface, but the syntax is not as clean as
I'd have
hoped. The idea is to be able to handle any type of UDT, all though the same
class property, like this:-
Dim mapping As MMVb = new MMVb(...) ' Object to handle xfer
Dim f As fred '
User-defined struct
....
mapping.struct = f '
Transfer to shared memory
So far so good. The last statement calls the 'struct' property set routine,
defined as "Set(ByVal Value As Object)". I can happily call
Marshal.StructureToPtr(..) to transfer the data and all works fine.
Now what I'd like to do is reverse the procedure to reconstruct the data,
like this:-
f = mapping.struct
'Transfer back to VB.NET
but of course the method Marshal.PtrToStructure requires the
System.Type of the structure it is reconstructing. For arbitrary
objects, this isn't known. I've tried adding an optional parameter
to the 'struct' property definition, and of course this works but
leads to messy syntax like this:-
f = mapping.struct( f)
'Parameter needed to work out return type
and I suppose I could always just define things as methods
passing 'f' by reference leading to syntax like this:-
mapping.getStruct( f)
So, is it possible to find the type of the expected returning data,
so that (in this case) I can determine it from the Property Get
routine?
Thanks for any insight....
I'm trying to transfer VB.NET structures to a shared memory area
at a fixed location in process memory space. The structures themselves
consist of simple data types (integers, shorts, etc.), and the data transfer
to/from the shared memory area is handled with the Marshalling routines
from System.Runtime.InteropServices. All seems to work ok.
I've implemented a class "MMVb" to handle the details of the data transfer,
and to simplify the end-user interface, but the syntax is not as clean as
I'd have
hoped. The idea is to be able to handle any type of UDT, all though the same
class property, like this:-
Dim mapping As MMVb = new MMVb(...) ' Object to handle xfer
Dim f As fred '
User-defined struct
....
mapping.struct = f '
Transfer to shared memory
So far so good. The last statement calls the 'struct' property set routine,
defined as "Set(ByVal Value As Object)". I can happily call
Marshal.StructureToPtr(..) to transfer the data and all works fine.
Now what I'd like to do is reverse the procedure to reconstruct the data,
like this:-
f = mapping.struct
'Transfer back to VB.NET
but of course the method Marshal.PtrToStructure requires the
System.Type of the structure it is reconstructing. For arbitrary
objects, this isn't known. I've tried adding an optional parameter
to the 'struct' property definition, and of course this works but
leads to messy syntax like this:-
f = mapping.struct( f)
'Parameter needed to work out return type
and I suppose I could always just define things as methods
passing 'f' by reference leading to syntax like this:-
mapping.getStruct( f)
So, is it possible to find the type of the expected returning data,
so that (in this case) I can determine it from the Property Get
routine?
Thanks for any insight....