Source code of Windows XP (NT5)
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.

132 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SetEnvironmentVariable.cpp
  5. Abstract:
  6. mapi dlls don't ship with w2k, and with outlook2000 it gets installed in a different
  7. location (%commonprogramfiles%)
  8. resumemaker and possibly others depend on mapi dlls being in system32 directory.
  9. Command line syntax is "envvariablename|envvariablevalue|envvariablename|envvariablevalue"
  10. Notes:
  11. This is an app specific shim.
  12. History:
  13. 07/02/2000 jarbats Created
  14. --*/
  15. #include "precomp.h"
  16. IMPLEMENT_SHIM_BEGIN(SetEnvironmentVariable)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_END
  20. /*++
  21. Set environment variables in the command line to get some dll path resolutions correct.
  22. --*/
  23. BOOL
  24. NOTIFY_FUNCTION(
  25. DWORD fdwReason
  26. )
  27. {
  28. if (fdwReason == DLL_PROCESS_ATTACH) {
  29. char *CmdLine = COMMAND_LINE;
  30. char *lpstrEnvName,*lpstrEnvVal,*lpstrBuf;
  31. DWORD num;
  32. while (1)
  33. {
  34. lpstrEnvName = lpstrEnvVal = CmdLine;
  35. while (*CmdLine && (*CmdLine != '|')) CmdLine++;
  36. if (*CmdLine == '|')
  37. {
  38. *CmdLine = '\0';
  39. CmdLine++;
  40. }
  41. lpstrEnvVal = CmdLine;
  42. if (0 == *lpstrEnvVal)
  43. {
  44. break;
  45. }
  46. lpstrBuf = NULL;
  47. num = 0;
  48. num = ExpandEnvironmentStringsA(lpstrEnvVal, lpstrBuf, 0);
  49. if (0 == num)
  50. {
  51. DPFN( eDbgLevelError, "Couldn't get environment strings size in the input\n %s\n", lpstrEnvVal);
  52. return TRUE;
  53. }
  54. lpstrBuf = (char*) HeapAlloc(GetProcessHeap(), 0, num+1);
  55. if (NULL == lpstrBuf)
  56. {
  57. DPFN( eDbgLevelError," Couldn't allocate memory");
  58. return TRUE;
  59. }
  60. num = ExpandEnvironmentStringsA(lpstrEnvVal,lpstrBuf,num);
  61. if (0 == num)
  62. {
  63. DPFN( eDbgLevelError, "Couldn't expand environment strings in the input\n %s\n", lpstrEnvVal);
  64. HeapFree(GetProcessHeap(),0,lpstrBuf);
  65. return TRUE;
  66. }
  67. if (SetEnvironmentVariableA(lpstrEnvName,lpstrBuf))
  68. {
  69. DPFN( eDbgLevelInfo, "Set %s to %s\n",lpstrEnvName,lpstrBuf);
  70. }
  71. else
  72. {
  73. DPFN( eDbgLevelInfo, "No Success setting %s to %s\n",lpstrEnvName,lpstrEnvVal);
  74. }
  75. if (NULL != lpstrBuf)
  76. {
  77. HeapFree(GetProcessHeap(),0,lpstrBuf);
  78. }
  79. while (*CmdLine && (*CmdLine == '|')) CmdLine++;
  80. }
  81. }
  82. return TRUE;
  83. }
  84. /*++
  85. Register hooked functions
  86. --*/
  87. HOOK_BEGIN
  88. CALL_NOTIFY_FUNCTION
  89. HOOK_END
  90. IMPLEMENT_SHIM_END