How to Use 32-bit StampResource() Function in Windows NT 3.51 (133699)
The information in this article applies to:
- Microsoft Win32 Software Development Kit (SDK) 3.51
This article was previously published under Q133699 SUMMARY
The 32-bit setup toolkit function, StampResource(), is used to write string
table resource data into binary (executable) files. This function is useful
for customizing installed files with installation-specific resource data,
such as a user's name, company, and so on. This article discusses issues
specific to using this function in the 32-bit Setup Toolkit for Windows NT
version 3.51.
MORE INFORMATION
StampResource() is prototyped in the 32-bit Setup Toolkit as follows:
VOID StampResource(LPSTR szSect, LPSTR szKey, LPSTR szDst,
int wResType, int wResId, LPSTR szData, int cbData);
Notice that the szData argument is prototyped as LPSTR. All string resource
data in Windows NT must be stored in UNICODE(tm) form. Therefore, because
StampResource() is writing directly into a binary file, you must convert
the string data for StampResource() into wide-character format. That means
you must make your szData string parameter type LPWSTR. The following
example shows how this can be done:
INT size;
TCHAR buf[80], szName[40],szCompany[20],szProductID[20];
LPWSTR wUnicodeString;
lstrcpy(szName,"Bob Smith");
lstrcpy(szCompany,"Microsoft");
lstrcpy(szProductID,"123-45-6789");
wsprintf(buf,"%c%s%c%s%c%s",lstrlen(szName),szName,lstrlen(szCompany),
szCompany,lstrlen(szProductID),szProductID);
size=MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,buf,-1,NULL,0);
wUnicodeString=(LPWSTR)GlobalAlloc(GMEM_FIXED,sizeof(WCHAR)*size);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,buf,-1,wUnicodeString,size);
StampResource("Extra Files","Config","d:\\setup32\\stamp\\disks\\disk1",
6,0x451,(LPSTR)wUnicodeString,sizeof(WCHAR)*size);
GlobalFree((HGLOBAL)wUnicodeString);
In this example, the code performs these steps:
- Convert the ASCII string "buf" to wide-character format by using the
Win32 MultiByteToWideChar() function. This first call to this function
retrieves the size, in wide characters, needed to store the resultant
wide-character string.
- Allocate memory for the resultant wide-character string and perform the
actual conversion by calling MultiByteToWideChar() again.
- Cast the wide-character string "wUnicodeString" to type LPSTR during the
call to StampResource() to avoid a type mismatch warning message.
NOTE: this information does not apply to Windows 95. The 32-bit
StampResource() function does not currently work in Windows 95
because it makes use of a Win32 API function that is not supported by
Windows 95.
REFERENCES
For more information on the other parameters of StampResource(), or how
StampResource() works in general, please see the following article in the
Microsoft Knowledge Base:
92525 Using the Setup Toolkit Function StampResource
Modification Type: | Major | Last Reviewed: | 1/12/2000 |
---|
Keywords: | KB133699 |
---|
|