none
RETAILMSG displays:- ERROR in reading registry value RRS feed

  • Question

  • Hello Freinds

    Below is my code in TST_Init() .. 

    I am trying to read the registry values from the key passed in  the first parameter of TST_Init()... but it displaying an error in PB Console as RETAILMSG displays:- ERROR in reading registry value .... I am following the mentioned link 

    http://geekswithblogs.net/BruceEitman/archive/2010/08/01/windows-ce-using-a-driver-to-readwrite-hardware-registers.aspx

    In this document I have no idea about DeviceArrayIndex. I have replaced it with the name of my registery folder name as shown below --

    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Test]
    "Prefix"="TST"
    "Dll"="Test1.dll"
    "Index"=dword:1
    "Order"=dword:10

    result = RegQueryValueEx(hKey, TEXT("Test"), NULL, &Type, (LPBYTE)&Data, &DataSize);
    				if(ERROR_SUCCESS == result)
    				{
    					RETAILMSG(TRUE,(TEXT("TEST_Init(): Registry values read successfully.\r\n"))); 
    					pDriverContext->Instance = Data;
    
    					RETAILMSG(TRUE, (TEXT("TEST_Init(): Registery value is -- %d"),pDriverContext->Instance));
    					RegCloseKey(hKey);
    
    				}
    				else
    				{
    					RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in reading registry values.\r\n")));
    					return FALSE;
    					exit;
    				}

    If any one knows, how to solve then please help me for this ???

    Monday, March 24, 2014 12:26 PM

Answers

  • The value received from calling GetLastError() is?

    Are you still opening the registry key using hKey = OpenDeviceKey((LPCTSTR)RegistryPath);?

    Never mind, you are calling RegQUeryValueEx wrong.   "Test" is a KEY name, not a value name, and from what you show there is no value name "Test".  (Hint:  Prefix, Dll, Index and Order are the only value names that you show)


    Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurotech DOT com My BLOG http://geekswithblogs.net/bruceeitman Eurotech Inc. www.Eurotech.com

    Monday, March 24, 2014 3:12 PM
    Moderator
  • Still its giving the same error -

    This is my new code with modification as you mentioned in the previous reply 

    DWORD TST_Init(
      LPCTSTR regPath,
      DWORD dwBusContext
    )
    {
    	HKEY	hKey;
    	DWORD	result;
    	/////*DWORD Type	=	REG_DWORD;
    	////DWORD Data;
    	////DWORD DataSize	=	sizeof(DWORD);*/
    	DWORD Type;
    
    DWORD cbValue = sizeof(DWORD);
    UCHAR RegDataCompare[4]={0};
    
    DWORD Data=0;
    	DRIVERSHELL_CONTEXT *pDriverContext;
    
    
    	RETAILMSG(TRUE,(TEXT("TST_Init(): START\r\n")));
    
    		////pDriverContext = LocalAlloc(LMEM_FIXED, sizeof(DRIVERSHELL_CONTEXT));
    		pDriverContext = (DRIVERSHELL_CONTEXT *)LocalAlloc(LMEM_FIXED, sizeof(DRIVERSHELL_CONTEXT));
    		if(!pDriverContext == NULL)
    		{
    			hKey = OpenDeviceKey((LPCTSTR)regPath);// This fxn opens the device registery key,
    				
    			if(!hKey)
    			{
    				RETAILMSG(TRUE,(TEXT("TEST_Init(): Failed to open registery\r\n")));
    				return FALSE;
    				exit;
    			}
    			else
    			{
    				RETAILMSG(TRUE,(TEXT("TEST_Init(): Registery key open successfully\r\n")));
    
    				//result = RegQueryValueEx(hKey, TEXT("Index"), NULL, &Type, (LPBYTE)&Data, &DataSize);
    				result = RegQueryValueEx(hKey,TEXT("Index"),NULL,&Type,\
    						(PBYTE)RegDataCompare,&cbValue);
    					memcpy(&Data,RegDataCompare,sizeof(DWORD));
    				if(result == ERROR_SUCCESS)
    				{
    					RETAILMSG(TRUE,(TEXT("TEST_Init(): Registry values read successfully.\r\n"))); 
    					pDriverContext->Instance = Data;
    
    					RETAILMSG(TRUE, (TEXT("TEST_Init(): Registery value is -- %d"),pDriverContext->Instance));
    					RegCloseKey(hKey);
    
    				}
    				else
    				{
    					RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in reading registry values.\r\n")));
    					return FALSE;
    					exit;
    				}
    			}								// with pointer to the registery
    		}
    		else
    		{
    			RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in allocating memory.\r\n")));
    			return FALSE;
    			exit;
    		}
    
    	
    	
    	RETAILMSG(TRUE,(TEXT("TST_Init(): END\r\n")));
    	return TRUE;
    
    }

    Tuesday, March 25, 2014 6:34 AM

