is java byte the same as C# byte?

2019-01-25 07:16发布

Native method from dll works in java if the input parameter is array of bytes - byte[]. If we use the same method from c# it throws EntryPointNotFoundException.

Is that because of byte[] in java and c# are different things? and if it's so how should I use native function from c#?

3条回答
我命由我不由天
2楼-- · 2019-01-25 08:01

What's the signature of the native function? How do you declare it in Java and in C#?

The most common reason for EntryPointNotFoundException is that function name is mangled (esp. true if function is written in C++) or misspelled.

Another source of problem is 'W' and 'A' suffixes for WinAPI function used to distinguish ANSI and Unicode versions of functions. .NET interop mechanism can try to guess the function suffix, so that may be the source of confusion,

查看更多
狗以群分
3楼-- · 2019-01-25 08:04

Java lacks the unsigned types. In particular, Java lacks a primitive type for an unsigned byte. The Java byte type is signed, while the C# byte is unsigned and sbyte is signed.

查看更多
Evening l夕情丶
4楼-- · 2019-01-25 08:13

Is that because of byte[] in java and c# are different things?

Yes.

  • Endianness: Java stores things internally as Big Endian, while .NET is Little Endian by default.
  • Signedness: C# bytes are unsigned. Java bytes are signed.

See different results when converting int to byte array - .NET vs Java.

查看更多
登录 后发表回答