Skip to content

Instantly share code, notes, and snippets.

@ROki1988
Last active June 25, 2016 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ROki1988/724c49e3c8dc15bd2be19f17e1389da7 to your computer and use it in GitHub Desktop.
Save ROki1988/724c49e3c8dc15bd2be19f17e1389da7 to your computer and use it in GitHub Desktop.
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