开发者

Apparently it's important to use Int32 instead of int when messing with DLLImport stuff?

开发者 https://www.devze.com 2022-12-31 15:24 出处:网络
In C#, when messing with that system DLLImport/(unmanaged?) code stuff, I read somewhere开发者_运维技巧 it\'s important to use Int32 exact type instead of int. Is this true? And can someone please ela

In C#, when messing with that system DLLImport/(unmanaged?) code stuff, I read somewhere开发者_运维技巧 it's important to use Int32 exact type instead of int. Is this true? And can someone please elaborate on why it's important to do this?


I think it is more likely that you read about using IntPtr instead of int. As others have said, int and Int32 are equivalent.

It is not really a problem to interchange int and IntPtr on a 32-bit system as they are the same size (4 bytes). The problem comes when on a 64-bit system - if you use int instead of IntPtr, it now has the wrong size (4 bytes instead of 8 bytes) and can cause errors.


I don't believe that this is true. int is an alias for Int32. They mean the exact same thing and will be compiled to the same IL.

A list of aliases can be found here.

0

精彩评论

暂无评论...
验证码 换一张
取 消