473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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

--
Dr. Tony Cox
Citrus Controls Inc.
e-mail: tc@coxrt.com
http://CitrusControls.com/
Nov 20 '05 #1
2 3011
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.


Thanks. Saved me a lot of further messing around.
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave | last post by:
Hi everyone, (I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group) The issue I'm having is occuring in the IDE of VS.NET...
40
by: Ron Adam | last post by:
After considering several alternatives and trying out a few ideas with a modified list object Bengt Richter posted, (Thank You), I think I've found a way to make slice operation (especially far end...
4
by: Dietmar Kuehl | last post by:
Hi, after reading the documentation on C# generics from several sources, I'm still unclear whether it is possible to infer associated types from a type argument. For example, if I have an...
10
by: MLH | last post by:
I wish to give someone an A97 database they can install on their PC as a runtime application. I want them to click a button on a form (frmDocumentMyPC). I want to document as much useful...
13
by: Alison Givens | last post by:
....... that nobody knows the answer. I can't imagine that I am the only one that uses parameters in CR. So, my question again: I have the following problem. (VB.NET 2003 with CR) I have a...
4
by: Zark3 | last post by:
Hi all, I was wondering if anybody could enlighten me on the possibility of dynamic casting. Or, well, whether or not I'm actually trying to do this the right way. What I have is a base class...
4
by: Fred Lazy | last post by:
Is is possible to retrieve the name of an .js file from within the .js file itself: For example, if the file is named "bla.js" and it is imported into an html document: <script...
2
by: Gillard | last post by:
hello I get a dll with standard call in C ++ but I really do not know how to use it in VB anyone can help??? there is the declarations in cpp to use the functions #ifndef SFPDF_H #define...
3
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.