943,898 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 387
  • C++ RSS
Nov 28th, 2008
0

Help Please Win32

Expand Post »
hey everyone im making an gui in C++ which needs to retrieve windows registrys such as windows version etc. however im stuck on some code i was hoping for some help please.
C++ Syntax (Toggle Plain Text)
  1. void GetSystemInformation(void)
  2. {
  3. float fprocessor;
  4. HKEY hKey;
  5. DWORD processorspeed;
  6. DWORD datasize;
  7.  
  8. RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Hardware\\Description\\System\\CentralProcessor\\0",0, KEY_QUERY_VALUE,&hKey);
  9. RegQueryValueEx(hKey,("~MHz"),NULL,NULL,(LPBYTE)&processorspeed,&datasize);
  10.  
  11. fprocessor=float(processorspeed);
  12.  
  13. if (fprocessor>1000)
  14. sprintf(processorspeed,"%3.1f Ghz",fprocessor/1000);
  15. else
  16. sprintf(processorspeed,"%3.1f Mhz",fprocessor);
  17. }

that is my function however i get a error which is error C2664: 'sprintf' : cannot convert parameter 1 from 'DWORD' to 'char *' i cant find what the problem is cause the teacher said sprintf should get it to work and now i cant get in touch with my teacher so all help will be much apperciated. also if anyone knows a site which will help me get more sample code for any registry calls such as windows version,computer name etc can you please let me know thanks
Last edited by Superstar288; Nov 28th, 2008 at 7:49 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
Superstar288 is offline Offline
46 posts
since Oct 2008
Nov 28th, 2008
0

Re: Help Please Win32

sprintf expects a char* as the first parameter; it is where it will store the output, as a string of characters.

I don't know what you actually want to do, but if you want to see that it's working, try the following lines (instead of the sprintf lines above):
  1. if (fprocessor>1000)
  2. printf("%3.1f Ghz",fprocessor/1000);
  3. else
  4. printf("%3.1f Mhz",fprocessor);
This will print the info to the console. If you wanted to return the string from the function, you would have to change the function return type, or parameter list.
Last edited by dougy83; Nov 28th, 2008 at 10:33 pm.
Reputation Points: 85
Solved Threads: 45
Posting Whiz in Training
dougy83 is offline Offline
275 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Rational Number Class
Next Thread in C++ Forum Timeline: const_reverse_iterator vs vec.rend()





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC