 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Michael Evans Guest
|
Posted: Thu Jan 12, 2006 8:06 pm Post subject: Access Active Desktop items |
|
|
Hi,
I'm trying to access desktop items on the Windows Active Desktop. Active
Desktop is enabled and there are two desktop items. I can get the
correct count of items, but using GetDesktopItem to access an item
always fails. I'm using Delphi 7, running on Windows XP.
Does anyone know what the problem is?
procedure TForm1.Button4Click(Sender: TObject);
const
CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
var
ActiveDesktop: IActiveDesktop;
Count : Integer;
Result : Integer;
ItemProperties: TShComponent;
begin
ActiveDesktop := CreateComObject(CLSID_ActiveDesktop) as
IActiveDesktop;
ActiveDesktop.GetDesktopItemCount(Count, 0); //gets correct count
Result := ActiveDesktop.GetDesktopItem(0, ItemProperties, 0);
//returns -2147024809
end;
Regards
Michael Evans
|
|
| Back to top |
|
 |
Maarten Wiltink Guest
|
Posted: Thu Jan 12, 2006 10:03 pm Post subject: Re: Access Active Desktop items |
|
|
"Michael Evans" <michael (AT) otherNOSPAMsoft (DOT) com> wrote
| Quote: | I'm trying to access desktop items on the Windows Active Desktop.
Active Desktop is enabled and there are two desktop items. I can
get the correct count of items, but using GetDesktopItem to access
an item always fails. I'm using Delphi 7, running on Windows XP.
[...]
ActiveDesktop.GetDesktopItemCount(Count, 0); //gets correct count
Result := ActiveDesktop.GetDesktopItem(0, ItemProperties, 0);
//returns -2147024809
|
Googling for the hexadecimal representation of that number seems to
indicate it means "invalid parameter value" and can sometimes be
fixed by installing a newer DirectX.
Groetjes,
Maarten Wiltink
|
|
| Back to top |
|
 |
Michael Evans Guest
|
Posted: Fri Jan 13, 2006 6:21 am Post subject: Re: Access Active Desktop items |
|
|
| Quote: | Googling for the hexadecimal representation of that number seems to
indicate it means "invalid parameter value" and can sometimes be
fixed by installing a newer DirectX.
|
Thanks. I don't think that the GetDesktopItem uses DirectX. Searching
for that error message I found that it means ""invalid parameter value"
but I didn;t see anyhting about DirectX.
Looking at the documentation for it, it's expecting an LPCOMPONENT
structure as the 2nd argument. In Delphi's ShlObj.pas it's defined in
the format of the IE4COMPONENT structure.
Also, GetDesktopItem says it's supported on Windows 2000/ME.
Does anyone know a way to do this under Windows XP (and Windows 98 if
possible).
GetDesktopItem Documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/shellcc/platform/shell/reference/ifaces/iactivedesktop/GetDesktopItem
..asp
Component Structure Documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/shellcc/platform/shell/reference/structures/component.asp
IE4COMPONENT Structure Documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/shellcc/platform/shell/reference/structures/ie4component.asp
Regards
Michael
|
|
| Back to top |
|
 |
Rob Kennedy Guest
|
Posted: Fri Jan 13, 2006 6:54 am Post subject: Re: Access Active Desktop items |
|
|
Michael Evans wrote:
| Quote: | I'm trying to access desktop items on the Windows Active Desktop. Active
Desktop is enabled and there are two desktop items. I can get the
correct count of items, but using GetDesktopItem to access an item
always fails. I'm using Delphi 7, running on Windows XP.
Does anyone know what the problem is?
procedure TForm1.Button4Click(Sender: TObject);
const
CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
var
ActiveDesktop: IActiveDesktop;
Count : Integer;
Result : Integer;
ItemProperties: TShComponent;
begin
ActiveDesktop := CreateComObject(CLSID_ActiveDesktop) as
IActiveDesktop;
ActiveDesktop.GetDesktopItemCount(Count, 0); //gets correct count
Result := ActiveDesktop.GetDesktopItem(0, ItemProperties, 0);
//returns -2147024809
|
Note that GetDesktopItem does not return an Integer. It returns an
HResult, which is a COM error code. (Change the Result variable's
declaration accordingly.) You can use the ComCheck procedure to turn
such an error code into an exception with an error message.
Also note that GetDesktopItemCount is a not a procedure. It is a
function, and it returns an HResult that you should check before
proceeding. Just because the Count parameter get filled with the value
you expected doesn't necessarily mean the function's result was S_OK.
I think the newsgroup archives will show that I'm paranoid about
checking return values from API functions.
If ItemProperties is indeed declared as the correct type, try setting
its dwSize parameter before you call GetDesktopItem. And if that doesn't
work, then try calling ZeroMemory on the record before you set the size.
Forgetting to set the record size for an API function is consistent with
a return value of E_InvalidArg.
--
Rob
|
|
| Back to top |
|
 |
