Link to home
Start Free TrialLog in
Avatar of wolsen
wolsen

asked on

COM - works in main thread, but not in seperate thread?

Please look at the code below.  I would like to know why it behaves differently in when I call it from a seperate thread.  Is there some sort of special COM/OLE initialization that I must do to make it work in a seperate thread?
...
uses
ShellApi,ShlObj, ComObj, ActiveX;
..
Procedure DoSomething;
var
  PIDL: PItemIDList;
  Path: array[0..MAX_PATH] of Char;
  psl  : IShellLink;
Begin
  SHGetSpecialFolderLocation(Application.Handle, CSIDL_RECENT, PIDL);
  SHGetPathFromIDList(PIDL, Path);
  CoCreateInstance(CLSID_ShellLink,
                  nil,
                  CLSCTX_INPROC_SERVER,
                  IShellLink,
                  psl);
  if psl.QueryInterface(IPersistFile, ppf) = 0 then
  begin
    //Program gets here if main thread calls DoSomething.  
    //Program does not get here if a seperate thread calls DoSomething.
.....

Thanks,

Will.
ASKER CERTIFIED SOLUTION
Avatar of Greybird
Greybird

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pcsentinel
pcsentinel

Concur with Greybird
Avatar of wolsen

ASKER

Thanks Greybird.  That worked.