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

cdlg32.c
Go to the documentation of this file.
00001 /*
00002  *  Common Dialog Boxes interface (32 bit)
00003  *  Find/Replace
00004  *
00005  * Copyright 1999 Bertho A. Stultiens
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00020  */
00021 
00022 #include <stdarg.h>
00023 
00024 #define COBJMACROS
00025 
00026 #include "windef.h"
00027 #include "winbase.h"
00028 #include "wingdi.h"
00029 #include "winuser.h"
00030 #include "objbase.h"
00031 #include "rpcproxy.h"
00032 #include "commdlg.h"
00033 #include "cderr.h"
00034 #include "wine/debug.h"
00035 
00036 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
00037 
00038 #include "cdlg.h"
00039 
00040 
00041 DECLSPEC_HIDDEN HINSTANCE   COMDLG32_hInstance = 0;
00042 
00043 static DWORD COMDLG32_TlsIndex = TLS_OUT_OF_INDEXES;
00044 
00045 static HINSTANCE    SHELL32_hInstance;
00046 static HINSTANCE    SHFOLDER_hInstance;
00047 
00048 /* ITEMIDLIST */
00049 LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILClone) (LPCITEMIDLIST) DECLSPEC_HIDDEN;
00050 LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILCombine)(LPCITEMIDLIST,LPCITEMIDLIST) DECLSPEC_HIDDEN;
00051 LPITEMIDLIST (WINAPI *COMDLG32_PIDL_ILGetNext)(LPITEMIDLIST) DECLSPEC_HIDDEN;
00052 BOOL (WINAPI *COMDLG32_PIDL_ILRemoveLastID)(LPCITEMIDLIST) DECLSPEC_HIDDEN;
00053 BOOL (WINAPI *COMDLG32_PIDL_ILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST) DECLSPEC_HIDDEN;
00054 UINT (WINAPI *COMDLG32_PIDL_ILGetSize)(LPCITEMIDLIST) DECLSPEC_HIDDEN;
00055 
00056 /* SHELL */
00057 LPVOID (WINAPI *COMDLG32_SHAlloc)(DWORD) DECLSPEC_HIDDEN;
00058 DWORD (WINAPI *COMDLG32_SHFree)(LPVOID) DECLSPEC_HIDDEN;
00059 BOOL (WINAPI *COMDLG32_SHGetFolderPathW)(HWND,int,HANDLE,DWORD,LPWSTR) DECLSPEC_HIDDEN;
00060 LPITEMIDLIST (WINAPI *COMDLG32_SHSimpleIDListFromPathAW)(LPCVOID) DECLSPEC_HIDDEN;
00061 
00062 /***********************************************************************
00063  *  DllMain  (COMDLG32.init)
00064  *
00065  *    Initialization code for the COMDLG32 DLL
00066  *
00067  * RETURNS:
00068  *  FALSE if sibling could not be loaded or instantiated twice, TRUE
00069  *  otherwise.
00070  */
00071 static const char GPA_string[] = "Failed to get entry point %s for hinst = %p\n";
00072 #define GPA(dest, hinst, name) \
00073     if(!(dest = (void*)GetProcAddress(hinst,name)))\
00074     { \
00075       ERR(GPA_string, debugstr_a(name), hinst); \
00076       return FALSE; \
00077     }
00078 
00079 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
00080 {
00081     TRACE("(%p, %d, %p)\n", hInstance, Reason, Reserved);
00082 
00083     switch(Reason)
00084     {
00085     case DLL_PROCESS_ATTACH:
00086         COMDLG32_hInstance = hInstance;
00087         DisableThreadLibraryCalls(hInstance);
00088 
00089         SHELL32_hInstance = GetModuleHandleA("SHELL32.DLL");
00090 
00091         /* ITEMIDLIST */
00092         GPA(COMDLG32_PIDL_ILIsEqual, SHELL32_hInstance, (LPCSTR)21L);
00093         GPA(COMDLG32_PIDL_ILCombine, SHELL32_hInstance, (LPCSTR)25L);
00094         GPA(COMDLG32_PIDL_ILGetNext, SHELL32_hInstance, (LPCSTR)153L);
00095         GPA(COMDLG32_PIDL_ILClone, SHELL32_hInstance, (LPCSTR)18L);
00096         GPA(COMDLG32_PIDL_ILRemoveLastID, SHELL32_hInstance, (LPCSTR)17L);
00097         GPA(COMDLG32_PIDL_ILGetSize, SHELL32_hInstance, (LPCSTR)152L);
00098 
00099         /* SHELL */
00100         GPA(COMDLG32_SHSimpleIDListFromPathAW, SHELL32_hInstance, (LPCSTR)162);
00101         GPA(COMDLG32_SHAlloc, SHELL32_hInstance, (LPCSTR)196L);
00102         GPA(COMDLG32_SHFree, SHELL32_hInstance, (LPCSTR)195L);
00103 
00104         /* for the first versions of shell32 SHGetFolderPathW is in SHFOLDER.DLL */
00105         COMDLG32_SHGetFolderPathW = (void*)GetProcAddress(SHELL32_hInstance,"SHGetFolderPathW");
00106         if (!COMDLG32_SHGetFolderPathW)
00107         {
00108           SHFOLDER_hInstance = LoadLibraryA("SHFOLDER.DLL");
00109           GPA(COMDLG32_SHGetFolderPathW, SHFOLDER_hInstance,"SHGetFolderPathW");
00110         }
00111 
00112         break;
00113 
00114     case DLL_PROCESS_DETACH:
00115             if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES) TlsFree(COMDLG32_TlsIndex);
00116             if(SHFOLDER_hInstance) FreeLibrary(SHFOLDER_hInstance);
00117             break;
00118     }
00119     return TRUE;
00120 }
00121 #undef GPA
00122 
00123 /***********************************************************************
00124  *  COMDLG32_AllocMem           (internal)
00125  * Get memory for internal datastructure plus stringspace etc.
00126  *  RETURNS
00127  *      Success: Pointer to a heap block
00128  *      Failure: null
00129  */
00130 LPVOID COMDLG32_AllocMem(
00131     int size    /* [in] Block size to allocate */
00132 ) {
00133         LPVOID ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
00134         if(!ptr)
00135         {
00136             COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
00137                 return NULL;
00138         }
00139         return ptr;
00140 }
00141 
00142 
00143 /***********************************************************************
00144  *  COMDLG32_SetCommDlgExtendedError    (internal)
00145  *
00146  * Used to set the thread's local error value if a comdlg32 function fails.
00147  */
00148 void COMDLG32_SetCommDlgExtendedError(DWORD err)
00149 {
00150     TRACE("(%08x)\n", err);
00151         if (COMDLG32_TlsIndex == TLS_OUT_OF_INDEXES)
00152       COMDLG32_TlsIndex = TlsAlloc();
00153     if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
00154       TlsSetValue(COMDLG32_TlsIndex, (LPVOID)(DWORD_PTR)err);
00155     else
00156       FIXME("No Tls Space\n");
00157 }
00158 
00159 
00160 /***********************************************************************
00161  *  CommDlgExtendedError            (COMDLG32.@)
00162  *
00163  * Get the thread's local error value if a comdlg32 function fails.
00164  *  RETURNS
00165  *      Current error value which might not be valid
00166  *      if a previous call succeeded.
00167  */
00168 DWORD WINAPI CommDlgExtendedError(void)
00169 {
00170         if (COMDLG32_TlsIndex != TLS_OUT_OF_INDEXES)
00171       return (DWORD_PTR)TlsGetValue(COMDLG32_TlsIndex);
00172     else
00173       return 0; /* we never set an error, so there isn't one */
00174 }
00175 
00176 #if 0 // Win 7
00177 
00178 /*************************************************************************
00179  * Implement the CommDlg32 class factory
00180  *
00181  * (Taken from shdocvw/factory.c; based on implementation in
00182  *  ddraw/main.c)
00183  */
00184 typedef struct
00185 {
00186     IClassFactory IClassFactory_iface;
00187     HRESULT (*cf)(IUnknown*, REFIID, void**);
00188 } IClassFactoryImpl;
00189 
00190 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
00191 {
00192     return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
00193 }
00194 
00195 /*************************************************************************
00196  * CDLGCF_QueryInterface (IUnknown)
00197  */
00198 static HRESULT WINAPI CDLGCF_QueryInterface(IClassFactory* iface,
00199                                             REFIID riid, void **ppobj)
00200 {
00201     TRACE("%p (%s %p)\n", iface, debugstr_guid(riid), ppobj);
00202 
00203     if(!ppobj)
00204         return E_POINTER;
00205 
00206     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid))
00207     {
00208         *ppobj = iface;
00209         IClassFactory_AddRef(iface);
00210         return S_OK;
00211     }
00212 
00213     WARN("Interface not supported.\n");
00214 
00215     *ppobj = NULL;
00216     return E_NOINTERFACE;
00217 }
00218 
00219 /*************************************************************************
00220  * CDLGCF_AddRef (IUnknown)
00221  */
00222 static ULONG WINAPI CDLGCF_AddRef(IClassFactory *iface)
00223 {
00224     return 2; /* non-heap based object */
00225 }
00226 
00227 /*************************************************************************
00228  * CDLGCF_Release (IUnknown)
00229  */
00230 static ULONG WINAPI CDLGCF_Release(IClassFactory *iface)
00231 {
00232     return 1; /* non-heap based object */
00233 }
00234 
00235 /*************************************************************************
00236  * CDLGCF_CreateInstance (IClassFactory)
00237  */
00238 static HRESULT WINAPI CDLGCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
00239                                             REFIID riid, void **ppobj)
00240 {
00241     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
00242     return This->cf(pOuter, riid, ppobj);
00243 }
00244 
00245 /*************************************************************************
00246  * CDLGCF_LockServer (IClassFactory)
00247  */
00248 static HRESULT WINAPI CDLGCF_LockServer(IClassFactory *iface, BOOL dolock)
00249 {
00250     TRACE("%p (%d)\n", iface, dolock);
00251     return S_OK;
00252 }
00253 
00254 static const IClassFactoryVtbl CDLGCF_Vtbl =
00255 {
00256     CDLGCF_QueryInterface,
00257     CDLGCF_AddRef,
00258     CDLGCF_Release,
00259     CDLGCF_CreateInstance,
00260     CDLGCF_LockServer
00261 };
00262 
00263 /*************************************************************************
00264  *              DllGetClassObject (COMMDLG32.@)
00265  */
00266 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
00267 {
00268     static IClassFactoryImpl FileOpenDlgClassFactory = {{&CDLGCF_Vtbl}, FileOpenDialog_Constructor};
00269     static IClassFactoryImpl FileSaveDlgClassFactory = {{&CDLGCF_Vtbl}, FileSaveDialog_Constructor};
00270 
00271     TRACE("%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
00272 
00273     if(IsEqualGUID(&CLSID_FileOpenDialog, rclsid))
00274         return IClassFactory_QueryInterface(&FileOpenDlgClassFactory.IClassFactory_iface, riid, ppv);
00275 
00276     if(IsEqualGUID(&CLSID_FileSaveDialog, rclsid))
00277         return IClassFactory_QueryInterface(&FileSaveDlgClassFactory.IClassFactory_iface, riid, ppv);
00278 
00279     return CLASS_E_CLASSNOTAVAILABLE;
00280 }
00281 
00282 /***********************************************************************
00283  *          DllRegisterServer (COMMDLG32.@)
00284  */
00285 HRESULT WINAPI DllRegisterServer(void)
00286 {
00287     return E_FAIL; // FIXME: __wine_register_resources(COMDLG32_hInstance);
00288 }
00289 
00290 /***********************************************************************
00291  *          DllUnregisterServer (COMMDLG32.@)
00292  */
00293 HRESULT WINAPI DllUnregisterServer(void)
00294 {
00295     return E_FAIL; // FIXME: __wine_unregister_resources(COMDLG32_hInstance);
00296 }
00297 
00298 #endif // Win 7

Generated on Sat May 26 2012 04:21:41 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.