Michael Evans Guest
|
Posted: Fri Jan 13, 2006 5:13 pm Post subject: Re: Access Active Desktop items |
|
|
| Quote: | Note that GetDesktopItem does not return an Integer. It returns an
HResult, which is a COM error code.
|
Thanks, I've changed the code to use this.
| Quote: | If ItemProperties is indeed declared as the correct type, try setting
its dwSize parameter before you call GetDesktopItem. And if that doesn't
work, then try calling ZeroMemory on the record before you set the size.
|
I tried setting dwSize but that didn't help. Not sure if I used
ZeroMemory correctly as that didn't work either.
procedure TForm1.Button4Click(Sender: TObject);
const
CLSID_ActiveDesktop: TGUID
= '{75048700-EF1F-11D0-9888-006097DEACF9}';
var
ActiveDesktop: IActiveDesktop;
Count : Integer;
Result : HResult;
Item : TShComponent;
begin
ActiveDesktop := CreateComObject(CLSID_ActiveDesktop) as
IActiveDesktop;
Result := ActiveDesktop.GetDesktopItemCount(Count, 0);
OleCheck(Result); //no error
Item.dwSize := SizeOf(Item);
ZeroMemory(@Item, SizeOf(TShComponent));
Result := ActiveDesktop.GetDesktopItem(0, Item, 0);
OleCheck(Result); //Error - The Parameter is incorrect.
end;
Regards
Michael
|
|
| Back to top |
|
 |
Hans-Peter Diettrich Guest
|
Posted: Fri Jan 13, 2006 9:26 pm Post subject: Re: Access Active Desktop items |
|
|
Rob Kennedy schrieb:
| Quote: | Note that GetDesktopItem does not return an Integer. It returns an
HResult, which is a COM error code. (Change the Result variable's
declaration accordingly.) You can use the ComCheck procedure to turn
such an error code into an exception with an error message.
|
The SafeCall calling convention automagically checks the HResult, and
returns the result of the function (if it is a function). Without
SafeCall, every method is wrapped into a function, which returns an
HResult error code. When the wrapped method is a function, the result is
returned in a var parameter, added to the parameter list.
The declarations should be checked for the calling convention, and the
function/procedure calls then can be handled accordingly.
In the environment options you can select whether you want safecall
(preferred) or stdcall calling convention in the type library
editor/importer.
DoDi
|
|
| Back to top |
|
 |
Rob Kennedy Guest
|
Posted: Sat Jan 14, 2006 7:55 pm Post subject: Re: Access Active Desktop items |
|
|
Hans-Peter Diettrich wrote:
| Quote: | The SafeCall calling convention automagically checks the HResult, and
returns the result of the function (if it is a function). Without
SafeCall, every method is wrapped into a function, which returns an
HResult error code. When the wrapped method is a function, the result is
returned in a var parameter, added to the parameter list.
|
But IActiveDesktop does not use safecall, and it is declared in
ShlObj.pas, which was not generated by the type-library importer.
--
Rob
|
|
| Back to top |
|
 |
alanglloyd@aol.com Guest
|
Posted: Sat Jan 14, 2006 10:40 pm Post subject: Re: Access Active Desktop items |
|
|
MSDN reference for COMPONENT structure (== Delphi TShComponent I
believe) also refers to a COMPPOS and a COMPSTATEINFO structure
(csiOriginal & csiRestored) referenced in the COMPONENT structure. I
would imagine you would have to supply, zero, and dwSize these other
structures before the GetDeskTopItem genie was happy.
You might have to troll through ShObj.pas to identify the Delphi name
of these two structure types in TShComponent.
Alan Lloyd
|
|
| Back to top |
|
 |
Michael Evans Guest
|
Posted: Sun Jan 15, 2006 11:57 am Post subject: Re: Access Active Desktop items |
|
|
In article <1137278402.876014.45640 (AT) f14g2000cwb (DOT) googlegroups.com>,
[email]alanglloyd (AT) aol (DOT) com[/email] says...
| Quote: | MSDN reference for COMPONENT structure (== Delphi TShComponent I
believe) also refers to a COMPPOS and a COMPSTATEINFO structure
(csiOriginal & csiRestored) referenced in the COMPONENT structure. I
would imagine you would have to supply, zero, and dwSize these other
structures before the GetDeskTopItem genie was happy.
You might have to troll through ShObj.pas to identify the Delphi name
of these two structure types in TShComponent.
Alan Lloyd
|
I've got it working now. Thanks for everyones help.
TShComponent in Delphi's ShlObj.pas is the older IE4COMPONENT component
structure. I found an update called ShlObjAdditional by Daniel U.
Thibault which contains the correct structure. The following code works:
const
CLSID_ActiveDesktop: TGUID
= '{75048700-EF1F-11D0-9888-006097DEACF9}';
var
ActiveDesktop: IActiveDesktop;
Count : Integer;
Item : TIE5Component;
begin
ActiveDesktop := CreateComObject(CLSID_ActiveDesktop) as
IActiveDesktop;
OleCheck(ActiveDesktop.GetDesktopItemCount(Count, 0));
Item.dwSize := SizeOf(Item);
OleCheck(ActiveDesktop.GetDesktopItem(1, @Item, 0));
end;
regards
Michael
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|