We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

How do i add wchar_t?

Medium Priority
1,322 Views
Last Modified: 2013-11-15
Hello
I wrote a sample code in VS.NET 2003 to set registry key. Please find the attached file(main.doc ),
In this code I want to change main.doc file:
1)  datatype of object  msiLocation from char to wchar_t (Line #105)
2) 6th argument in regsetvalueex() function has to be modified.(Line#114,140)
3) #define MACROS to be set to wide characters.(Line# 5-10).



For this change in main.doc  I would like to know:
1) What header files to include to support wchar_t?
2) projects settings to be done in this regard.
3) code change in attached file main.doc  to support wchar_t datatype.


Regards
Sham


main.doc
Comment
Watch Question

>>>> 1) What header files to include to support wchar_t?
It is a basic type for most compilers. No need to include extra headers.
>>>> 2) projects settings to be done in this regard.
project settings only need to be changed if you want to have all strings automatically changed to wide chars and use the Visual Studio. Then you scan set the project settings to use UNICODE (set preprocessor macro _UNICODE) and have to use types TCHAR, LPTSTR, LPCTSTR, ... and functions like _tcscpy to copy char arrays  and macro _T for literals to get it done automatically .
 
>>>> code change in attached file main.doc  to support wchar_t datatype
Can you post the code in the 'Attach Code Snippet'. Unfortunately I can't download .doc files at my current place.
Subrat (C++ windows/Linux)Software Engineer
CERTIFIED EXPERT

Commented:
you may use
#include "wchar.h"

I'm unable to see your code.Better you copy-paste the code here.But my guess is.....

In your program instead of using printf() use wprintf().I don't know what functions u r using.You use wide char version of that function where needed.

Also replace all the strings with L".......", i.e write L before the wide char string.This may solve your problem.

To get wide char version of your function you can see MSDN...

Author

Commented:
Hello

Please find the attached code snippet.


#include <stdio.h>
#include <windows.h>
 
void set_mediapkgpath();
#define MSI_SOURCE_BASE_KEY			"SOFTWARE\\Classes\\Installer\\Products"
#define WVSevProp_MSI		"WVSevProp"
#define MSI_SOURCE_KEY		"SourceList"
#define MSI_MEDIA_KEY		"Media"
#define MSI_MEDIA_PACKAGE_VAL		"MediaPackage"
#define MSI_PRODUCT_NAME_KEY	"ProductName"
 
