How to transfer an array in COMDCOM

zhaozj2021-02-08  296

Because the COM / DCOM object is not running in the client program (except for the COM object, even if so, in order to unify the interface, the inner process COM must not pass the pointer), and all the programs in Win32 have their own independent 2GB The memory space, the program and the program transmits pointer (memory address) are meaningless, and a large number of data such as arrays, strings is allocated in the program, and then use the pointer to add internal deployment. If you access data, how do you pass in the COM / DCOM object?

A new variable Variant is introduced in Win32, and an array can be passed through Variant. Specific implementation method, Delphi is implemented as:

Server (COM / DCOM program):

Procedure ttestdcom.send4 (Size: Integer; D1: Olevariant);

Type

TDATA = array [0..999] of byte;

VAR

Data: TDATA;

i: integer;

Begin

For i: = 0 to size-1 do begin

Data [i]: = D1 [i];

END;

END;

CLEINT:

VAR

D1: olevariant;

Begin

D1: = VararrayCreate ([0,99], Varbyte);

{

D1 [1]: = 45;

.... // Deposit value into D1

}

S.send4 (99, d1); // s is TestDcom object

END;

转载请注明原文地址:https://www.9cbs.com/read-1335.html

New Post(0)