function SendArrayMessage(Handle: HWND; Msg: UINT; WParam: WPARAM;
LParam: TIntegerDynArray): LRESULT;
var
Buffer: IntPtr;
begin
Buffer := Marshal.AllocHGlobal(Length(LParam) * SizeOf(Integer));
try
Marshal.Copy(LParam, 0, Buffer, Length(LParam));
Result := SendMessage(Handle, Msg, WParam, Buffer);
finally
Marshal.FreeHGlobal(Buffer);
end;
end;
Callback Functions When passing a function pointer for a managed function to an unmanaged API, a reference must be maintained to the delegate or it will be garbage collected. If you pass a pointer to your managed function directly, a temporary delegate will be created, and as soon as it goes out of scope (at the end of MyFunction in the example below), it is subject to garbage collection. Consider the following Delphi 7 code: function MyFunction: Integer; begin ... RegisterCallback(@MyCallback); ... end;In order for this to work in a managed environment, the code needs to be changed to the following:
const MyCallbackDelegate: TFNMyCallback = @MyCallback; function MyFunction: Integer; begin ... RegisterCallback(MyCallbackDelegate); ... end;This will ensure that the callback can be called as long as MyCallbackDelegate is in scope. Data types The same rules apply for callbacks as any other unmanaged API function. Special cases Any parameters used in an asynchronous process must be declared as
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