int main(void)
{
	
	set_mediapkgpath();
 
   
	return 0;
}
 
 
 
 
 
 
void set_mediapkgpath()
{
       HKEY   hkey;
       LONG   ccode;
       BOOL   validSourceFound = FALSE;
       REGSAM  samRedirect = 0;
		
 
    // Open the installer products key.
       if ((ccode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MSI_SOURCE_BASE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS)
       {
		   
		   
			samRedirect |= KEY_WOW64_64KEY;
			if ((ccode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MSI_SOURCE_BASE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS)
			{
			   
				
			}  
			else
			{
                  
				  
			}
		}
		else
		{
              
			  
		}
 
		// Enumerate the key to find our product's key.
		if( ccode == ERROR_SUCCESS )
		{
              TCHAR         enumname[256];
              DWORD         enumnamelen = sizeof( enumname );
              DWORD         index = 0L;
              FILETIME      dummy;
 
              ccode = ERROR_SUCCESS;
              while (ccode == ERROR_SUCCESS)
              {
                     HKEY   hsubkey;
                     TCHAR  prodname[256];
                     DWORD  prodnamelen = sizeof( prodname );
 
                     enumnamelen = sizeof( enumname );
                     ccode = RegEnumKeyEx(hkey, index, enumname, &enumnamelen, NULL, NULL, NULL,  &dummy);
                     if (ccode != ERROR_SUCCESS)
                           break;
                     
					 
                     if ((ccode = RegOpenKeyEx(hkey, enumname, 0, samRedirect | KEY_ALL_ACCESS, &hsubkey) != ERROR_SUCCESS))
                     {
                           
						   
                     }
                     else
                     if ((ccode = RegQueryValueEx(hsubkey, MSI_PRODUCT_NAME_KEY, NULL, NULL, (LPBYTE) prodname, &prodnamelen)) != ERROR_SUCCESS)
                     {
                           
						   
                     }
                     else
                     if (!_tcsicmp(prodname, WVSevProp_MSI))
                     {
                           HKEY   hkeysrclist;
 
                           
						   
                           if ((ccode = RegOpenKeyEx(hsubkey, MSI_SOURCE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkeysrclist) != ERROR_SUCCESS))
                           {//unable to open sourcelist key
                                  
								  
                           }
                           else
                           {//source list key opened
                                  
								  HKEY hkeymedia;
								  char   msiLocation[] = "\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
									
								if ((ccode = RegOpenKeyEx(hkeysrclist, MSI_MEDIA_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkeymedia) == ERROR_SUCCESS))
								{ // media key found
									
 
									
								   
									//Without checking the existence of MediaPackage path string, set MediaPackage to L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp"								  
									if ((ccode = RegSetValueEx( hkeymedia, MSI_MEDIA_PACKAGE_VAL, 0, REG_SZ,(LPBYTE)msiLocation,(DWORD) strlen(msiLocation)+1))  != ERROR_SUCCESS)
									{
											// Failed to set it.
										
											
									}
									else
									{
										
									}
 
									RegCloseKey(hkeymedia);
                                  
                                RegCloseKey(hkeysrclist);
								}
								else
								{// media key not found, create one.
									//Create the media key.
									DWORD dwDisp;
									if ((ccode =RegCreateKeyEx(hkeysrclist, MSI_MEDIA_KEY,0, NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL, &hkeymedia, &dwDisp))!= ERROR_SUCCESS) 
									{
										
 
									}
									else
									{//able to create media key
										if( ( ccode = RegSetValueEx( hkeymedia, MSI_MEDIA_PACKAGE_VAL, 0, REG_SZ,(LPBYTE)msiLocation, (DWORD) (strlen(msiLocation)+1)) ) != ERROR_SUCCESS)
										{
											// Failed to set it.
											
										}
										
									}
 
 
 
								}
						   
						   
						   }
						   break;
                     }
					else
					{
                           
						   
					}
                     index++;
                     RegCloseKey(hsubkey);
              }
              if (ccode != ERROR_NO_MORE_ITEMS && ccode != ERROR_SUCCESS)
              {
				  // not find wvsevprop
					
              }
              RegCloseKey(hkey);
       }
       
 
		return;
}

Open in new window

Author

Commented:
Basically i want to make the following changes in the attached code snippet.
1)  datatype of object  msiLocation from char to wchar_t (Line #105)
2) 6th argument in regsetvalueex() function has to be modified.(Line#114,140)
3) #define MACROS to be set to wide characters.(Line# 5-10).
4) I would like to know, in which scenarios wchar_t will be useful.


Regards
Sham

Author

Commented:
Hello

I my latest update,
2) 5th and 6th argument in regsetvaluex() function has to be modified (Line #114,140)

Author

Commented:
Hello

This is very urgent, please update in next 2-3 hours.

Regards
Sham

Author

Commented:
Hello Moderator

I am not getting response from past 4-5 hours for this question.
Please help me in this regard.

Regards
Sham


Author

Commented:
Hello
Below are my questions with respect to code anippet:
1)  datatype of object  msiLocation from char to wchar_t (Line #105)
2) 5th and 6th argument in regsetvalueex() function has to be modified.(Line#114,140)
3) #define MACROS to be set to wide characters.(Line# 5-10).
4) I would like to know, in which scenarios wchar_t will be useful.
5) What is the difference between TCHAR and wchar_t variable?
6) an example to initialise TCHAR and wchar_t varialbles in declaration.

Regards

Author

Commented:
Hello Moderator

I did not get any reply till now.

Please look into this issue.


Regards
Sham


Subrat (C++ windows/Linux)Software Engineer
CERTIFIED EXPERT

Commented:
Your complete code below...Try it..

#include <stdio.h>
#include <windows.h>

