Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

Is it possible to find the System.Type of the expected function return type in VB.NET?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony Cox - 25 Sep 2003 21:43 GMT
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....

Signature

Dr. Tony Cox
Citrus Controls Inc.
e-mail: tc@coxrt.com
http://CitrusControls.com/

Mattias Sj?gren - 26 Sep 2003 06:56 GMT
Tony,

>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?

No, in this case all you could find out was that the method returns
Object, not what that object is assigned to.

I'd add a System.Type parameter indicating the requested return type,
and call it with

f = mapping.GetStruct(GetType(fred))

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Tony Cox - 26 Sep 2003 14:27 GMT
> Tony,
>
[quoted text clipped - 4 lines]
> No, in this case all you could find out was that the method returns
> Object, not what that object is assigned to.

Thanks. Saved me a lot of further messing around.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.