Last active
June 25, 2016 06:51
-
-
Save ROki1988/724c49e3c8dc15bd2be19f17e1389da7 to your computer and use it in GitHub Desktop.
COMUtils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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