I'm new to C++ and have come across a problem that has me stumped. It's obviously something I'm doing wrong but for the life of me I can't figure out what.
I have some code to return the width of my monitor in pixels:
int x = GetSystemMetrics(SM_CXSCREEN);
This returns 1366, which is correct for the monitor I'm currently using. However the problem arises when I try to wrap it up in a function as follows:
1 2 3 4 5
int getScreenWidth() {
return GetSystemMetrics(SM_CXSCREEN);
}
When calling this function it returns the value 013214B5. I have no idea why?
Can anyone shed some light on what I'm doing wrong?
Thanks.
Edit: I'm using Visual Studio Community 2015 and I should add that I don't get any build errors or warnings. Also, if it matters, creating a function out of GetSystemMetrics(SM_CXSCREEN) in exactly the same manner in Visual Basic (syntactical differences aside of course) returns the correct result, so I'm clearly missing or misunderstanding something specific to C++ here.
Yes I'm returning it to an integer value. I thought it was hex too but if you convert 013214B5 to decimal it equals 20059317, which doesn't make much sense either.
The fist line is correctly printing 1366 but the next line is now printing 012714B5 to the console window.
When I return getScreenWidth() to an integer variable then try to print that I get the value of 013214B5.
Edit: Okay guys I've solved it. Really sorry to waste your time but it was a daft oversight on my part the whole time - I looked again over my code and realised that when I was calling getScreenWidth() I wasn't including the parenthesis at the end!!!! Such a schoolboy error! Sorry again guys but I really appreciate your help in trying to figure it out for me. Thank you.
That makes sense. I was just about to ask why the integer was being printed in hexadecimal format - that suggested it was printing the address of something.