E_NOTIMPL error with IActiveDesktop

I'm trying to write a program that will save the positions of all my icons on my desktop so that if they get jumbled up, I don't have to spend five minutes putting them back where they should be (about 2/3 of my screen is icons). This is my first time using COM, so I decided to try a simple program first using GetDesktopItemCount(). After searching the tubes for tutorials, I wrote this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <shlobj.h>

using namespace std;

int main()
{
	int testInt;
	HRESULT hr;
	IActiveDesktop* pIAD;

	hr = CoInitialize(NULL);

	hr = CoCreateInstance(
		CLSID_ActiveDesktop,
		NULL,
		CLSCTX_INPROC_SERVER,
		IID_IActiveDesktop,
		(void**) &pIAD);

	hr = pIAD->GetDesktopItemCount(&testInt,0);

	cout<<testInt<<endl;

	cin.get();

	pIAD->Release();

	return 0;
}

I have two questions. 1. Is IActiveDesktop the correct/best way to do what I want to do? 2. Why do I get the error E_NOTIMPL after the call to GetDesktopItemCount() on line 21 and what can I do to fix it? So far, MSDN and Google have been all but useless so any help would be appreciated.
Works for me. Did you define _WIN32_IE=0x0500?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <windows.h>
#include <wininet.h>
#include <ShlObj.h>
#include <ShlGuid.h>
#include <iostream>

int main()
{
	HRESULT hr;

	CoInitialize(0);

	IActiveDesktop *pActiveDesktop;
	hr = CoCreateInstance(
			CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
			IID_IActiveDesktop, (void**)&pActiveDesktop);
	if (pActiveDesktop)
	{
		INT iCount = -1;
		pActiveDesktop->GetDesktopItemCount(&iCount, 0);
		std::cout << iCount << std::endl;

		pActiveDesktop->Release();
	}

	CoUninitialize();

	return 0;
}
Did you define _WIN32_IE=0x0500?


Where do I need to do (or not do) that?

EDIT: I found out that Active Desktop is no longer supported after windows xp (sigh).
Last edited on
I needed to do it as I plugged the code into an old project that I use for checking syntax and so on for the forum related code. If yours compiled at all, you probably don't need it.

Without _WIN32_IE being defined to a value greated than 0x0400, the IActiveDesktop stuff isn't defined. I presume that's because the Active Desktop was introduce in NT 4.0. I built and ran this on XP (NT 5.1).
Topic archived. No new replies allowed.