iam porting a c++ software to c#
iam reading a registry key in c++ my code is
if(::RegOpenKeyEx(hParentKey, (LPCTSTR) strKeyName2,NULL,KEY_READ , &hKey)==ERROR_SUCCESS)
{
lRet = RegQueryValueEx(hKey, key, NULL, &type,(LPBYTE)data,&dataLen);
}
in c# my code is
iam getting different output from c# code while reading a binary data from registry
how can i solve this problem ?
What I have tried:
public static readonly UIntPtr HKEY_CURRENT_USER = (UIntPtr)0x80000001;
public const string lpSubKey = "Software\\Scooter Software\\Beyond Compare 3";
public const int KEY_QUERY_VALUE = 0x1;
[DllImport("advapi32.dll", EntryPoint = "RegOpenKeyEx")]
public static extern int RegOpenKeyEx(UIntPtr hKey, string lpSubKey, uint ulOptions, int samDesired, out UIntPtr phkResult);
[DllImport("advapi32.dll", EntryPoint = "RegQueryValueEx", CharSet = CharSet.Auto)]
public static extern int RegQueryValueEx(UIntPtr hKey, string lpValueName, int lpReserved, out uint lpType, StringBuilder lpData, ref int lpcbData);
UIntPtr hKeyVal;
int valueRet;
uint lpType;
StringBuilder sb = new StringBuilder(1000);
int lpcbData = sb.Capacity;
valueRet = RegOpenKeyEx(HKEY_CURRENT_USER, lpSubKey, 0, KEY_QUERY_VALUE, out hKeyVal);
valueRet = RegQueryValueEx(hKeyVal, "CacheID", 0, out lpType, sb, ref lpcbData);
MessageBox.Show(string.Format("data type :{0}\n,data size :{1}\n,data :{2}\n", lpType.ToString(), lpcbData.ToString(), sb.ToString()), "Value", MessageBoxButtons.OK);