.NET Interop IntPtr vs. ref

前端 未结 5 868
独厮守ぢ
独厮守ぢ 2020-12-28 09:22

Probably a noob question but interop isn\'t one of my strong points yet.

Aside from limiting the number of overloads is there any reason I should declare my DllImpo

5条回答
  •  天命终不由人
    2020-12-28 09:49

    No, you cannot overload SendMessage and make the wparam argument an int. That will make your program fail on a 64-bit version of the operating system. It has to be a pointer, either IntPtr, a blittable reference or an out or ref value type. Overloading the out/ref type is otherwise fine.


    EDIT: As the OP pointed out, this is not actually a problem. The 64-bit function calling convention passes the first 4 arguments through registers, not the stack. There is thus no danger of stack mis-alignment for the wparam and lparam arguments.

提交回复
热议问题