void set_mediapkgpath();
#define MSI_SOURCE_BASE_KEY                     L"SOFTWARE\\Classes\\Installer\\Products"
#define WVSevProp_MSI           L"WVSevProp"
#define MSI_SOURCE_KEY          L"SourceList"
#define MSI_MEDIA_KEY           L"Media"
#define MSI_MEDIA_PACKAGE_VAL           L"MediaPackage"
#define MSI_PRODUCT_NAME_KEY    L"ProductName"



int main(void)
{
       
        set_mediapkgpath();
 
   
        return 0;
}


void set_mediapkgpath()
{
       HKEY   hkey;
       LONG   ccode;
       BOOL   validSourceFound = FALSE;
       REGSAM  samRedirect = 0;
               
 
    // Open the installer products key.
       if ((ccode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MSI_SOURCE_BASE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS)
       {
                   
                   
                        samRedirect |= KEY_WOW64_64KEY;
                        if ((ccode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MSI_SOURCE_BASE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS)
                        {
                           
                               
                        }  
                        else
                        {
                 
                                 
                        }
                }
                else
                {
             
                         
                }
 
                // Enumerate the key to find our product's key.
                if( ccode == ERROR_SUCCESS )
                {
              TCHAR         enumname[256];
              DWORD         enumnamelen = sizeof( enumname );
              DWORD         index = 0L;
              FILETIME      dummy;
 
              ccode = ERROR_SUCCESS;
              while (ccode == ERROR_SUCCESS)
              {
                     HKEY   hsubkey;
                     TCHAR  prodname[256];
                     DWORD  prodnamelen = sizeof( prodname );
 
                     enumnamelen = sizeof( enumname );
                     ccode = RegEnumKeyEx(hkey, index, enumname, &enumnamelen, NULL, NULL, NULL,  &dummy);
                     if (ccode != ERROR_SUCCESS)
                           break;
                     
                                         
                     if ((ccode = RegOpenKeyEx(hkey, enumname, 0, samRedirect | KEY_ALL_ACCESS, &hsubkey) != ERROR_SUCCESS))
                     {
                           
                                                   
                     }
                     else
                     if ((ccode = RegQueryValueEx(hsubkey, MSI_PRODUCT_NAME_KEY, NULL, NULL, (LPBYTE) prodname, &prodnamelen)) != ERROR_SUCCESS)
                     {
                           
                                                   
                     }
                     else
                     if (!_tcsicmp(prodname, WVSevProp_MSI))
                     {
                           HKEY   hkeysrclist;
 
                           
                                                   
                           if ((ccode = RegOpenKeyEx(hsubkey, MSI_SOURCE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkeysrclist) != ERROR_SUCCESS))
                           {//unable to open sourcelist key
                                 
                                                                 
                           }
                           else
                           {//source list key opened
                                 
                                                                  HKEY hkeymedia;
                                                                  wchar_t   msiLocation[] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
                                                                       
                                                                if ((ccode = RegOpenKeyEx(hkeysrclist, MSI_MEDIA_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkeymedia) == ERROR_SUCCESS))
                                                                { // media key found
                                                                       
 
                                                                       
                                                                   
                                                                        //Without checking the existence of MediaPackage path string, set MediaPackage to L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp"                                                            
                                                                        if ((ccode = RegSetValueEx( hkeymedia, MSI_MEDIA_PACKAGE_VAL, 0, REG_SZ,(LPBYTE)msiLocation,(DWORD) wcslen(msiLocation)+1))  != ERROR_SUCCESS)
                                                                        {
                                                                                        // Failed to set it.
                                                                               
                                                                                       
                                                                        }
                                                                        else
                                                                        {
                                                                               
                                                                        }
 
                                                                        RegCloseKey(hkeymedia);
                                 
                                RegCloseKey(hkeysrclist);
                                                                }
                                                                else
                                                                {// media key not found, create one.
                                                                        //Create the media key.
                                                                        DWORD dwDisp;
                                                                        if ((ccode =RegCreateKeyEx(hkeysrclist, MSI_MEDIA_KEY,0, NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL, &hkeymedia, &dwDisp))!= ERROR_SUCCESS)
                                                                        {
                                                                               
 
                                                                        }
                                                                        else
                                                                        {//able to create media key
                                                                                if( ( ccode = RegSetValueEx( hkeymedia, MSI_MEDIA_PACKAGE_VAL, 0, REG_SZ,(LPBYTE)msiLocation, (DWORD) (wcslen(msiLocation)+1)) ) != ERROR_SUCCESS)
                                                                                {
                                                                                        // Failed to set it.
                                                                                       
                                                                                }
                                                                               
                                                                        }
 
 
 
                                                                }
                                                   
                                                   
                                                   }
                                                   break;
                     }
                                        else
                                        {
                           
                                                   
                                        }
                     index++;
                     RegCloseKey(hsubkey);
              }
              if (ccode != ERROR_NO_MORE_ITEMS && ccode != ERROR_SUCCESS)
              {
                                  // not find wvsevprop
                                       
              }
              RegCloseKey(hkey);
       }
       

Author

Commented:
Hello

How do i initialise(Null values)  these declarations?
HKEY   hkey;
 LONG   ccode;

TCHAR         enumname[256];

 FILETIME      dummy;


Regards
Sham




Author

Commented:
Hello
If i write
1)   wchar_t   msiLocation[] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
 2) RegSetValueEx( hkeymedia, MSI_MEDIA_PACKAGE_VAL, 0, REG_SZ,(LPBYTE)msiLocation, (DWORD) (wcslen(msiLocation)+1)

I see MediaPackage value as "\ "  rather than \CCS\VOL2\NT\WVFILES\SevProp in Registry.

I already tried before. Please let me know the problem


Regards
Sham

Author

Commented:
I also tried following:

1)   wchar_t   msiLocation[] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
2) RegSetValueEx( hkeymedia, MSI_MEDIA_PACKAGE_VAL, 0, REG_SZ,(LPBYTE)msiLocation, (DWORD) (wcslen(msiLocation)+1)* sizeof(wchar_t)

This is also did not work

Regards
Sham



Subrat (C++ windows/Linux)Software Engineer
CERTIFIED EXPERT

Commented:
Try it,
wchar_t   msiLocation[256] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";

Author

Commented:
Hello

I came to know that wchar_t type cannot be given as 5th and 6th argument for regsetvalueex(),as it expects const BYTE * type.

Regards
Sham


Subrat (C++ windows/Linux)Software Engineer
CERTIFIED EXPERT

Commented:
wchar_t   msiLocation[256] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
RegSetValueEx( hkeymedia,
                          MSI_MEDIA_PACKAGE_VAL,
                          0,
                          REG_SZ,
                          reinterpret_cast<const BYTE*>(msiLocation),
                          static_cast<DWORD>( wcslen(msiLocation)) * sizeof(wchar_t) ) );
