SystemParametersInfo - C/C++

Started by
15 comments, last by Endar 18 years, 4 months ago
Okay, how do you convert a normal char string to a wchar string?

Edit:: or, better yet, a std::string to std::wstring?


Okay, I've gotten that working.

The program compiles fine, runs with no errors, yet again, nothing happens.

This is the code that I currenly have:
	// create a wstring object because that is what the setwallpaper func takes	std::wstring s;	// convert between string and wstring	for(i=0; i < fname.size(); i++)		s += fname;	CoInitialize(NULL);	HRESULT hr;	IActiveDesktop *pActiveDesktop;	//Create an instance of the Active Desktop	hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,						IID_IActiveDesktop, (void**)&pActiveDesktop);	if( hr != S_OK )		MessageBox(NULL, "ERROR", "ERROR", MB_OK);	// change the wallpaper	pActiveDesktop->SetWallpaper(s.c_str(), 0);	// Call the Release method	pActiveDesktop->Release();	CoUninitialize () ;


And, I've tried calling GetLastError after every single statement there. After every single one, and the only error I get, is after the 'CoUninit..' call. The error is "Class does not exist.". Which is fairly confusing, because, if it didn't wouldn't every function call there generate a fit? (fit, as in crazy fit)

[Edited by - Endar on December 20, 2005 8:40:37 AM]
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Advertisement
That's really wierd, my program above's just worked with me (Windows XP Pro).
I also noticed that even these function executed successfully, a call to GetLastError () still produces error codes (I checked every function call and invoked GetLastError () right after). This case I really have no idea, sorry.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Quote:Original post by Skeleton_V@T
That's really wierd, my program above's just worked with me (Windows XP Pro).
I also noticed that even these function executed successfully, a call to GetLastError () still produces error codes (I checked every function call and invoked GetLastError () right after). This case I really have no idea, sorry.


Did you try with jpg's or only bmp's?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
I've tried JPG, PNG, GIF, not BMP (as I'm quite sure it will work). And with BMPs I'd just use SystemParametersInfo ().

I'm surprised you received no error code from these functions but GetLastError ().

You may try GetWallpaper () method to see if pActiveDesktop really works:
WCHAR wcTemp[512] ;hr = pActiveDesktop -> GetWallpaper (wcTemp, 512, 0) ;MessageBoxW (0, wcTemp, 0, 0) ;



[Edited by - Skeleton_V@T on December 20, 2005 10:10:21 AM]
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Skeleton, your little code snippet (when called after I've called SetWallpaper) gives the name of the wallpaper I just set it to. So, it looks like a case of what happened before when I was using SystemParametersInfo. It just looks like the system doesn't know to update the wallpaper.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
I just realized I hadn't included IActiveDesktop::ApplyChanges () in my posted code.
Quote:There maybe something wrong though, I have no compiler to check right now...

pActiveDesktop -> ApplyChanges (AD_APPLY_ALL) ;

This should work for you now, sorry.

Btw, if we select a JPEG as wallpaper then call GetWallpaper (), we'll see that the temporary bitmap is stored at
[WinPart]:\Documents and Settings\[UserName]\Local Settings\Application Data\Microsoft\Wallpaper1.bmp
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Success!!

Thanks for all your help Skeleton.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper

This topic is closed to new replies.

Advertisement