L
LLLYJ
Unregistered / Unconfirmed
GUEST, unregistred user!
本人在开发一个软件,通过在COM对象中使用SafeArray来保存数据,
例子:
IDXData = interface(IDispatch)
function Get_Data : PSafeArray; stdcall;
...
property Data : PSafeArray read Get_Data;
end;
我另有一个线程,希望使用它实现对于数据的异步处理,
TDXSendDaemon = class(TThread)
private
FInEventHandle : THandle;
FOutEventHandle : THandle;
FDxDataLock : TCriticalSection;
FObjStream : Pointer;
protected
procedure ExecuteSend; virtual;
procedure Execute; override;
public
constructor Create(CreateSuspended: Boolean);
destructor Destroy; override;
procedure SendMessage(const ADXData: IDXData);
end;
procedure TDXSendDaemon.Execute;
begin
CoInitialize(nil);
try
while not Terminated do
begin
if WaitForSingleObject(FInEventHandle,50) = WAIT_OBJECT_0 then
begin
try
ExecuteSend;
except
on e : exception do
begin
//Terminate;
DebugMessageFmt('%s,%s',[e.classname, e.message]);
raise;
end;
end;
end;
end;
finally
CoUnInitialize;
end;
end;
procedure TDXSendDaemon.ExecuteSend;
var
Rslt : HRESULT;
Intf : IDXData;
PSa : PsafeArray;
DataPtr : Pointer;
begin
Rslt := CoGetInterfaceAndReleaseStream(IStream(FObjStream), IDXData, Intf);
FObjStream := nil;
SetEvent(FOutEventHandle);
OLECheck(Rslt);
if Assigned(Intf) then
begin
PSa :=Intf.Data;
Rslt := SafeArrayAccessData(PSA, DataPtr);
OleCheck(Rslt);
try
//; do my process on DataPtr
finally
SafeArrayUnAccessdata(PSA); // 基本上到这儿就会出错,且CPU占用达到100%
end;
Intf := nil;
end;
end;
有谁碰到过这样的问题吗?[gold]重金酬谢![/gold]
例子:
IDXData = interface(IDispatch)
function Get_Data : PSafeArray; stdcall;
...
property Data : PSafeArray read Get_Data;
end;
我另有一个线程,希望使用它实现对于数据的异步处理,
TDXSendDaemon = class(TThread)
private
FInEventHandle : THandle;
FOutEventHandle : THandle;
FDxDataLock : TCriticalSection;
FObjStream : Pointer;
protected
procedure ExecuteSend; virtual;
procedure Execute; override;
public
constructor Create(CreateSuspended: Boolean);
destructor Destroy; override;
procedure SendMessage(const ADXData: IDXData);
end;
procedure TDXSendDaemon.Execute;
begin
CoInitialize(nil);
try
while not Terminated do
begin
if WaitForSingleObject(FInEventHandle,50) = WAIT_OBJECT_0 then
begin
try
ExecuteSend;
except
on e : exception do
begin
//Terminate;
DebugMessageFmt('%s,%s',[e.classname, e.message]);
raise;
end;
end;
end;
end;
finally
CoUnInitialize;
end;
end;
procedure TDXSendDaemon.ExecuteSend;
var
Rslt : HRESULT;
Intf : IDXData;
PSa : PsafeArray;
DataPtr : Pointer;
begin
Rslt := CoGetInterfaceAndReleaseStream(IStream(FObjStream), IDXData, Intf);
FObjStream := nil;
SetEvent(FOutEventHandle);
OLECheck(Rslt);
if Assigned(Intf) then
begin
PSa :=Intf.Data;
Rslt := SafeArrayAccessData(PSA, DataPtr);
OleCheck(Rslt);
try
//; do my process on DataPtr
finally
SafeArrayUnAccessdata(PSA); // 基本上到这儿就会出错,且CPU占用达到100%
end;
Intf := nil;
end;
end;
有谁碰到过这样的问题吗?[gold]重金酬谢![/gold]