473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why does this keep failing?

It always returns false...*pvParam never gets populated. Any ideas?

int temp;

char *pvParam = "";

try

{

if(SystemParametersInfo(SPI_GETDESKWALLPAPER,0,pvP aram,0)==true)

{

cout << "True: vParam = " << pvParam;

}

else

{

cout << "False: vParam = " << pvParam;

}

}

catch(char * str)

{

cout << "EXCEPTION: " << str;

}

cout << "\n\nHit a Key to exit...";

cin >> temp;
Jul 19 '05 #1
2 3034
Steve S wrote:
It always returns false...*pvParam never gets populated. Any ideas?
Well, let's see...

Oh wait, this is going to be harder than I thought, given the absurd
formatting of the code you've provided. Ugh!

int temp;

char *pvParam = "";

try

{

if(SystemParametersInfo(SPI_GETDESKWALLPAPER,0,pvP aram,0)==true)
Hmmm. Passing a pointer to a string literal and expecting it to
*receive* information?

Make `pvParam' either an array of char or allocate space for it (in
either case long enough to contain whatever that long-named
non-standard function wants to write into it).

{

cout << "True: vParam = " << pvParam;

}

else

{

cout << "False: vParam = " << pvParam;

}

}

catch(char * str)

{

cout << "EXCEPTION: " << str;

}

cout << "\n\nHit a Key to exit...";

cin >> temp;


HTH,
--ag

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Jul 19 '05 #2

"Steve S" <hi***@rogersNOSPAM.com> wrote in message
news:iB********************@news01.bloor.is.net.ca ble.rogers.com...
It always returns false...*pvParam never gets populated. Any ideas?
See below.
int temp;

char *pvParam = "";
'pvParam' points to one character (with value zero)
of storage which must not be modified. I.e. it
points to a (nonmodifiable) string literal, not
modifiable storage.
char pvParam[size required by 'SystemParametersInfo()'];

or

char *pvParam = new char[size required by 'SystemParametersInfo()'];

See the documentation for 'SystemParametersInfo()' for
what the size requirement is.

More below.
try

{

if(SystemParametersInfo(SPI_GETDESKWALLPAPER,0,pvP aram,0)==true)

{

cout << "True: vParam = " << pvParam;

}

else

{

cout << "False: vParam = " << pvParam;

}

}

catch(char * str)
Are you sure that 'SystemParametersInfo()' throws this
type as an exception?

{

cout << "EXCEPTION: " << str;

}

cout << "\n\nHit a Key to exit...";

cin >> temp;


If you use the 'new[]' form above for reserving
your storage, don't forget to free it after you're
done with it:

delete[] pvParam;

-Mike
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: lawrence | last post by:
In the following loop, at the end, the method debugNotes() is printing out some notes for me to read, so I can figure out what is going on in my script. Where I try to print out the value of the...
12
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard...
4
by: Scott Kinney | last post by:
I have an inventory database. I want to delete out-of-stock items from the main database, but keep them in a separate table so that I can reference data about them. I created a copy of the item...
17
by: hugo27 | last post by:
hugo27 July 13, 2004 > >The teachy books and documentation I've read do not >mention the Escape key, but everytime I hit it during >runtime my programs go bananas. > >This relates to a larger...
31
by: bilbothebagginsbab5 AT freenet DOT de | last post by:
Hello, hello. So. I've read what I could find on google(groups) for this, also the faq of comp.lang.c. But still I do not understand why there is not standard method to "(...) query the...
7
by: grocery_stocker | last post by:
Given the following snippet of code: (taken from http://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html) void * xmalloc (size_t size) { register void *value = malloc (size);...
18
by: Scott David Daniels | last post by:
There has been a bit of discussion about a way of providing test cases in a test suite that _should_ work but don't. One of the rules has been the test suite should be runnable and silent at every...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
3
by: =?Utf-8?B?V2FsaWQ=?= | last post by:
Hello: I have migrated a site from IIS5 to IIS6. The site is configured and the we app is installed on the new IIS site. I can get to the web page but when I try to login, this is what I get...
4
by: James | last post by:
Hi, I have just upgraded a user machine to Vista (our first) as a test. Unfortunately a couple of our apps are failing due to Vista... 1. One app that loads an assembly from an Intranet...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.