home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap03 / lst31use / lst31use.cpp next >
Encoding:
C/C++ Source or Header  |  1996-09-23  |  1.1 KB  |  54 lines

  1.  
  2. #include <objbase.h>
  3. #include <initguid.h>
  4. #include <stdio.h>
  5.  
  6. class ILowerStr    : public IUnknown
  7. {
  8. public:
  9.     virtual STDMETHODIMP Lower(char *lpInput, char**lpOutput) = 0;
  10. };
  11.  
  12.  
  13. const CLSID CLSID_CLowerStr =
  14. {0x4f126d90, 0x1319, 0x11d0, {0xa6, 0xac, 0x0, 0xaa, 0x0, 0x60, 0x25, 0x53}};
  15.                                                                                     
  16. const CLSID IID_ILowerStr = 
  17. {0x4f126d91, 0x1319, 0x11d0, {0xa6, 0xac, 0x0, 0xaa, 0x0, 0x60, 0x25, 0x53}};
  18.  
  19.  
  20. void main()
  21. {
  22.  
  23.     HRESULT hr;
  24.      ILowerStr  *pILowerStr; 
  25.     
  26.  
  27.     hr = CoInitialize(NULL);
  28.  
  29.     if(FAILED(hr))
  30.     {
  31.         printf("CoInitialize failed[0x%x]\n", hr);
  32.         exit(1);
  33.     }
  34.  
  35.     //Create an instance of the COM object 
  36.     hr = CoCreateInstance(CLSID_CLowerStr, NULL, CLSCTX_INPROC_SERVER,
  37.          IID_ILowerStr,(void**) &pILowerStr); 
  38.  
  39.     if(FAILED(hr))
  40.     {
  41.         printf("CoCreateInstance failed[0x%x]\n", hr);
  42.         if(hr == REGDB_E_CLASSNOTREG)
  43.             printf("please register the class\n");
  44.         exit(1);
  45.     }
  46.  
  47.     char *lpOutput;
  48.  
  49.     pILowerStr->Lower("hEllo World", &lpOutput);
  50.     printf("the output is %s\n", lpOutput);
  51.  
  52.     pILowerStr->Release();
  53.     CoUninitialize();    
  54. }