Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 2000-2002 Microsoft Corporation
  3. Module Name:
  4. BaanERP5.cpp
  5. Abstract:
  6. Set 'lpstrInitialDir' in the OPENFILENAMEA structure passed to
  7. GetSaveFileNameA to be the directory the app is installed to.
  8. This information is read from the registry.
  9. No idea why this worked in Win9x.
  10. Notes:
  11. This is an app specific shim.
  12. History:
  13. 02/16/2000 clupu Created
  14. 03/07/2002 robkenny Security changes
  15. --*/
  16. #include "precomp.h"
  17. #include <commdlg.h>
  18. IMPLEMENT_SHIM_BEGIN(BaanERP5)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(GetSaveFileNameA)
  22. APIHOOK_ENUM_END
  23. const char gszLibUser[] = "\\LIB\\USER";
  24. char gszBaanDir[MAX_PATH];
  25. /*++
  26. Set the initial directory to be the directory the app was installed to. This
  27. information is read from the registry.
  28. --*/
  29. BOOL
  30. APIHOOK(GetSaveFileNameA)(
  31. LPOPENFILENAMEA lpofn
  32. )
  33. {
  34. if (lpofn->lpstrInitialDir == NULL) {
  35. HKEY hkey = NULL;
  36. DWORD ret;
  37. DWORD cbSize;
  38. /*
  39. * Get the directory only once
  40. */
  41. if (gszBaanDir[0] == 0) {
  42. ret = RegOpenKeyA(HKEY_LOCAL_MACHINE,
  43. "SOFTWARE\\Baan\\bse",
  44. &hkey);
  45. if (ret != ERROR_SUCCESS) {
  46. DPFN( eDbgLevelInfo, "Failed to open key 'SOFTWARE\\Baan\\bse'");
  47. goto Cont;
  48. }
  49. cbSize = MAX_PATH;
  50. ret = (DWORD)RegQueryValueExA(hkey,
  51. "BSE",
  52. NULL,
  53. NULL,
  54. (LPBYTE)gszBaanDir,
  55. &cbSize);
  56. if (ret != ERROR_SUCCESS) {
  57. DPFN( eDbgLevelInfo, "Failed to query value BSE");
  58. goto Cont;
  59. }
  60. StringCchCatA(gszBaanDir, MAX_PATH, gszLibUser);
  61. Cont:
  62. if (hkey != NULL) {
  63. RegCloseKey(hkey);
  64. }
  65. }
  66. lpofn->lpstrInitialDir = gszBaanDir;
  67. DPFN( eDbgLevelInfo, "BaanERP5.dll, Changing lpstrInitialDir to '%s'", gszBaanDir);
  68. }
  69. // Call the Initial function
  70. return ORIGINAL_API(GetSaveFileNameA)(lpofn);
  71. }
  72. /*++
  73. Register hooked functions
  74. --*/
  75. HOOK_BEGIN
  76. APIHOOK_ENTRY(COMDLG32.DLL, GetSaveFileNameA)
  77. HOOK_END
  78. IMPLEMENT_SHIM_END