Create a gist now

Instantly share code, notes, and snippets.

COMUtils
unit COMUtils;
interface
uses
System.Classes, Winapi.ActiveX;
type
TCOMUseThread = class(TThread)
private
FCOMType: Integer;
protected
procedure Execute(); override; final;
procedure InternalExecute(); virtual; abstract;
public
constructor CreateMTA(CreateSuspended: Boolean);
end;
implementation
{ TCOMUseThread }
constructor TCOMUseThread.Create4NonWindow(CreateSuspended: Boolean);
begin
FCOMType := COINIT_MULTITHREADED;
inherited Create(CreateSuspended);
end;
procedure TCOMUseThread.Execute;
begin
if not Succeeded(CoInitializeEx(nil, FCOMType)) then
begin
Exit();
end;
try
InternalExecute();
finally
CoUninitialize();
end;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment