473,405 Members | 2,421 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,405 software developers and data experts.

DllImport and Data Marshalling

Hi,

I had a question on DllImport. On importing a function from a VC++ dll
using DllImport (to a C# program), the function argument data types
and the return types may be of a type that is not supported by C#. In
this case if I am not mistaken the system performs default marshalling
- matching the data types to its most similar equivalent in C#. Is
this right?

Also, I presume this can be overridden by using MarshalAs. Is this
right as well?

However my main question is if I do not want to override the default
marshalling, how do I figure out what is the default marshalled (C#)
type for a given VC++ type?

Hope to hear from someone on this. Thank you.
Nov 16 '05 #1
2 5758
Marshaling allocates unmanaged memory, copies unmanaged memory blocks and
converts managed to unmanaged types.

System.Runtime.InteropServices.UnmanagedType to get the equivalent types in
c#.

There are lot of converstion routines in Marshal class as static functions

for example

Marshal.StringToBSTR - Converts .NET string to COM string.

--
Shak
(Houston)
"Rookie" <do***********@rediffmail.com> wrote in message
news:cf**************************@posting.google.c om...
Hi,

I had a question on DllImport. On importing a function from a VC++ dll
using DllImport (to a C# program), the function argument data types
and the return types may be of a type that is not supported by C#. In
this case if I am not mistaken the system performs default marshalling
- matching the data types to its most similar equivalent in C#. Is
this right?

Also, I presume this can be overridden by using MarshalAs. Is this
right as well?

However my main question is if I do not want to override the default
marshalling, how do I figure out what is the default marshalled (C#)
type for a given VC++ type?

Hope to hear from someone on this. Thank you.

Nov 16 '05 #2

"Rookie" <do***********@rediffmail.com> wrote in message
news:cf**************************@posting.google.c om...
Hi,

I had a question on DllImport. On importing a function from a VC++ dll
using DllImport (to a C# program), the function argument data types
and the return types may be of a type that is not supported by C#. In
this case if I am not mistaken the system performs default marshalling
- matching the data types to its most similar equivalent in C#. Is
this right?

Also, I presume this can be overridden by using MarshalAs. Is this
right as well?

However my main question is if I do not want to override the default
marshalling, how do I figure out what is the default marshalled (C#)
type for a given VC++ type?
Not sure if you see it right. You always have to specify the parameters
(managed ones) yourself when declaring a function prototype for import.

Some managed types can be marshalled as more then one unmanaged type,
therefore one of the unmanaged types is the default and MarshalAs lets you
override it.

There is a table available suggesting what managed type to use for a given
unmanaged type:
http://msdn.microsoft.com/library/de...edatatypes.asp

HTH,
greetings


Hope to hear from someone on this. Thank you.

Nov 16 '05 #3

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

Similar topics

1
by: Peter Gloor | last post by:
Hello NG, I have a mirror.dll written in C I would like to access from a C# console application. However, I dont't know how to to it. The dll is fairly well documented and I have access to the...
6
by: Tim Mulholland | last post by:
Whats the correct C# datatype (or marshalling function or something) to use when you're importing a function that has a signature similar to char* FuncA(char c) ? Assuming you know that...
3
by: Simon | last post by:
Hi all, I am trying to call a function from a dll and it has the following prototype. int foo(int *argc, char ***argv) or int foo(int *argc, char *argv) I am having problems that I assume...
1
by: Stephen Richardson | last post by:
I have a C++ dll which returns a structure, the structure contains a char variable, as shown below. struct MyCStruct { short iNumber; char Name; }; I've declared a structure in C# as shown...
1
by: marfi95 | last post by:
I'm trying to call methods in a C++ dll from vb.net that is not a .com component. I've read I can just use regular Declare statements just as you do in VB6 except that some of the types need to...
8
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2, C# for Windows application. I use DllImport so I can call up a function written in C++ as unmanaged code and compiled as a dll us vs2005. My application is able to...
11
by: itdevries | last post by:
Hi, I'm trying to convert some char data I read from a binary file (using ifstream) to a float type. I've managed to convert the int types but now I need to do the float types as well but it...
1
by: JohnCox | last post by:
I have a simple Win32 DLL I wrote named "SimpleLib" that exports two functions. It is written in C++ and compiled with __stdcall (/Gz) and with the preprocessor definition _MBCS (not Unicode). ...
1
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.