Subrat (C++ windows/Linux)Software Engineer
CERTIFIED EXPERT

Commented:
Else..........

wchar_t   msiLocation[256] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
DWORD sz_msiLocation = static_cast<DWORD>(wcslen(msiLocation));
RegSetValueEx( hkeymedia,
                          MSI_MEDIA_PACKAGE_VAL,
                          0,
                          REG_SZ,
                          reinterpret_cast<const BYTE*>(msiLocation),
                          sz_msiLocation * sizeof(wchar_t) );
As told in your other thread you may try:

wchar_t *  msiLocation= L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
RegSetValueExW( hkeymedia,
                          MSI_MEDIA_PACKAGE_VAL,
                          0,
                          REG_SZ,
                          (LPCBYTE)msiLocation,
                          wcslen(msiLocation)* sizeof(wchar_t) );

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Hello
I get the following errors with the attached snippet code,wherever the registry API's are using the macros present in .h file. Please let me know the reason.




 error C2220: warning treated as error - no object file generated
 warning C4133: 'function' : incompatible types - from 'unsigned short [36]' to 'LPCSTR'
 warning C4133: 'function' : incompatible types - from 'unsigned short [36]' to 'LPCSTR'
 warning C4133: 'function' : incompatible types - from 'unsigned short [12]' to 'LPCSTR'
 warning C4133: 'function' : incompatible types - from 'unsigned short [10]' to 'const unsigned char *'
 warning C4133: 'function' : incompatible types - from 'unsigned short [11]' to 'LPCSTR'
 warning C4133: 'function' : incompatible types - from 'unsigned short [6]' to 'LPCSTR'
 warning C4133: 'function' : incompatible types - from 'unsigned short [6]' to 'LPCSTR'
