home *** CD-ROM | disk | FTP | other *** search
/ Enter 1999 November / ENTER11_1.bin / WARSZTAT / SDKJava32.exe / data1.cab / fg_Win32Src / Src / Win32Api / Ole32.java < prev    next >
Encoding:
Java Source  |  1999-03-17  |  11.2 KB  |  324 lines

  1. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  2.  
  3. // These classes provide direct, low-overhead access to commonly used
  4. // Windows api. These classes use the new J/Direct feature.
  5. //
  6. // Information on how to use J/Direct to write your own declarations
  7. // can be found in the Microsoft SDK for Java.
  8. //
  9. // Methods marked as "ole" mode throw an instance of ComFailException
  10. //  if the native method returns an unsuccessful HRESULT.
  11.  
  12. package com.ms.win32;
  13.  
  14. import com.ms.com.*;
  15.  
  16.  
  17. /** @security(checkClassLinking=on) */
  18. public class Ole32
  19. {
  20.     /****** COM init/uninit methods *******************************************/
  21.  
  22.     /**
  23.       * note that this method returns an HRESULT, the return value from the
  24.       *  system call.
  25.       *
  26.       * @dll.import( "OLE32", unicode )
  27.       */
  28.     public native static int CoInitialize( int pvReserved );
  29.  
  30.     /**
  31.       * note that this method returns an HRESULT, the return value from the
  32.       *  system call.
  33.       *
  34.       * @dll.import( "OLE32", unicode )
  35.       */
  36.     public native static int CoInitializeEx( int pvReserved, int dwCoInit );
  37.  
  38.     /** @dll.import( "OLE32", auto ) */
  39.     public native static void CoUninitialize();
  40.  
  41.     /** @dll.import( "OLE32", auto ) */
  42.     public native static int CoGetCurrentProcess();
  43.  
  44.  
  45.     /****** COM register/revoke/get class objects *****************************/
  46.  
  47.     /** @dll.import( "OLE32", ole ) */
  48.     public native static IUnknown CoGetClassObject( _Guid rclsid, int
  49.         dwClsContext, COSERVERINFO pServerInfo, _Guid riid );
  50.  
  51.     /** @dll.import( "OLE32", ole ) */
  52.     public native static int CoRegisterClassObject( _Guid rclsid, IUnknown pUnk,
  53.         int dwClsContext, int flags );
  54.  
  55.     /** @dll.import( "OLE32", ole ) */
  56.     public native static void CoRevokeClassObject( int dwRegister );
  57.  
  58.     /** @dll.import( "OLE32", ole ) */
  59.     public native static void CoResumeClassObjects();
  60.  
  61.     /** @dll.import( "OLE32", ole ) */
  62.     public native static void CoSuspendClassObjects();
  63.  
  64.     /** @dll.import( "OLE32", auto ) */
  65.     public native static int CoAddRefServerProcess();
  66.  
  67.     /** @dll.import( "OLE32", auto ) */
  68.     public native static int CoReleaseServerProcess();
  69.  
  70.     /** @dll.import( "OLE32", ole ) */
  71.     public native static _Guid CoGetPSClsid( _Guid riid );
  72.  
  73.     /** @dll.import( "OLE32", ole ) */
  74.     public native static void CoRegisterPSClsid( _Guid riid, _Guid rclsid );
  75.  
  76.  
  77.     /****** DCOM Call Security. ***********************************************/
  78.  
  79.     /** @dll.import( "OLE32", ole ) */
  80.     public native static IUnknown CoGetCallContext( _Guid riid );
  81.  
  82.     /** @dll.import( "OLE32", ole ) */
  83.     public native static IUnknown CoCopyProxy( IUnknown pProxy );
  84.  
  85.     /** @dll.import( "OLE32", ole ) */
  86.     public native static void CoImpersonateClient();
  87.  
  88.     /** @dll.import( "OLE32", ole ) */
  89.     public native static void CoRevertToSelf();
  90.  
  91.     /** @dll.import( "OLE32", ole ) */
  92.     public native static IUnknown CoSwitchCallContext( IUnknown pNewObject );
  93.  
  94.  
  95.     /****** helpers for creating instances ************************************/
  96.  
  97.     /** @dll.import( "OLE32", ole ) */
  98.     public native static IUnknown CoCreateInstance( _Guid rclsid, IUnknown
  99.         pUnkOuter, int dwClsContext, _Guid riid );
  100.  
  101.  
  102. //TODO:
  103.     /** @dll.import( "OLE32", ole ) */
  104.     private native static void CoGetInstanceFromFile( COSERVERINFO pServerInfo,
  105.         _Guid pClsid, IUnknown punkOuter, int dwClsCtx, int grfMode, String
  106.         pwszName, int dwCount, MULTI_QI pResults );
  107.  
  108.     public static void CoGetInstanceFromFile( COSERVERINFO pServerInfo,
  109.         _Guid pClsid, IUnknown punkOuter, int dwClsCtx, int grfMode, String
  110.         pwszName, MULTI_QI[] pResults )
  111.     {
  112.         if( pResults.length == 1 )
  113.         {
  114.             CoGetInstanceFromFile( pServerInfo, pClsid, punkOuter,
  115.                                     dwClsCtx, grfMode, pwszName, 1, pResults[ 0 ] );
  116.         }
  117.         else
  118.         {
  119.             throw new IllegalArgumentException( "currently, only 1-element MULTI_QI arrays can be used" );
  120.         }
  121.     }
  122.  
  123.  
  124. //TODO:
  125.     /** @dll.import( "OLE32", ole ) */
  126.     private native static void CoGetInstanceFromIStorage( COSERVERINFO
  127.         pServerInfo, _Guid pClsid, IUnknown punkOuter, int dwClsCtx, IStorage
  128.         pstg, int dwCount, MULTI_QI pResults );
  129.         
  130.     public static void CoGetInstanceFromIStorage( COSERVERINFO
  131.         pServerInfo, _Guid pClsid, IUnknown punkOuter, int dwClsCtx, IStorage
  132.         pstg, MULTI_QI[] pResults )
  133.     {
  134.         if( pResults.length == 1 )
  135.         {
  136.             CoGetInstanceFromIStorage( pServerInfo, pClsid, punkOuter,
  137.                                         dwClsCtx, pstg, 1, pResults[ 0 ] );
  138.         }
  139.         else
  140.         {
  141.             throw new IllegalArgumentException( "currently, only 1-element MULTI_QI arrays can be used" );
  142.         }
  143.     }
  144.  
  145.  
  146. //TODO:
  147.     /** @dll.import( "OLE32", ole ) */
  148.     private native static void CoCreateInstanceEx( _Guid rclsid, IUnknown
  149.         punkOuter, int dwClsCtx, COSERVERINFO pServerInfo, int dwCount,
  150.         MULTI_QI pResults );
  151.  
  152.     public static void CoCreateInstanceEx( _Guid rclsid, IUnknown
  153.         punkOuter, int dwClsCtx, COSERVERINFO pServerInfo, MULTI_QI[] pResults )
  154.     {
  155.         if( pResults.length == 1 )
  156.         {
  157.             CoCreateInstanceEx( rclsid, punkOuter, dwClsCtx, pServerInfo, 1, pResults[ 0 ] );
  158.         }
  159.         else
  160.         {
  161.             throw new IllegalArgumentException( "currently, only 1-element MULTI_QI arrays can be used" );
  162.         }        
  163.     }
  164.  
  165.  
  166.     /****** other helpers *****************************************************/
  167.  
  168.     /** @dll.import( "OLE32", ole ) */
  169.     public native static String StringFromCLSID( _Guid rclsid );
  170.  
  171.     /** @dll.import( "OLE32", ole ) */
  172.     public native static _Guid CLSIDFromString( String lpsz );
  173.     
  174.     /** @dll.import( "OLE32", ole ) */
  175.     public native static String StringFromIID( _Guid riid );
  176.     
  177.     /** @dll.import( "OLE32", ole ) */
  178.     public native static _Guid IIDFromString( String lpsz );
  179.  
  180.     /** @dll.import( "OLE32", auto ) */
  181.     public native static boolean CoIsOle1Class( _Guid rclsid );
  182.     
  183.     /** @dll.import( "OLE32", ole ) */
  184.     public native static String ProgIDFromCLSID( _Guid clsid );
  185.     
  186.     /** @dll.import( "OLE32", ole ) */
  187.     public native static _Guid CLSIDFromProgID( String lpszProgID );
  188.     
  189.     /** @dll.import( "OLE32", unicode ) */
  190.     public native static int StringFromGUID2( _Guid rguid, StringBuffer lpsz,
  191.         int cbMax );
  192.  
  193.     /** @dll.import( "OLE32", ole ) */
  194.     public native static _Guid CoCreateGuid();
  195.  
  196.     
  197.     /****** TreatAs APIS ******************************************************/
  198.  
  199.     /** @dll.import( "OLE32", ole ) */
  200.     public native static _Guid CoGetTreatAsClass( _Guid clsidOld );
  201.  
  202.     /** @dll.import( "OLE32", ole ) */
  203.     public native static void CoTreatAsClass( _Guid clsidOld, _Guid clsidNew );
  204.  
  205.     
  206.     /****** Default Memory Allocation *****************************************/
  207.  
  208.     /** @dll.import( "OLE32", auto ) */
  209.     public native static int CoTaskMemAlloc( int cb );
  210.  
  211.     /** @dll.import( "OLE32", auto ) */
  212.     public native static int CoTaskMemRealloc( int pv, int cb );
  213.  
  214.     /** @dll.import( "OLE32", auto ) */
  215.     public native static void CoTaskMemFree( int pv );
  216.  
  217.  
  218.     /****** Storage API Prototypes ********************************************/
  219.  
  220.     /** @dll.import( "OLE32", ole ) */
  221.     public native static IStorage StgCreateDocfile( String pwcsName, int grfMode,
  222.         int reserved );
  223.  
  224.     /** @dll.import( "OLE32", ole ) */
  225.     public native static IStorage StgOpenStorage( String pwcsName, IStorage
  226.         pstgPriority, int grfMode, Object snbExclude, int reserved );
  227.  
  228.     /** @dll.import( "OLE32", unicode ) */
  229.     public native static int StgIsStorageFile( String pwcsName );
  230.  
  231.     /** @dll.import( "OLE32", ole ) */
  232.     public native static void StgSetTimes( String lpszName, long[] pctime,
  233.         long[] patime, long[] pmtime );
  234.  
  235.     /** @dll.import( "OLE32", ole ) */
  236.     public native static IStorage StgOpenLayoutDocfile( String pwcsDfName, int
  237.         grfMode, int reserved );
  238.  
  239.     /** @dll.import( "OLE32", ole ) */
  240.     public native static IStorage StgCreateStorageEx( String pwcsName, int
  241.         grfMode, int stgfmt, int grfAttrs, int reserved1, int reserved2,
  242.         _Guid riid );
  243.  
  244.  
  245.     /****** Moniker APIs ******************************************************/
  246.  
  247.     /** @dll.import( "OLE32", ole ) */
  248.     public native static IUnknown BindMoniker( IMoniker pmk, int grfOpt, _Guid
  249.         iidResult );
  250.  
  251.     /** @dll.import( "OLE32", ole ) */
  252.     public native static IUnknown CoGetObject( String pszName, BIND_OPTS
  253.         pBindOptions, _Guid riid );
  254.  
  255.     /** @dll.import( "OLE32", ole ) */
  256.     public native static IMoniker MkParseDisplayName( IBindCtx pbc, String
  257.         szUserName, int[] pchEaten );
  258.  
  259.     /**
  260.       * note that this method returns an HRESULT, the return value from the
  261.       *  system call.
  262.       *
  263.       * @dll.import( "OLE32", unicode )
  264.       */
  265.     public native static void MonikerRelativePathTo( IMoniker pmkSrc, IMoniker
  266.         pmkDest, IMoniker[] ppmkRelPath, boolean dwReserved );
  267.  
  268.     /**
  269.       * note that this method returns an HRESULT, the return value from the
  270.       *  system call.
  271.       *
  272.       * @dll.import( "OLE32", unicode )
  273.       */
  274.     public native static int MonikerCommonPrefixWith( IMoniker pmkThis,
  275.         IMoniker pmkOther, IMoniker[] ppmkCommon );
  276.  
  277.     /** @dll.import( "OLE32", ole ) */
  278.     public native static IBindCtx CreateBindCtx( int reserved );
  279.  
  280.     /** @dll.import( "OLE32", ole ) */
  281.     public native static IMoniker CreateGenericComposite( IMoniker pmkFirst,
  282.         IMoniker pmkRest );
  283.  
  284.     /** @dll.import( "OLE32", ole ) */
  285.     public native static _Guid GetClassFile( String szFilename );
  286.  
  287.     /** @dll.import( "OLE32", ole ) */
  288.     public native static IMoniker CreateClassMoniker( _Guid rclsid );
  289.  
  290.     /** @dll.import( "OLE32", ole ) */
  291.     public native static IMoniker CreateFileMoniker( String lpszPathName );
  292.  
  293.     /** @dll.import( "OLE32", ole ) */
  294.     public native static IMoniker CreateItemMoniker( String lpszDelim, String
  295.         lpszItem );
  296.  
  297.     /** @dll.import( "OLE32", ole ) */
  298.     public native static IMoniker CreateAntiMoniker();
  299.  
  300.     /** @dll.import( "OLE32", ole ) */
  301.     public native static IMoniker CreatePointerMoniker( IUnknown punk );
  302.  
  303.     /** @dll.import( "OLE32", ole ) */
  304.     public native static IRunningObjectTable GetRunningObjectTable( int
  305.         reserved );
  306.  
  307.  
  308.     /****** Storage Utility APIs **********************************************/
  309.  
  310.     /** @dll.import( "OLE32", ole ) */
  311.     public native static IStream CreateStreamOnHGlobal(int hGlobal, boolean
  312.         fDeleteOnRelease);
  313.  
  314.     /** @dll.import( "OLE32", ole ) */
  315.     public native static int GetHGlobalFromStream(IStream pstm);
  316.  
  317.     /** @dll.import( "OLE32", ole ) */
  318.     public native static ILockBytes CreateILockBytesOnHGlobal(int hGlobal,
  319.         boolean fDeleteOnRelease);
  320.  
  321.     /** @dll.import( "OLE32", ole ) */
  322.     public native static int GetHGlobalFromILockBytes(ILockBytes plkbyt);
  323. }
  324.