All replies

  • The first parameter you receive in TST_Init() function is a string that containg the path of the active key related to the driver and created by Device Manager on system boot. It is a "number" key under :

    HKEY_LOCAL_MACHINE\Drivers\Active

    For example the string passed as first parameter to yout TST_Init() function is "HKEY_LOCAL_MACHINE\Drivers\Active\56"

    Opening this key, you can find a string value named "Key" that is the registry path to your driver information. In your case it is :

    HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Test

    For example "Key" value under "HKEY_LOCAL_MACHINE\Drivers\Active\56" is "HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Test"

    Opening the above key you can find all your driver information (Index, Order, Dll and other parameters you set inside the registry).

    More info here : http://geekswithblogs.net/BruceEitman/archive/2009/04/12/windows-ce-opening-driver-registry-key.aspx

    Paolo



    Paolo Patierno

    Monday, March 24, 2014 2:35 PM
  • The value received from calling GetLastError() is?

    Are you still opening the registry key using hKey = OpenDeviceKey((LPCTSTR)RegistryPath);?

    Never mind, you are calling RegQUeryValueEx wrong.   "Test" is a KEY name, not a value name, and from what you show there is no value name "Test".  (Hint:  Prefix, Dll, Index and Order are the only value names that you show)


    Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurotech DOT com My BLOG http://geekswithblogs.net/bruceeitman Eurotech Inc. www.Eurotech.com

    Monday, March 24, 2014 3:12 PM
    Moderator
  • Yes,

    I have opened the registry key using

    HKEY hKey = OpenDeviceKey((LPCTSTR)regPath);// This fxn opens the device registery key,

    and also checking the status of hKey value in if condition as shown below:-

    if(!hKey)
    			{
    				RETAILMSG(TRUE,(TEXT("TEST_Init(): Failed to open registery\r\n")));
    				return FALSE;
    				exit;
    			}
    else
    {
    	RETAILMSG(TRUE,(TEXT("TEST_Init(): Registery key open successfully\r\n")));
    
    	result = RegQueryValueEx(hKey, TEXT("Index"), NULL, &Type, (LPBYTE)&Data, &DataSize);
    	if(result == ERROR_SUCCESS)
    	{
    		RETAILMSG(TRUE,(TEXT("TEST_Init(): Registry values read successfully.\r\n"))); 
    		pDriverContext->Instance = Data;
    
    		RETAILMSG(TRUE, (TEXT("TEST_Init(): Registery value is -- %d"),pDriverContext->Instance));
    		RegCloseKey(hKey);
    
    	}
    	else
    	{
    		RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in reading registry values.\r\n")));
    		return FALSE;
    		exit;
    	}
    }								// with pointer to the registery
    		

    I have replaced the value of text with Index, that I am using in the registry of TEST driver

    Still getting the same error???



    Tuesday, March 25, 2014 5:09 AM
  • Try like this ....

    DWORD Type;

    DWORD cbValue = sizeof(DWORD);
    UCHAR RegDataCompare[4]={0};

    DWORD Data=0;

    RegQueryValueEx(hKey,TEXT("Index"),NULL,&Type,\
    (PBYTE)RegDataCompare,&cbValue);

    memcpy(&Data,RegDataCompare,sizeof(DWORD));

    --- Misbah


    Senior Design Engineer T.E.S Electroni Solutions (Bangalore-India) www.tes-dst.com email-misbah.khan@tes-dst.com


    • Edited by Misbah Khan Tuesday, March 25, 2014 6:07 AM
    Tuesday, March 25, 2014 6:01 AM
  • Still its giving the same error -

    This is my new code with modification as you mentioned in the previous reply 

    DWORD TST_Init(
      LPCTSTR regPath,
      DWORD dwBusContext
    )
    {
    	HKEY	hKey;
    	DWORD	result;
    	/////*DWORD Type	=	REG_DWORD;
    	////DWORD Data;
    	////DWORD DataSize	=	sizeof(DWORD);*/
    	DWORD Type;
    
    DWORD cbValue = sizeof(DWORD);
    UCHAR RegDataCompare[4]={0};
    
    DWORD Data=0;
    	DRIVERSHELL_CONTEXT *pDriverContext;
    
    
    	RETAILMSG(TRUE,(TEXT("TST_Init(): START\r\n")));
    
    		////pDriverContext = LocalAlloc(LMEM_FIXED, sizeof(DRIVERSHELL_CONTEXT));
    		pDriverContext = (DRIVERSHELL_CONTEXT *)LocalAlloc(LMEM_FIXED, sizeof(DRIVERSHELL_CONTEXT));
    		if(!pDriverContext == NULL)
    		{
    			hKey = OpenDeviceKey((LPCTSTR)regPath);// This fxn opens the device registery key,
    				
    			if(!hKey)
    			{
    				RETAILMSG(TRUE,(TEXT("TEST_Init(): Failed to open registery\r\n")));
    				return FALSE;
    				exit;
    			}
    			else
    			{
    				RETAILMSG(TRUE,(TEXT("TEST_Init(): Registery key open successfully\r\n")));
    
    				//result = RegQueryValueEx(hKey, TEXT("Index"), NULL, &Type, (LPBYTE)&Data, &DataSize);
    				result = RegQueryValueEx(hKey,TEXT("Index"),NULL,&Type,\
    						(PBYTE)RegDataCompare,&cbValue);
    					memcpy(&Data,RegDataCompare,sizeof(DWORD));
    				if(result == ERROR_SUCCESS)
    				{
    					RETAILMSG(TRUE,(TEXT("TEST_Init(): Registry values read successfully.\r\n"))); 
    					pDriverContext->Instance = Data;
    
    					RETAILMSG(TRUE, (TEXT("TEST_Init(): Registery value is -- %d"),pDriverContext->Instance));
    					RegCloseKey(hKey);
    
    				}
    				else
    				{
    					RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in reading registry values.\r\n")));
    					return FALSE;
    					exit;
    				}
    			}								// with pointer to the registery
    		}
    		else
    		{
    			RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in allocating memory.\r\n")));
    			return FALSE;
    			exit;
    		}
    
    	
    	
    	RETAILMSG(TRUE,(TEXT("TST_Init(): END\r\n")));
    	return TRUE;
    
    }

    Tuesday, March 25, 2014 6:34 AM
  • Can you print the error value using GetLastError() ?

    You can try passing NULL in place of this variable (Type ) address as :

    result = RegQueryValueEx(hKey,TEXT("Index"),NULL,NULL,\
    						(PBYTE)RegDataCompare,&cbValue);

    if(result == ERROR_SUCCESS) { RETAILMSG(TRUE,(TEXT("TEST_Init(): Registry values read successfully.\r\n")));

    memcpy(&Data,RegDataCompare,sizeof(DWORD));

    pDriverContext->Instance = Data; RETAILMSG(TRUE, (TEXT("TEST_Init(): Registery value is -- %d"),pDriverContext->Instance)); RegCloseKey(hKey); } else { RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in reading registry values Error = %d \r\n"),GetLastError())); return FALSE; }

    --- Misbah


    Senior Design Engineer T.E.S Electroni Solutions (Bangalore-India) www.tes-dst.com email-misbah.khan@tes-dst.com




    Tuesday, March 25, 2014 6:37 AM
  • OKay fine, It will take some time bcz my system is on full building stage...
    Tuesday, March 25, 2014 6:38 AM
  • Ya, its working fine.

    I did not build fully thats why it was using the same code.. Now, your method and my method both are working fine. But, the problem is that I am trying to read Order value by passing in TEXT("Order") and in retail messages it is displaying as 16 instead of displaying 10 as I am using the following entries for my driver in .reg file

    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Test]
    	"Prefix"="TST"
    	"Dll"="Test.dll"
    	"Index"=dword:1
    	"Order"=dword:10
    	

    But for index it is displaying 1 that is accurate....

    and for Order it is displaying 16 that is not accurate ????????????????????????


    Tuesday, March 25, 2014 9:54 AM
  • The values in .reg file follows hex format hence hex 10 is decimal 16 which is correctly printed.

    --- Misbah


    Senior Design Engineer T.E.S Electroni Solutions (Bangalore-India) www.tes-dst.com email-misbah.khan@tes-dst.com

    Tuesday, March 25, 2014 11:37 AM
  • Okay, now the problem solved but one more problem for reading the string value ?????

    I am working on it still getting exceptions if it is done then fine otherwise i will share my code what i have done to read string values?????

    Tuesday, March 25, 2014 11:43 AM
  • So what was the problem?

    Reading strings from the registry:  http://geekswithblogs.net/BruceEitman/archive/2008/06/11/windows-ce-reading-a-string-from-the-registry.aspx


    Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurotech DOT com My BLOG http://geekswithblogs.net/bruceeitman Eurotech Inc. www.Eurotech.com

    Tuesday, March 25, 2014 12:17 PM
    Moderator
  • Now, according to little bit modification in the code, I am able to display string values. But in my reg one text is as Dll that contains "Test.dll"

    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Test]
    	"Prefix"="TST"
    	"Dll"="Test.dll"
    	"Index"=dword:1
    	"Order"=dword:10


    for displaying the value the same string code is displaying error.

    my modified code is as:

    HKEY	hKey;
    	DWORD	result;
    	//DWORD Type	=	REG_DWORD;
    	DWORD Type = REG_SZ;
    	TCHAR *MemAlloc = NULL;
    	DWORD Data;
    	DWORD NoBytes;
    	DWORD DataSize	=	sizeof(DWORD);
    	DWORD lcl_error;
    ////	DWORD Type;
    ////
    ////
    ////DWORD cbValue = sizeof(DWORD);
    ////UCHAR RegDataCompare[4]={0};
    ////
    ////DWORD Data=0;
    	DRIVERSHELL_CONTEXT *pDriverContext;
    
    
    	RETAILMSG(TRUE,(TEXT("TST_Init(): START\r\n")));
    
    		////pDriverContext = LocalAlloc(LMEM_FIXED, sizeof(DRIVERSHELL_CONTEXT));
    		pDriverContext = (DRIVERSHELL_CONTEXT *)LocalAlloc(LMEM_FIXED, sizeof(DRIVERSHELL_CONTEXT));
    		if(!pDriverContext == NULL)
    		{
    			hKey = OpenDeviceKey((LPCTSTR)regPath);// This fxn opens the device registery key,
    				
    			if(!hKey)
    			{
    				RETAILMSG(TRUE,(TEXT("TEST_Init(): Failed to open registery\r\n")));
    				return FALSE;
    				exit;
    			}
    			else
    			{
    				RETAILMSG(TRUE,(TEXT("TEST_Init(): Registery key open successfully\r\n")));
    				//result = RegQueryValueEx(hKey, TEXT("Index"), NULL, &Type, (LPBYTE)&Data, &DataSize);
    
    
    				result = RegQueryValueEx(hKey, TEXT("Prefix"), NULL, &Type, NULL, &NoBytes);
    
    				if(NoBytes > 0)
    				{
    					MemAlloc = (TCHAR *)malloc(NoBytes);
    					if(MemAlloc != NULL)
    					{
    						result = RegQueryValueEx(hKey, TEXT("Dll"), NULL, &Type, LPBYTE(MemAlloc), &NoBytes);
    						if(result == ERROR_SUCCESS)
    						{
    							RETAILMSG(TRUE,(TEXT("TEST_Init(): Registry values read successfully.\r\n"))); 
    							pDriverContext->StrngVal = MemAlloc;
    
    							RETAILMSG(TRUE, (TEXT("TEST_Init(): Registery value is -- %s"),pDriverContext->StrngVal));
    							RegCloseKey(hKey);
    
    						}
    						else
    						{
    							lcl_error = GetLastError();
    							RETAILMSG(TRUE,(TEXT("TEST_Init(): -- %d --%s \r\n"),lcl_error, lcl_error));
    							RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in reading registry values.\r\n")));
    							return FALSE;
    							exit;
    						}
    
    					}
    					else
    					{
    						RETAILMSG(TRUE,(TEXT("TEST_Init(): Failed to allocate memory to bytes\r\n")));
    						exit;
    					}
    				}
    					
    				///*result = RegQueryValueEx(hKey, TEXT("Order"), NULL, &Type, (LPBYTE)&Data, &DataSize);*/
    				///*/*result = RegQueryValueEx(hKey,TEXT("Dll"),NULL,&Type,\
    				//		(PBYTE)RegDataCompare,&cbValue);*/*/
    				///*result = RegQueryValueEx(hKey,TEXT("Order"),NULL,NULL,\
    				//		(PBYTE)RegDataCompare,&cbValue);*/
    					//memcpy(&Data,RegDataCompare,sizeof(DWORD));
    							}								// with pointer to the registery
    		}
    		else
    		{
    			RETAILMSG(TRUE,(TEXT("TEST_Init(): Error in allocating memory.\r\n")));
    			return FALSE;
    			exit;
    		}
    
    	
    	
    	RETAILMSG(TRUE,(TEXT("TST_Init(): END\r\n")));
    	return TRUE;

    and the header file modification is as:-

    typedef struct _DRIVERSHELL_CONTEXT
    {
                    DWORD Instance;
    				TCHAR *StrngVal;
                    
    } DRIVERSHELL_CONTEXT;

    Retail message error as:

    8210 PID:400002 TID:aa0006 TEST_Init(): Registery key open successfully
       8211 PID:400002 TID:aa0006 Exception 'Data Abort' (0x4): Thread-Id=00aa0006(pth=9e406ad8), Proc-Id=00400002(pprc=826ef700) 'NK.EXE', VM-active=02040002(pprc=9e41d220) 'udevice.exe'
       8212 PID:400002 TID:aa0006 PC=8003c12c(kernel.dll+0x0000d12c) RA=8005f21c(kernel.dll+0x0003021c) SP=a8afeed0, BVA=00000057
       8213 PID:400002 TID:aa0006 Exception 'Raised Exception' (0x116): Thread-Id=00aa0006(pth=9e406ad8), Proc-Id=00400002(pprc=826ef700) 'NK.EXE', VM-active=02040002(pprc=9e41d220) 'udevice.exe'
       8213 PID:400002 TID:aa0006 PC=eff6eef8(k.coredll.dll+0x0001eef8) RA=800442ac(kernel.dll+0x000152ac) SP=a8afe5ec, BVA=ffffffff
    Mr. Bruce Eitman, I have read this link that why I am able to display string value. But unable to display abc.xyx type of values?????
    Tuesday, March 25, 2014 12:22 PM
  • It would be better to start a new thread to discuss this new topic - reading strings from the registry.

    Huh?  That code doesn't "display string value", it reads a string from the registry.

    Are you really asking us to debug your code before you do any debugging?  I know that you didn't because the problem is so obvious, and the code that you started with worked, I use it quite often myself.

    The problem is that you are using hard coded strings in the code, but not consistently using the same string for the same purpose.  You find the string length of the shortest string in your registry key, then allocate space for the shortest string, then read the longest string - no surprise that you have a data abort.

    So, I will ask again, what was the solution to your original problem?


    Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurotech DOT com My BLOG http://geekswithblogs.net/bruceeitman Eurotech Inc. www.Eurotech.com

    Tuesday, March 25, 2014 12:49 PM
    Moderator
  • No Sir, its not like that What you were thinking. 

    This code is perfectly displaying string values for me. I have tested it for Prefix that contains TST value and in my PB Console it displayed TST. Okay, tomorrow i will start new thread for this... No issue regarding this...It time to leave from office so catch you tomorrow. Good day to every one

    Tuesday, March 25, 2014 12:55 PM
  • Well, that code will most likely Data Abort when it reads the string from the registry.  It does that, as you showed, because of the reason that I stated.  

    Further, it does this because you did not correctly change the code from reading "Prefix" to reading "Dll".

    And another thing, your statement that it correctly reads "Prefix" proves my point.

    So, I will ask again, what was the solution to your original problem?  Why do I have to ask so often?


    Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurotech DOT com My BLOG http://geekswithblogs.net/bruceeitman Eurotech Inc. www.Eurotech.com

    Tuesday, March 25, 2014 2:28 PM
    Moderator
  • Hello Sir,

    I did not get your point. You are asking for which original problem ; current thread problem or read the string value with "." problem.

    If you are asking about current problem then the solution of current thread is given by Mr. Misabh as

    result = RegQueryValueEx(hKey,TEXT("Index"),NULL,NULL,\
    						(PBYTE)RegDataCompare,&cbValue);

    I did not build the project as Clean Sysgen after his solution thats why i was facing the same type of problem.. But after building the project using clean sysgen the problem was resolved ????????

    Wednesday, March 26, 2014 2:49 AM
  • That is what I thought.  I gave you the solution to the original problem last Wednesday.  Then I gave you the solution to the current problem on Tuesday, but since you boldly told me that it was "not like What you were thinking" there was not much that we could for you.

    You should start a thread to discuss your build problem.  you are doing something wrong if you needed to do a clean sysgen.


    Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurotech DOT com My BLOG http://geekswithblogs.net/bruceeitman Eurotech Inc. www.Eurotech.com

    Thursday, March 27, 2014 9:38 AM
    Moderator
  • Hello Sir,

    No, Sir i was replying for this "Are you really asking us to debug your code before you do any debugging?"'

    Don't mistook me for this...... Seriously I checked and it was not working for me because we are doing lot of things together and i clicked on full build and after some time i cancel it and again build and used the image so it was not working I only said the truth.. And i also created the new thread for string value........

    Thursday, March 27, 2014 9:49 AM