Sign in to follow this  
Followers 0

Simple conversation question

5 posts in this topic

#1 ·  Posted (edited)

I needed a function to change the screenresolution and frequency so I started to write code to implement to Autoit3, cause I didn't want to use an external tool like "setres.exe". :huh2:

For instance one part of it is to set the display frequency through:

devMode.dmDisplayFrequency = (ulong)vParams[3].szValue();

the MSDN help shows that this parameter has to be an unsigned long value, so I do it with conversation "(ulong)".

The result ist that it doesn't work.

If I use f.i.:

devMode.dmDisplayFrequency = 75;

then the screenfrequency will change. :D

Hmmm....I don't know...I've looked into my c++book but can't find anything about it...

Has anyone of you an idea? maybe with "strtoul"?

Thanks for your help and regards :)

Edited by Holger

Share this post

Link to post
Share on other sites

One good example of why C++ casts (Although slightly cumbersome) are much better. Attempting to compile your code with the C-style cast, I get a pointer truncation Warning. Attempting to compile by using a C++ cast, I get an Error.

devMode.dmDisplayFrequency = static_cast<ulong>(vParams[3].szValue());

error C2440: 'static_cast' : cannot convert from 'const char *' to 'unsigned long'

        This conversion requires a reinterpret_cast, a C-style cast or function-style cast

Just a little food for thought, I use C-style casts in too many places also, hard habit to break.

Share this post

Link to post
Share on other sites

szValue() returns a string (char *) and nValue() returns a number (double). If you want numeric values, use nValue().

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0