home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somd / cpp / dii / nlsutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-27  |  2.5 KB  |  90 lines

  1. /*
  2. #
  3. #   COMPONENT_NAME: somx
  4. #
  5. #   ORIGINS: 27
  6. #
  7. #
  8. #   10H9767, 10H9769  (C) COPYRIGHT International Business Machines Corp. 1992,1994
  9. #   All Rights Reserved
  10. #   Licensed Materials - Property of IBM
  11. #   US Government Users Restricted Rights - Use, duplication or
  12. #   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  13.  
  14.  
  15.  
  16.  
  17. # DISCLAIMER OF WARRANTIES.
  18. # The following [enclosed] code is sample code created by IBM
  19. # Corporation. This sample code is not part of any standard or IBM
  20. # product and is provided to you solely for the purpose of assisting
  21. # you in the development of your applications.  The code is provided
  22. # "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
  23. # NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. # FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF
  25. # THIS CODE.  IBM shall not be liable for any damages arising out of
  26. # your use of the sample code, even if they have been advised of the
  27. # possibility of such damages.
  28. #
  29. # DISTRIBUTION.
  30. # This sample code can be freely distributed, copied, altered, and
  31. # incorporated into other software, provided that it bears the above
  32. # Copyright notice and DISCLAIMER intact.
  33. */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #include <windows.h>
  39. #include <stdio.h>
  40. #include <som.h>
  41.  
  42. #define BUFSIZE 256
  43. char buf[BUFSIZE];
  44.  
  45.  
  46. static HINSTANCE hinst = NULL;
  47.  
  48. /*************************************************************
  49. Load a message from the resource, based on the msgId.
  50. A temp buffer is returned.
  51. **************************************************************/
  52. char * __stdcall NlsMsgGet(int msgId){
  53.  
  54.     if (hinst == NULL)
  55.     {
  56.         hinst = GetModuleHandle(NULL);
  57.         if (hinst == NULL)
  58.         {
  59.             /* note: can't translate this error message */
  60.             fprintf(stderr,"can't get module handle\n");
  61.             exit(1);
  62.         }
  63.     }
  64.  
  65.     if (LoadString(hinst, msgId, buf, BUFSIZE) == 0)
  66.         return "unknown nls message";
  67.     else return buf;
  68. }
  69.  
  70. /**********************************************************************
  71. Load a nls message from the rc.
  72. New memory is allocated. The new memory should be freed with somFree
  73. ***********************************************************************/
  74. char * __stdcall NlsMsgAlloc(int msgId){
  75. char *msg, *finalMsg;
  76.  
  77.     msg = NlsMsgGet(msgId);
  78.     finalMsg=(char *)SOMMalloc(strlen(msg)+1);
  79.     if (finalMsg == NULL){
  80.         fprintf(stderr,"out of memory\n");
  81.         exit(1);
  82.     }
  83.     strcpy(finalMsg, msg);
  84.     return finalMsg;
  85. }
  86.  
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90.