NMAKE : fatal error U1077: 'cl' : return code '0x2'




Regards
Sham

//////.h file/////////////////
#define MSI_SOURCE_BASE_KEY		L"SOFTWARE\\Classes\\Installer\\Products"
#define WVSevProp_MSI		L"WVSevProp"
#define MSI_SOURCE_KEY		L"SourceList"
#define MSI_MEDIA_KEY		L"Media"
#define MSI_MEDIA_PACKAGE_VAL		L"MediaPackage"
#define MSI_PRODUCT_NAME_KEY	L"ProductName"
 
//////////////.h file///////////////////////
 
 
 
////////////////.c file//////////////////////
void set_mediapkgpath()
{
       HKEY   hkey;
       LONG   ccode;
       REGSAM  samRedirect = 0;
	   
 
 
    // Open the installer products key.
       if ((ccode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MSI_SOURCE_BASE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS)
       {
		   TRACEF(FW_TRCARGS, "Unable to open MSI Installer Product base key in 32-bit registry ");
		   
			samRedirect |= KEY_WOW64_64KEY;
			if ((ccode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MSI_SOURCE_BASE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS)
			{
			   TRACEF(FW_TRCARGS, "Unable to open MSI Installer Product base key in 64-bit registry");
               
			}  
			else
			{
                  TRACEF(FW_TRCARGS, " Opened MSI Installer Product base key in 64-bit registry.");
				  
			}
		}
		else
		{
              TRACEF(FW_TRCARGS, " Opened MSI Installer Product base key in 32-bit registry.");
			  
		}
 
		// Enumerate the key to find our product's key.
		if( ccode == ERROR_SUCCESS )
		{
			TCHAR      enumname[256];
              DWORD         enumnamelen = sizeof( enumname );
              DWORD         index =0L;
              FILETIME      dummy;
 
              ccode = ERROR_SUCCESS;
              while (ccode == ERROR_SUCCESS)
              {
                     HKEY   hsubkey;
					 TCHAR  prodname[256];
					 DWORD  prodnamelen = sizeof( prodname );
 
                     enumnamelen = sizeof( enumname );
                     ccode = RegEnumKeyEx(hkey, index, enumname, &enumnamelen, NULL, NULL, NULL,  &dummy);
                     if (ccode != ERROR_SUCCESS)
                           break;
                     TRACEF(FW_TRCARGS, " Found subkey Checking...");
					 
                     if ((ccode = RegOpenKeyEx(hkey, enumname, 0, samRedirect | KEY_ALL_ACCESS, &hsubkey) != ERROR_SUCCESS))
                     {
                           TRACEF(FW_TRCARGS, "Unable to open MSI Installer Product sub key ");
						   
                     }
                     else
                     if ((ccode = RegQueryValueEx(hsubkey, MSI_PRODUCT_NAME_KEY, NULL, NULL, (LPBYTE) prodname, &prodnamelen)) != ERROR_SUCCESS)
                     {
                           TRACEF(FW_TRCARGS, " Unable to query for ProductName");
						   
                     }
                     else
                     if (!_tcsicmp(prodname, WVSevProp_MSI))
                     {
                           HKEY   hkeysrclist;
 
                           TRACEF(FW_TRCARGS, " Found WVSevProp  key!");
					
						   if ((ccode = RegOpenKeyEx(hsubkey, MSI_SOURCE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkeysrclist) != ERROR_SUCCESS))
                           {//unable to open sourcelist key
                                  TRACEF(FW_TRCARGS, " Unable to open MSI Installer SourceList key ");
								  
                           }
                           else
                           {//source list key opened
							   TCHAR       mediapackage[1040];
								DWORD  mediapackagelen = sizeof( mediapackage );
								HKEY hkeymedia;
								
								
								wchar_t    msiLocation[] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
								//LPCWSTR  msi_media_package_val	=	L"MediaPackage";
																
								if ((ccode = RegOpenKeyEx(hkeysrclist, MSI_MEDIA_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkeymedia) == ERROR_SUCCESS))
								{ // media key found
									
									TRACEF(FW_TRCARGS, "  Successfully open Media key");
								   
									//Without checking the existence of MediaPackage path string, set MediaPackage to L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp"								  
									if ((ccode = RegSetValueExW( hkeymedia, MSI_MEDIA_PACKAGE_VAL, 0, REG_SZ,(LPBYTE)msiLocation,(DWORD)wcslen(msiLocation)*sizeof(wchar_t) ))  != ERROR_SUCCESS)
 
									{
											// Failed to set it.
											TRACEF(FW_TRCARGS, " Unable to set MediaPackage value ");
									}
									RegCloseKey(hkeymedia);
                                  
                                RegCloseKey(hkeysrclist);
								}
								else
								{// media key not found, create one.
									//Create the media key.
									DWORD dwDisp;
									if ((ccode =RegCreateKeyEx(hkeysrclist, MSI_MEDIA_KEY,0, NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL, &hkeymedia, &dwDisp))!= ERROR_SUCCESS) 
									{
										TRACEF(FW_TRCARGS, "unable to create media key");
 
									}
									else
									{//able to create media key
										if( ( ccode = RegSetValueExW( hkeymedia, MSI_MEDIA_PACKAGE_VAL, 0, REG_SZ,(LPBYTE)msiLocation,(DWORD)wcslen(msiLocation)*sizeof(wchar_t)) ) != ERROR_SUCCESS)
										{
											// Failed to set it.
											TRACEF(FW_TRCARGS, " Unable to set MediaPackage value after creating media key ");
										}
										
									}
 
 
 
								}
						   
						   
						   }
						   break;
                     }
					else
					{
                           TRACEF(FW_TRCARGS, " Haven't yet found WVSevProp product key...");
						   
					}
                     index++;
                     RegCloseKey(hsubkey);
              }
              if (ccode != ERROR_NO_MORE_ITEMS && ccode != ERROR_SUCCESS)
              {
				  // not find wvsevprop
					TRACEF(FW_TRCARGS,"wvsevprop not found");
              }
              RegCloseKey(hkey);
       }
       
		return;
}
////////////////.c file/////////////////////

Open in new window

Author

Commented:
Hello
i get the following errors, if i use attached acode snippet:

Line #(3907) : error C2065: '_T' : undeclared identifier
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3907) : warning C4047: 'function' : 'LPCSTR' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3907) : error C2143: syntax error : missing ')' before 'string'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3907) : error C2198: 'RegQueryValueExA' : too few arguments for call through pointer-to-function
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3909) : error C2181: illegal else without matching if
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3912) : error C2181: illegal else without matching if
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3913) : error C2065: 'prodname' : undeclared identifier
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3913) : warning C4047: 'function' : 'const unsigned char *' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3919) : error C2065: 'hsubkey' : undeclared identifier
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3919) : warning C4047: 'function' : 'HKEY' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3919) : warning C4047: 'function' : 'LPCSTR' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3919) : error C2143: syntax error : missing ')' before 'string'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3919) : error C2198: 'RegOpenKeyExA' : too few arguments for call through pointer-to-function
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3921) : error C2181: illegal else without matching if
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3934) : error C2065: 'hkeysrclist' : undeclared identifier
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3934) : warning C4047: 'function' : 'HKEY' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3948) : warning C4047: 'function' : 'HKEY' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3954) : warning C4047: 'function' : 'HKEY' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3975) : error C2043: illegal break
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3982) : error C2065: 'index' : undeclared identifier
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3983) : warning C4047: 'function' : 'HKEY' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3985) : error C2059: syntax error : 'if'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3990) : error C2373: 'RegCloseKey' : redefinition; different type modifiers
        C:\CAIMAGES\BuildAreas\Austin\Development\Release\SDKS\MSSDK_2003_3790\include\WinReg.h(144) : see declaration of 'RegCloseKey'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3991) : error C2059: syntax error : '}'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3993) : error C2059: syntax error : 'else'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3994) : error C2059: syntax error : 'return'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3995) : error C2059: syntax error : '}'
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.
///////////////.h file////////////////////////////////
#define MSI_SOURCE_BASE_KEY			_T("SOFTWARE\\Classes\\Installer\\Products")
#define WVSevProp_MSI		_T("WVSevProp")
#define MSI_SOURCE_KEY		_T"SourceList")
#define MSI_MEDIA_KEY		_T("Media")
#define MSI_MEDIA_PACKAGE_VAL		_T("MediaPackage")
#define MSI_PRODUCT_NAME_KEY	_T"ProductName")
///////////////////////////.h file/////////////////////////////////
 
 
 
