| | |
Problems with changing values returned by RegQueryValueEx
![]() |
•
•
Join Date: Jun 2005
Posts: 11
Reputation:
Solved Threads: 0
I desperately need help on data type conversions. I am working on converting a set of codes in Visual Basic to C but i'm faced with a lot of problems dealing with strings. Can anyone help me out here? Below is the code I have in Visual Basic.
C Syntax (Toggle Plain Text)
Private Function RegGetStringValue(ByVal hKey As Long, _ ByVal sValue As String, _ dwDataSize As Long) As String Dim sDataRet As String Dim dwDataRet As Long Dim success As Long Dim pos As Long 'returns number of spaces based on dwDataSize sDataRet = Space$(dwDataSize) 'get the size of the null terminating char dwDataRet = Len(sDataRet) success = RegQueryValueEx(hKey, sValue, _ ByVal 0&, dwDataSize, _ ByVal sDataRet, dwDataRet) If success = ERROR_SUCCESS Then If dwDataRet > 0 Then pos = InStr(sDataRet, Chr$(0)) RegGetStringValue = Left$(sDataRet, pos - 1) End If End If End Function
•
•
Join Date: Jun 2005
Posts: 11
Reputation:
Solved Threads: 0
<< moderator edit: merged threads >>
I manage to get the value from the registry with the function below but its in LPBYTE. I need to change the value to an int format so that i can perform arithmetic processes on it. I tried type casting it using a DWORD pointer(in this case, the pointer name is Test), but it returned rubbish values, which was not the value from the registry. Can anyone please help?
I manage to get the value from the registry with the function below but its in LPBYTE. I need to change the value to an int format so that i can perform arithmetic processes on it. I tried type casting it using a DWORD pointer(in this case, the pointer name is Test), but it returned rubbish values, which was not the value from the registry. Can anyone please help?
C Syntax (Toggle Plain Text)
DWORD RegGetStringValue(HKEY hKey,LPTSTR sValue,DWORD* dwDataSize) { BYTE *DataRet=(BYTE*)malloc(sizeof(*dwDataSize)); DWORD *DataRetSize=(DWORD*)malloc(sizeof(DWORD*)); long success; DWORD* Test=(DWORD*)malloc(sizeof(DWORD*)); success = RegQueryValueEx(hKey,(LPCTSTR)sValue,NULL,NULL,DataRet,DataRetSize); Test = (DWORD*)DataRet; //Tried type casting, but returns rubbish values if(success == ERROR_SUCCESS) return (DWORD)*DataRet; }
I had been messing with this a bit from the original, but I wasn't exactly sure of what it was the VB was doing. Could you provide an example of what the function is intended to do? Something along the lines of...
More information will make the question easier to answer correctly.
•
•
•
•
[Background information about function usage.]
The functionis used to retrieve a string from the registry. The example on MSDN is not sufficient because [...].C Syntax (Toggle Plain Text)
DWORD RegGetStringValue(HKEY hKey,LPTSTR sValue,DWORD* dwDataSize)
I have already done a [...] to get the hKey that is passed to this function. An example value would be [...]. The sValue is where the string will go, and dwDataSize is a pointer to a variable containing its maximum length.
I realize that the calling code must free() the pointer returned by this function. An example usage would be like this./* setup code */ retval = RegGetStringValue(hKey, "", 1); /* cleanup code */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Want to get more space and remove HP recovery partition (Windows NT / 2000 / XP)
- Functions and Array help (C++)
- tweaking my amd 64 (Motherboards, CPUs and RAM)
- msi gefroce fx5900xt and gefroce4 mx problems HELP~ (Windows NT / 2000 / XP)
- The improtance of replacing values in pointers (C)
- Any chance of a little help? (Java)
- Random Restarts (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: how to reverse link list using recurtion
- Next Thread: Image Not Showing
| Thread Tools | Search this Thread |
#include * adobe ansi api array asterisks binarysearch centimeter changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork frequency function getlasterror getlogicaldrivestrin givemetehcodez global grade graphics gtkgcurlcompiling gtkwinlinux hacking highest histogram include incrementoperators infiniteloop input interest kernel keyboard kilometer linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft mqqueue number odf opendocumentformat owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape single socket socketprograming standard string systemcall threads turboc unix user voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






