私はこれを機能させることができます:
[<DllImport("user32.dll")>]
extern bool GetClientRect(nativeint, RECT*)
let getClientRect hwnd =
let mutable r = RECT()
if GetClientRect(hwnd, &&r) = false then
raise <| System.Exception("GetClientRect failed")
r
しかし、何らかの理由で、これr
は例外がスローされることなく、ゼロのままになります。
[<DllImport("user32.dll")>]
extern bool GetClientRect(nativeint, [<Out>] RECT rect)
let getClientRect hwnd =
let mutable r = RECT()
if GetClientRect(hwnd, r) = false then
raise <| System.Exception("GetClientRect failed")
r
もちろん、ポインタを使用する際の問題は、警告が表示warning FS0051: The use of native pointers may result in unverifiable .NET IL code
されることです。当然のことながらそうです。
何が欠けている可能性がありますか?
編集:それはすでに答えられていますが、記録のために、構造体の定義:
[<Struct>]
type RECT =
val left:int
val top:int
val right:int
val bottom:int