[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1158
  • Last Modified:

How do i add wchar_t?

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
0
sham_ibmgs
Asked:
sham_ibmgs
  • 15
  • 5
  • 3
1 Solution
 
itsmeandnobodyelseCommented:
>>>> 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.
0
 
Subrat (C++ windows/Linux)Software EngineerCommented:
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...
0
 
sham_ibmgsAuthor 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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sham_ibmgsAuthor 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
0
 
sham_ibmgsAuthor Commented:
Hello

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

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

Regards
Sham
0
 
sham_ibmgsAuthor Commented:
Hello Moderator

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

Regards
Sham


0
 
sham_ibmgsAuthor 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
0
 
sham_ibmgsAuthor Commented:
Hello Moderator

I did not get any reply till now.

Please look into this issue.


Regards
Sham


0
 
Subrat (C++ windows/Linux)Software EngineerCommented:
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);
       }
       
0
 
sham_ibmgsAuthor Commented:
Hello

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

TCHAR         enumname[256];

 FILETIME      dummy;


Regards
Sham




0
 
sham_ibmgsAuthor 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
0
 
sham_ibmgsAuthor 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



0
 
Subrat (C++ windows/Linux)Software EngineerCommented:
Try it,
wchar_t   msiLocation[256] = L"\\CCS\\VOL2\\NT\\WVFILES\\SevProp";
0
 
sham_ibmgsAuthor 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


0
 
Subrat (C++ windows/Linux)Software EngineerCommented:
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) ) );
0
 
Subrat (C++ windows/Linux)Software EngineerCommented:
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) );
0
 
itsmeandnobodyelseCommented:
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) );
0
 
sham_ibmgsAuthor 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

0
 
sham_ibmgsAuthor 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

0
 
sham_ibmgsAuthor Commented:
Hello

Please ignore my latest update of

02.12.2009 at 07:25PM IST, ID: 23621873

Sorry

Regards
sham
0
 
sham_ibmgsAuthor 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

0
 
itsmeandnobodyelseCommented:
>>>> 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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 15
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now