| Willy Denoyette [MVP] wrote:
| > Not really,
|
| Yes, really.
|
Sorry, but we will have to agree to disagree.
| > just name me a C compiler that targets the Microsoft Windows
| > platform who has a 64 bit "built-in" long type.
|
| Why? It doesn't matter if I know of one, or if one exists, the
| definitions of the data types are still the same.
|
We are not discussing the definitions of a language, we are talking about
interop, that is pass values across managed/unmanaged module boundaries.
| > 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,
|
| Of course not. It relies on the sizes defined in the specific compiler
used.
|
PInvoke doesn't and can't rely on the type or version of the native compiler
used. What's important for you, is to consider the interop mapping, and
here, the documented behavior is that a long type (in C/C++) is mapped to a
Int32 (just like an int), MS (safely) assumed this to be valid because all C
compilers targetting Windows use 32 bit ints and longs, that's why I can
'safely' say to the OP, a "long" in C is an "Int32" in .NET. If the module
was built with a 'deriving' compiler (it doesn't have to be a C compiler),
you better know it before you start calling into that module.
Things are more consistent when talking about COM interop marshaling (or
user marshaling), here it's the MIDL who rules, and MIDL defines an int and
a long to be 32 bit, no confusion possible, unless another tool is used to
define the interface which derives from the MIDL definitions, but also here
AFAIK there isn't such a tool.
| > 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.
| >
| >
| > | > | 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.
| > | >
| > | >
| > | > | > | > | 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.
| > | > | >
| > | > | > | > | > | > | 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.
| > | > | >
| > | > | >
| > | >
| > | >
| >
| >