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 (Applicati on.Handle, CSIDL_RECENT, PIDL);
SHGetPathFromIDList(PIDL, Path);
CoCreateInstance(CLSID_She llLink,
nil,
CLSCTX_INPROC_SERVER,
IShellLink,
psl);
if psl.QueryInterface(IPersis tFile, 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.
...
uses
ShellApi,ShlObj, ComObj, ActiveX;
..
Procedure DoSomething;
var
PIDL: PItemIDList;
Path: array[0..MAX_PATH] of Char;
psl : IShellLink;
Begin
SHGetSpecialFolderLocation
SHGetPathFromIDList(PIDL, Path);
CoCreateInstance(CLSID_She
nil,
CLSCTX_INPROC_SERVER,
IShellLink,
psl);
if psl.QueryInterface(IPersis
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Concur with Greybird
ASKER
Thanks Greybird. That worked.