ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

register.c
Go to the documentation of this file.
00001 /*
00002  * Support functions for Wine dll registrations
00003  *
00004  * Copyright (c) 2010 Alexandre Julliard
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "config.h"
00022 #include <stdarg.h>
00023 
00024 #define COBJMACROS
00025 #define ATL_INITGUID
00026 #include "windef.h"
00027 #include "winbase.h"
00028 #include "winnls.h"
00029 #include "ole2.h"
00030 #include "rpcproxy.h"
00031 #include "atliface.h"
00032 
00033 static const WCHAR ole32W[] = {'o','l','e','3','2','.','d','l','l',0};
00034 static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0};
00035 static const WCHAR moduleW[] = {'M','O','D','U','L','E',0};
00036 
00037 struct reg_info
00038 {
00039     IRegistrar  *registrar;
00040     BOOL         do_register;
00041     BOOL         uninit;
00042     HRESULT      result;
00043 };
00044 
00045 static HMODULE ole32;
00046 static HRESULT (WINAPI *pCoInitialize)(LPVOID);
00047 static void (WINAPI *pCoUninitialize)(void);
00048 static HRESULT (WINAPI *pCoCreateInstance)(REFCLSID,LPUNKNOWN,DWORD,REFIID,LPVOID*);
00049 
00050 static IRegistrar *create_registrar( HMODULE inst, struct reg_info *info )
00051 {
00052     if (!pCoCreateInstance)
00053     {
00054         if (!(ole32 = LoadLibraryW( ole32W )) ||
00055             !(pCoInitialize = (void *)GetProcAddress( ole32, "CoInitialize" )) ||
00056             !(pCoUninitialize = (void *)GetProcAddress( ole32, "CoUninitialize" )) ||
00057             !(pCoCreateInstance = (void *)GetProcAddress( ole32, "CoCreateInstance" )))
00058         {
00059             info->result = E_NOINTERFACE;
00060             return NULL;
00061         }
00062     }
00063     info->uninit = SUCCEEDED( pCoInitialize( NULL ));
00064 
00065     info->result = pCoCreateInstance( &CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER,
00066                                       &IID_IRegistrar, (void **)&info->registrar );
00067     if (SUCCEEDED( info->result ))
00068     {
00069         WCHAR str[MAX_PATH];
00070 
00071         GetModuleFileNameW( inst, str, MAX_PATH );
00072         IRegistrar_AddReplacement( info->registrar, moduleW, str );
00073     }
00074     return info->registrar;
00075 }
00076 
00077 static BOOL CALLBACK register_resource( HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg )
00078 {
00079     struct reg_info *info = (struct reg_info *)arg;
00080     WCHAR *buffer;
00081     HRSRC rsrc = FindResourceW( module, name, type );
00082     char *str = LoadResource( module, rsrc );
00083     DWORD lenW, lenA = SizeofResource( module, rsrc );
00084 
00085     if (!str) return FALSE;
00086     if (!info->registrar && !create_registrar( module, info )) return FALSE;
00087     lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1;
00088     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
00089     {
00090         info->result = E_OUTOFMEMORY;
00091         return FALSE;
00092     }
00093     MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW );
00094     buffer[lenW - 1] = 0;
00095 
00096     if (info->do_register)
00097         info->result = IRegistrar_StringRegister( info->registrar, buffer );
00098     else
00099         info->result = IRegistrar_StringUnregister( info->registrar, buffer );
00100 
00101     HeapFree( GetProcessHeap(), 0, buffer );
00102     return SUCCEEDED(info->result);
00103 }
00104 
00105 HRESULT __wine_register_resources( HMODULE module )
00106 {
00107     struct reg_info info;
00108 
00109     info.registrar = NULL;
00110     info.do_register = TRUE;
00111     info.uninit = FALSE;
00112     info.result = S_OK;
00113     EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&info );
00114     if (info.registrar) IRegistrar_Release( info.registrar );
00115     if (info.uninit) pCoUninitialize();
00116     return info.result;
00117 }
00118 
00119 HRESULT __wine_unregister_resources( HMODULE module )
00120 {
00121     struct reg_info info;
00122 
00123     info.registrar = NULL;
00124     info.do_register = FALSE;
00125     info.uninit = FALSE;
00126     info.result = S_OK;
00127     EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&info );
00128     if (info.registrar) IRegistrar_Release( info.registrar );
00129     if (info.uninit) pCoUninitialize();
00130     return info.result;
00131 }

Generated on Fri May 25 2012 04:25:05 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.