Re: c dll to c#
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Tue, 13 Jun 2006 23:54:57 +0200
Not really, just name me a C compiler that targets the Microsoft Windows
platform who has a 64 bit "built-in" long type.
Anyway, .NET interop (both PInvoke and COM) cannot rely on a 'vague'
definition of fundamental types like integers to build systems that have to
pass such types across module boundaries, that's why there is an interop
mapping defined (search MSDN for details on Marshaling arguments, this
mapping for an int and a long looks like:
wtypes.h INT = C++ int = C++/CLI int = CLR Int32
wtypes.h LONG = C++ long = C++/CLI long = CLR Int32
See, both are mapped to In32 and the value is passed "as is". If you happen
to interop with a library that assumes a long to be 64 bit, you better know
it or you are in trouble.
Willy.
"Göran Andersson" <guffa@xxxxxxxxx> wrote in message
news:OEmlVuxjGHA.3408@xxxxxxxxxxxxxxxxxxxxxxx
| Yes, for that specific C compiler, that is true.
|
| Willy Denoyette [MVP] wrote:
| > Well, the OP is talking about .NET PInvoke interop on Windows platforms
| > right? Well, in that case a long in C is 32 bit (or could you name me a
| > Windows C compiler that has 64 bit longs?) and the PInvoke layer will
pass
| > an UInt64 as a "long long" (64 bit integer) which is not what is
expected.
| >
| >
| >
| > Willy.
| >
| >
| > "Göran Andersson" <guffa@xxxxxxxxx> wrote in message
| > news:erpuqXsjGHA.5036@xxxxxxxxxxxxxxxxxxxxxxx
| > | That depends.
| > |
| > | The size of an int is defined as the word size of the CPU. A long is
| > | only defined to be at least the size of an int.
| > |
| > | Willy Denoyette [MVP] wrote:
| > | > Not at all, UInt64 is 64 bit, a long in C is 32 bit!
| > | >
| > | > Willy.
| > | >
| > | > "Mihaly" <Mihaly@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
| > | > news:17399D14-21DB-44E3-B6D9-3B2D971FA00A@xxxxxxxxxxxxxxxx
| > | > | Hello,
| > | > |
| > | > | Try to use System.Byte[100] for unsigned char[100] and
System.UInt64
| > for
| > | > | unsigned long.
| > | > |
| > | > | Mihaly
| > | > |
| > | > | "Arda Zuber" wrote:
| > | > |
| > | > | > Hi everyone.
| > | > | > I have a .dll that i want to call from a c# source. But i can't
| > figure
| > | > out a
| > | > | > way...
| > | > | > Here are the .dll's input variables and the definition.
| > | > | >
| > | > | > extern "C" void _stdcall MyFunc(unsigned char var1[100], int
length,
| > | > | > unsigned long *arrFinal)
| > | > | >
| > | > | > And I want to call it by [DllImport(path,EntryPoint=MyFunc)]
| > | > | > public static extern void MyFunc(here comes the variables)
| > | > | >
| > | > | > but i cannot figure out the replacements for unsigned char and
| > unsigned
| > | > long
| > | > | > * types in c#.
| > | > | >
| > | > | > Can you help me? Thanks.
| > | >
| > | >
| >
| >
.
- Follow-Ups:
- Re: c dll to c#
- From: Göran Andersson
- Re: c dll to c#
- References:
- Re: c dll to c#
- From: Willy Denoyette [MVP]
- Re: c dll to c#
- From: Göran Andersson
- Re: c dll to c#
- From: Willy Denoyette [MVP]
- Re: c dll to c#
- From: Göran Andersson
- Re: c dll to c#
- Prev by Date: Re: How Dictionary<TKey,TValue> is checking keys?
- Next by Date: Reading \r From File As Carriage Return
- Previous by thread: Re: c dll to c#
- Next by thread: Re: c dll to c#
- Index(es):
Relevant Pages
|