Re: c dll to c#



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


.



Relevant Pages

  • Re: integer size and portability-a wishful controversy
    ... >> BTW, there is no point in using the old Turbo C compiler, unless ... I do NOT consider programs relying on int having at least 32 bits as ... use the PC as an almost freestanding platform for developing/testing ... device drivers for various pieces of PC hardware. ...
    (comp.lang.c)
  • printf anomaly
    ... My understanding is that the 1000 will default to int ... Then it will be promoted to unsigned long (since on our platform long ... and printf is a variadic ... I must be missing something or the compiler is broken? ...
    (comp.lang.c)
  • Re: data types
    ... ...but the manual for the compiler I am using says int is 16-bit. ... typedef [whatever type is 16 bits in your platform] int16; ...
    (comp.lang.c)
  • Re: how to detect the compile is 32 bits or 64 bits?
    ... If your question is simply about int, you create problems by assuming it is determined by whether you have a 32- or 64-bit platform. ... The algorithm is the same ... It's certainly likely, but not assured, that a compiler would choose int in accordance with efficiency. ... For example, most Windows compilers have 32-bit int and long even on platforms which have efficient 64- and 128-bit instructions, where linux for the same platform supports 64-bit int. ...
    (comp.lang.c)
  • Re: interesting use of NEXT SENTENCE vs. CONTINUE
    ... These days I don't do compiler maintenance, but I HAVE done in the past, so ... You had a chance to point out how adherence to the standard can improve ... >> compile it WITH MINOR MODIFICATIONS for a specific platform. ... > platform-specific extension to COBOL ...
    (comp.lang.cobol)