Commit in reactos/lib/userenv on MAIN
desktop.c+30-171.6 -> 1.7
internal.h+31-11.6 -> 1.7
makefile+1-11.7 -> 1.8
misc.c+68-11.2 -> 1.3
+130-20
4 modified files
do not statically link to ole32.dll, import the functions dynamically instead. This is required since winlogon statically links to userenv.dll and then ole32.dll would automatically be loaded which causes ole32.dll to register a window class before the first window station is created (-> the ole32 window class(es) couldn't be registered). Besides it's bad to have winlogon depend on ole32.dll

reactos/lib/userenv
desktop.c 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- desktop.c	7 May 2004 11:18:53 -0000	1.6
+++ desktop.c	11 Jul 2004 22:35:07 -0000	1.7
@@ -1,4 +1,4 @@
-/* $Id: desktop.c,v 1.6 2004/05/07 11:18:53 ekohl Exp $
+/* $Id: desktop.c,v 1.7 2004/07/11 22:35:07 weiden Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -150,6 +150,7 @@
 		 WORD wHotKey,
 		 INT iShowCmd)
 {
+  DYN_FUNCS Ole32;
   WCHAR szLinkPath[MAX_PATH];
   WCHAR szArguments[MAX_PATH];
   WCHAR szCommand[MAX_PATH];
@@ -216,16 +217,20 @@
   DPRINT ("szCommand: '%S'\n", szCommand);
   DPRINT ("szArguments: '%S'\n", szArguments);
 
-  CoInitialize(NULL);
+  /* dynamically load ole32.dll */
+  LoadDynamicImports(&DynOle32, &Ole32);
 
-  hr = CoCreateInstance(&CLSID_ShellLink,
-                        NULL,
-                        CLSCTX_INPROC_SERVER,
-                        &IID_IShellLinkW,
-                       (LPVOID*)&psl);
+  Ole32.fn.CoInitialize(NULL);
+
+  hr = Ole32.fn.CoCreateInstance(&CLSID_ShellLink,
+                                 NULL,
+                                 CLSCTX_INPROC_SERVER,
+                                 &IID_IShellLinkW,
+                                 (LPVOID*)&psl);
   if (!SUCCEEDED(hr))
     {
-      CoUninitialize();
+      Ole32.fn.CoUninitialize();
+      UnloadDynamicImports(&Ole32);
       return FALSE;
     }
 
@@ -275,7 +280,9 @@
 
   psl->lpVtbl->Release(psl);
 
-  CoUninitialize();
+  Ole32.fn.CoUninitialize();
+  
+  UnloadDynamicImports(&Ole32);
 
   DPRINT ("AddDesktopItemW() done\n");
 
@@ -428,6 +435,7 @@
 	  WORD wHotKey,
 	  INT iShowCmd)
 {
+  DYN_FUNCS Ole32;
   WCHAR szLinkPath[MAX_PATH];
   WCHAR szArguments[MAX_PATH];
   WCHAR szCommand[MAX_PATH];
@@ -499,16 +507,20 @@
   DPRINT ("szCommand: '%S'\n", szCommand);
   DPRINT ("szArguments: '%S'\n", szArguments);
 
-  CoInitialize(NULL);
+  /* dynamically load ole32.dll */
+  LoadDynamicImports(&DynOle32, &Ole32);
+
+  Ole32.fn.CoInitialize(NULL);
 
-  hr = CoCreateInstance(&CLSID_ShellLink,
-                        NULL,
-                        CLSCTX_INPROC_SERVER,
-                        &IID_IShellLinkW,
-                       (LPVOID*)&psl);
+  hr = Ole32.fn.CoCreateInstance(&CLSID_ShellLink,
+                                 NULL,
+                                 CLSCTX_INPROC_SERVER,
+                                 &IID_IShellLinkW,
+                                 (LPVOID*)&psl);
   if (!SUCCEEDED(hr))
     {
-      CoUninitialize();
+      Ole32.fn.CoUninitialize();
+      UnloadDynamicImports(&Ole32);
       return FALSE;
     }
 
@@ -558,7 +570,8 @@
 
   psl->lpVtbl->Release(psl);
 
-  CoUninitialize();
+  Ole32.fn.CoUninitialize();
+  UnloadDynamicImports(&Ole32);
 
   DPRINT ("AddItemW() done\n");
 

reactos/lib/userenv
internal.h 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- internal.h	7 May 2004 11:18:53 -0000	1.6
+++ internal.h	11 Jul 2004 22:35:07 -0000	1.7
@@ -1,4 +1,4 @@
-/* $Id: internal.h,v 1.6 2004/05/07 11:18:53 ekohl Exp $ 
+/* $Id: internal.h,v 1.7 2004/07/11 22:35:07 weiden Exp $ 
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -37,6 +37,36 @@
 RemoveDirectoryPath (LPCWSTR lpPathName);
 
 /* misc.c */
+typedef struct _DYN_FUNCS
+{
+  HMODULE hModule;
+  union
+  {
+    PVOID foo;
+    struct
+    {
+      HRESULT (STDCALL *CoInitialize)(LPVOID pvReserved);
+      HRESULT (STDCALL *CoCreateInstance)(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID * ppv);
+      HRESULT (STDCALL *CoUninitialize)(VOID);
+    };
+  } fn;
+} DYN_FUNCS, *PDYN_FUNCS;
+
+typedef struct _DYN_MODULE
+{
+  LPWSTR Library;    /* dll file name */
+  int nFunctions;    /* number of functions in the Functions array */
+  LPSTR *Functions;  /* function names */
+} DYN_MODULE, *PDYN_MODULE;
+
+extern DYN_MODULE DynOle32;
+
+BOOL
+LoadDynamicImports(PDYN_MODULE Module, PDYN_FUNCS DynFuncs);
+
+VOID
+UnloadDynamicImports(PDYN_FUNCS DynFuncs);
+
 LPWSTR
 AppendBackslash (LPWSTR String);
 

reactos/lib/userenv
makefile 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- makefile	29 May 2004 21:24:47 -0000	1.7
+++ makefile	11 Jul 2004 22:35:07 -0000	1.8
@@ -13,7 +13,7 @@
 
 TARGET_LFLAGS = -nostdlib -nostartfiles
 
-TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a ole32.a wine_uuid.a
+TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a wine_uuid.a
 
 TARGET_OBJECTS = desktop.o directory.o environment.o profile.o misc.o \
                  registry.o setup.o userenv.o

reactos/lib/userenv
misc.c 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- misc.c	13 Mar 2004 20:49:07 -0000	1.2
+++ misc.c	11 Jul 2004 22:35:07 -0000	1.3
@@ -1,4 +1,4 @@
-/* $Id: misc.c,v 1.2 2004/03/13 20:49:07 ekohl Exp $
+/* $Id: misc.c,v 1.3 2004/07/11 22:35:07 weiden Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -91,4 +91,71 @@
   return TRUE;
 }
 
+/* Dynamic DLL loading interface **********************************************/
+
+/* OLE32.DLL import table */
+LPSTR Ole32Imports[] =
+{
+  "CoInitialize",
+  "CoCreateInstance",
+  "CoUninitialize",
+};
+
+DYN_MODULE DynOle32 = 
+{
+  L"ole32.dll",
+  sizeof(Ole32Imports) / sizeof(LPSTR),
+  Ole32Imports
+};
+
+/*
+   Use this function to load functions from other modules. We cannot statically
+   link to e.g. ole32.dll because those dlls would get loaded on startup with
+   winlogon and they may try to register classes etc when not even a window station
+   has been created!
+*/
+
+BOOL
+LoadDynamicImports(PDYN_MODULE Module, PDYN_FUNCS DynFuncs)
+{
+  int i;
+  PVOID *fn;
+  
+  ZeroMemory(DynFuncs, sizeof(DYN_FUNCS));
+  
+  DynFuncs->hModule = LoadLibraryW(Module->Library);
+  if(!DynFuncs->hModule)
+  {
+    return FALSE;
+  }
+  
+  /* begin with the first function */
+  fn = &DynFuncs->fn.foo; /* warning: assignment from incompatible pointer type */
+  
+  /* load the imports */
+  for(i = 0; i < Module->nFunctions; i++)
+  {
+    *fn = GetProcAddress(DynFuncs->hModule, Module->Functions[i]);
+    if(*fn == NULL)
+    {
+      FreeLibrary(DynFuncs->hModule);
+      DynFuncs->hModule = (HMODULE)0;
+      return FALSE;
+    }
+    fn++;
+  }
+  
+  return TRUE;
+}
+
+VOID
+UnloadDynamicImports(PDYN_FUNCS DynFuncs)
+{
+  if(DynFuncs->hModule)
+  {
+    FreeLibrary(DynFuncs->hModule);
+    DynFuncs->hModule = (HMODULE)0;
+  }
+}
+
 /* EOF */
CVSspam 0.2.8