By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

DllImport and Data Marshalling

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.