/////////////////////////////////.c file///////////////////////////////
void set_mediapkgpath() //Line #3848 
{
       HKEY   hkey;
       LONG   ccode;
       REGSAM  samRedirect = 0;
	   
 
		
    // Open the installer products key.
       if ((ccode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MSI_SOURCE_BASE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS)
       {
		   TRACEF(FW_TRCARGS, "Unable to open MSI Installer Product base key in 32-bit registry ");
		   
			samRedirect |= KEY_WOW64_64KEY;
			if ((ccode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MSI_SOURCE_BASE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS)
			{
			   TRACEF(FW_TRCARGS, "Unable to open MSI Installer Product base key in 64-bit registry");
               
			}  
			else
			{
                  TRACEF(FW_TRCARGS, " Opened MSI Installer Product base key in 64-bit registry.");
				  
			}
		}
		else
		{
              TRACEF(FW_TRCARGS, " Opened MSI Installer Product base key in 32-bit registry.");
			  
		}
 
		// Enumerate the key to find our product's key.
		if( ccode == ERROR_SUCCESS )
		{
			TCHAR      enumname[256];
              DWORD         enumnamelen = sizeof( enumname );
              DWORD         index =0L;
              FILETIME      dummy;
 
              ccode = ERROR_SUCCESS;
              while (ccode == ERROR_SUCCESS)
              {
                     HKEY   hsubkey;
					 TCHAR  prodname[256];
					 DWORD  prodnamelen = sizeof( prodname );
 
                     enumnamelen = sizeof( enumname );
                     ccode = RegEnumKeyEx(hkey, index, enumname, &enumnamelen, NULL, NULL, NULL,  &dummy);
                     if (ccode != ERROR_SUCCESS)
                           break;
                     TRACEF(FW_TRCARGS, " Found subkey Checking...");
					 
                     if ((ccode = RegOpenKeyEx(hkey, enumname, 0, samRedirect | KEY_ALL_ACCESS, &hsubkey) != ERROR_SUCCESS))
                     {
                           TRACEF(FW_TRCARGS, "Unable to open MSI Installer Product sub key ");
						   
                     }
                     else
                     if ((ccode = RegQueryValueEx(hsubkey, MSI_PRODUCT_NAME_KEY, NULL, NULL, (LPBYTE) prodname, &prodnamelen)) != ERROR_SUCCESS)
                     {
                           TRACEF(FW_TRCARGS, " Unable to query for ProductName");
						   
                     }
                     else
                     if (!_tcsicmp(prodname, WVSevProp_MSI))
                     {
                           HKEY   hkeysrclist;
 
                           TRACEF(FW_TRCARGS, " Found WVSevProp  key!");
					
						   if ((ccode = RegOpenKeyEx(hsubkey, MSI_SOURCE_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkeysrclist) != ERROR_SUCCESS))
                           {//unable to open sourcelist key
                                  TRACEF(FW_TRCARGS, " Unable to open MSI Installer SourceList key ");
								  
                           }
                           else
                           {//source list key opened
							   TCHAR       mediapackage[1040];
								DWORD  mediapackagelen = sizeof( mediapackage );
								HKEY hkeymedia;
								
								
								wchar_t  msiLocation[] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
								LPCWSTR  msi_media_package_val	=	L"MediaPackage";
																
								if ((ccode = RegOpenKeyEx(hkeysrclist, MSI_MEDIA_KEY, 0, samRedirect | KEY_ALL_ACCESS, &hkeymedia) == ERROR_SUCCESS))
								{ // media key found
									
									TRACEF(FW_TRCARGS, "  Successfully open Media key");
								   
									//Without checking the existence of MediaPackage path string, set MediaPackage to L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp"								  
									if ((ccode = RegSetValueExW( hkeymedia, msi_media_package_val, 0, REG_SZ,(LPBYTE)msiLocation,(DWORD)wcslen(msiLocation)*sizeof(wchar_t) ))  != ERROR_SUCCESS)
 
									{
											// Failed to set it.
											TRACEF(FW_TRCARGS, " Unable to set MediaPackage value ");
									}
									RegCloseKey(hkeymedia);
                                  
                                RegCloseKey(hkeysrclist);
								}
								else
								{// media key not found, create one.
									//Create the media key.
									DWORD dwDisp;
									if ((ccode =RegCreateKeyEx(hkeysrclist, MSI_MEDIA_KEY,0, NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL, &hkeymedia, &dwDisp))!= ERROR_SUCCESS) 
									{
										TRACEF(FW_TRCARGS, "unable to create media key");
 
									}
									else
									{//able to create media key
										if( ( ccode = RegSetValueExW( hkeymedia, msi_media_package_val, 0, REG_SZ,(LPBYTE)msiLocation,(DWORD)wcslen(msiLocation)*sizeof(wchar_t)) ) != ERROR_SUCCESS)
										{
											// Failed to set it.
											TRACEF(FW_TRCARGS, " Unable to set MediaPackage value after creating media key ");
										}
										
									}
 
 
 
								}
						   
						   
						   }
						   break;
                     }
					else
					{
                           TRACEF(FW_TRCARGS, " Haven't yet found WVSevProp product key...");
						   
					}
                     index++;
                     RegCloseKey(hsubkey);
              }
              if (ccode != ERROR_NO_MORE_ITEMS && ccode != ERROR_SUCCESS)
              {
				  // not find wvsevprop
					TRACEF(FW_TRCARGS,"wvsevprop not found");
              }
              RegCloseKey(hkey);
       }
       
		
		return;
}
////////////////////////.c file//////////////////////////////////

Open in new window

Author

Commented:
Hello

Please ignore my latest update of

02.12.2009 at 07:25PM IST, ID: 23621873

Sorry

Regards
sham

Author

Commented:
Hello
With reference to my  update of 02.12.2009 at 07:14PM IST, ID: 23621786, if i change L"" to _T"" in .h file
void set_mediapkgpath() function starts at line# 3858
i get the following errors, Please let me know the reason.


C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3907) : error C2065: '_T' : undeclared identifier
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3907) : warning C4047: 'function' : 'LPCSTR' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3907) : error C2143: syntax error : missing ')' before 'string'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3907) : error C2198: 'RegQueryValueExA' : too few arguments for call through pointer-to-function
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3909) : error C2181: illegal else without matching if
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3912) : error C2181: illegal else without matching if
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3913) : error C2065: 'prodname' : undeclared identifier
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3913) : warning C4047: 'function' : 'const unsigned char *' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3919) : error C2065: 'hsubkey' : undeclared identifier
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3919) : warning C4047: 'function' : 'HKEY' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3975) : error C2043: illegal break
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3983) : warning C4047: 'function' : 'HKEY' differs in levels of indirection from 'int'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3993) : error C2059: syntax error : 'if'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3993) : error C2059: syntax error : 'else'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3994) : error C2059: syntax error : 'return'
C:\BuildAreas\Austin\Development\Release\UNINT\TNGSETUP\PLUGINS\WVSETUP\SRC\TNGWVSSAPI.C(3995) : error C2059: syntax error : '}'
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.


Regards
Sham

>>>> i get the following errors, Please let me know the reason.

The _T macro is defined in tchar.h. You need to include it in your header (or into stdafx.h if using precompiled headers) before use.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.