|
If have tried your code but it results in 2 errors:
error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
error C2664: 'RegQueryValueExW' : cannot convert parameter 2 from 'const char [8]' to 'LPCWSTR'
That's the complete code:
#include "stdafx.h"<br />
#include <string><br />
#include <windows.h><br />
#include <iostream><br />
using namespace std;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
HKEY temporarykey;<br />
char* value;<br />
value = (char*)malloc(32);
DWORD lpcbData = 32;<br />
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\xxx",0,KEY_QUERY_VALUE,&temporarykey);<br />
RegQueryValueEx(temporarykey,"License",NULL,NULL,(unsigned char*)value,&lpcbData);<br />
RegCloseKey(temporarykey);<br />
value[31]=0;<br />
cout<<value;<br />
free(value);<br />
char i;<br />
cin >> i;<br />
return 0;<br />
}
Sorry for being such a pest! I owe you at least a beer for your efforts. Where are you based by the way?
|
|
|
|
|
I'm sorry, I forgot to put the _T() macro in. For some reason, my compiler (VC++ 6.0) accepts a string for LPCWSTR. Just replace "SOFTWARE\\xxx" with _T("SOFTWARE\\xxx") and "License" with _T("License") to fix that problem. If it STILL doesn't show the correct value, I'm stumped.
BTW, I know how annoying it is when the reg functions just won't do what you want them to do. I've had problems like this before. (Although I've never seen something like this...). And you're not, surprisingly, being much of a pest. I've had people ask me why the compiler doesn't let them use variables, and I told them to define the variables first, but they say that that's not the problem when each and every one of their "variables" are undefined. **sigh**. I hope I never meet programmers like that again.
|
|
|
|
|
Getting closer... Now no errors but it displays a sequence of 31 ===============================
whereas the key value is a hexadecimal number. Also tried to change the value to decimal numbers but it display the same sequence. Unsolvable mysteries of the registry keys....
|
|
|
|
|
Try changing lpcdData to a larger value. Or just change it back to 64, which is what you started with.
|
|
|
|
|
Nope. Changing the value slighlty outputs the same weird = signs. Increasing the value to 64 triggers a breakpoint in the executable. Arghhhhh!
|
|
|
|
|
No luck. I always get an error. I am starting wondering whether the fact that it is not working on my pc is becasue me and you are using different compilers... I am using Visual Studio 2005. Could that be the reason?
|
|
|
|
|
Well, I'm using Visual Studio 6.0. Isn't that older than 2005? I assume that all the functions in VC++ 6.0 would be incorporated into VC++ 2005...Is there any place where you can get a trial version of 2005?
|
|
|
|
|
How to initialize a string.. so that it can hold any size..
char str[100] i dont want to do this way...str[] should be able to support as many characters as input by user..
|
|
|
|
|
Use a std::string instead (from the Standard Template Library).
|
|
|
|
|
are you coding in C or C++ ?
|
|
|
|
|
i m coding in C..so cannot use STL.
|
|
|
|
|
document yourself about linked lists. they can be performed using C structures, and a set of pointers...
otherwise, you have to allocate/reallocate/free blocks of memory as you need...
|
|
|
|
|
You can use pointers if you know that.
|
|
|
|
|
Ask user approx how many char(s) his string will be. the allocate memory to a char pointer with the size specified.
char * str;
str = (char *)malloc(size);
|
|
|
|
|
Can we do it without asking the user??? Is any other Way?
|
|
|
|
|
uhhh, where is the user asked ? your program allocates memory without asking AFAIK !
|
|
|
|
|
dona jain wrote: Is any other Way?
What are you trying to achieve?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
char str[100]
i dont want it this way ..i want that all the characters which a user give i/p can be allocated memory...that means we dont know yhe exact array size
|
|
|
|
|
Do you get them blockwise or char by char?
For blocks, a linked list of blocksized buffers would be the way to go.
For single chars, you could assemble blocks by yourself (get chars until you have, say, 512 and then add this buffer to your linked list and make a new buffer of size 512).
Note that there must be any amount of ready-made solutions for that on *specialized C-Programming pages*. Not in the C++/MFC forum of Codeproject.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
dona jain wrote: Can we do it without asking the user??? Is any other Way?
Yes. Assign each character that the user types to a char variable. Dynamically grow an array and append the char to it each time. Note that this reeks of inefficiency.
Why don't you tell us what you are ultimately trying to achieve so that we may possibly offer a better solution?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hi masters
i have made an application in vc++ using dialog based
i have a button so i want when i click this it ask for some system ip address
and when i enter ip address and click then it connect to that system
and a window appwar for chat between those two systems
please guide me
thanks
|
|
|
|
|
p_ wrote: urgent please
What do you think where you are here?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
sorry for that
i think my view goes in wrong direction
|
|
|
|
|
|
thanks for this sir
but i want it through coding in vc++
thanks
|
|
|
|