How to Use 32-bit StampResource() Function in Windows NT 3.51

Last reviewed: August 3, 1995
Article ID: Q133699
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) version 3.51

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:

  1. 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.

  2. Allocate memory for the resultant wide-character string and perform the actual conversion by calling MultiByteToWideChar() again.

  3. 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:

   ARTICLE-ID: Q92525
   TITLE     : Using the Setup Toolkit Function StampResource


Additional reference words: 3.51
KBCategory: kbtool
KBSubcategory: tlsmss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 3, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.