Click here to Skip to main content
16,007,885 members
Home / Discussions / C#
   

C#

 
GeneralClass question Pin
nc3b30-Jul-05 0:02
nc3b30-Jul-05 0:02 
GeneralRe: Class question Pin
User 665830-Jul-05 0:11
User 665830-Jul-05 0:11 
GeneralRe: Class question Pin
nc3b30-Jul-05 0:14
nc3b30-Jul-05 0:14 
GeneralRe: Class question Pin
User 665830-Jul-05 0:26
User 665830-Jul-05 0:26 
GeneralRe: Class question Pin
nc3b30-Jul-05 1:06
nc3b30-Jul-05 1:06 
GeneralKeycodeV2.dll ?- Error Pin
Virendrak29-Jul-05 23:13
Virendrak29-Jul-05 23:13 
GeneralRe: KeycodeV2.dll ?- Error Pin
Michael P Butler30-Jul-05 1:52
Michael P Butler30-Jul-05 1:52 
GeneralUsing API RegQueryValueEx with DllImport to read data from Registry Pin
rahul_iacsd29-Jul-05 19:41
rahul_iacsd29-Jul-05 19:41 
Hello,

I'm trying to read registry value using the API functions RegOpenKeyEx and RegQueryValueEx along with DllImport in C#(I'm aware of C# inbuilt registry access but I need to do it in this way). The results show that code runs fine but I'm not getting the desired data. Its returns 0 instead of the data. I'm including the code that I'm using

//*** declarations in the class *****

public static readonly UIntPtr HkeyLocalMachine = (UIntPtr)0x80000002;<br />
<br />
public const string lpSubKey = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";<br />
<br />
public const int KEY_QUERY_VALUE = 0x1;<br />
public const int REZ_SZ =0x00000002;<br />
<br />
[DllImport("advapi32.dll",EntryPoint="RegOpenKeyEx")]<br />
public static extern int RegOpenKeyEx_DllImport(UIntPtr hKey,string lpSubKey,uint ulOptions,int samDesired,out IntPtr phkResult);<br />
<br />
[DllImport("advapi32.dll",EntryPoint="RegQueryValueEx")]<br />
public static extern int RegQueryValueEx_DllImport(IntPtr hKey,string lpValueName,int lpReserved,out uint lpType, IntPtr lpData,out uint lpcbData);<br />
<br />
//****** declared on load or click event ****<br />
<br />
IntPtr hKeyVal;<br />
uint lpType;<br />
uint lpcbData;<br />
IntPtr q=new IntPtr();<br />
<br />
int valueRet=RegOpenKeyEx_DllImport(HkeyLocalMachine,lpSubKey,0,KEY_QUERY_VALUE,out hKeyVal);<br />
<br />
valueRet=RegQueryValueEx_DllImport(hKeyVal,"ProcessorNameString",0,out lpType, q,out lpcbData);

Output when viewd using different variables :

lpType= returns 1 which signify a string value
q returns 0 *** this should return data but does not
lpcbData returns 48 signifying size of the data being returned.

The return values of the functions show 0 which means success

Any help or insight on "Why I'm unable to get the data" would be highly appreciated.

Thanks
Rahul Sharma
GeneralRe: Using API RegQueryValueEx with DllImport to read data from Registry Pin
rahul_iacsd31-Jul-05 19:14
rahul_iacsd31-Jul-05 19:14 
GeneralRe: Using API RegQueryValueEx with DllImport to read data from Registry Pin
najmu24-Sep-09 7:53
najmu24-Sep-09 7:53 
Generalthread pool Pin
ppp00129-Jul-05 19:19
ppp00129-Jul-05 19:19 
GeneralRe: thread pool Pin
S. Senthil Kumar29-Jul-05 21:02
S. Senthil Kumar29-Jul-05 21:02 
GeneralRe: thread pool Pin
ppp00131-Jul-05 15:45
ppp00131-Jul-05 15:45 
GeneralRe: thread pool Pin
S. Senthil Kumar31-Jul-05 19:31
S. Senthil Kumar31-Jul-05 19:31 
GeneralInstalltion Problem Pin
ksanju100029-Jul-05 18:14
ksanju100029-Jul-05 18:14 
GeneraldataSet Problem Pin
ksanju100029-Jul-05 18:09
ksanju100029-Jul-05 18:09 
GeneralDataSet with DateTime Problem with MySql Pin
ksanju100029-Jul-05 18:06
ksanju100029-Jul-05 18:06 
QuestionHow can I.. Pin
KORCARI29-Jul-05 17:58
KORCARI29-Jul-05 17:58 
AnswerRe: How can I.. Pin
JSBALOCH29-Jul-05 23:33
JSBALOCH29-Jul-05 23:33 
AnswerRe: How can I.. Pin
tatchung30-Jul-05 7:24
tatchung30-Jul-05 7:24 
GeneralListView GridLines Don't line up Pin
Dominic Farr29-Jul-05 15:39
Dominic Farr29-Jul-05 15:39 
Questionhow do I make a very basic graphics app Pin
Member 209158729-Jul-05 15:31
Member 209158729-Jul-05 15:31 
AnswerRe: how do I make a very basic graphics app Pin
Robert Rohde29-Jul-05 19:49
Robert Rohde29-Jul-05 19:49 
GeneralASP.NET big problem Pin
brunoconde29-Jul-05 12:39
brunoconde29-Jul-05 12:39 
GeneralThreadsafe Generic Dictionary Pin
Werdna29-Jul-05 12:18
Werdna29-Jul-05 12:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.