NCMsiHelper.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) by Michael Schuster <michael@schuster.ms>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * Parts of this file are based on:
  15. * https://www.codeproject.com/articles/570751/devmsi-an-example-cplusplus-msi-wix-deferred-custo
  16. *
  17. * Licensed under the The Code Project Open License (CPOL):
  18. * https://www.codeproject.com/info/cpol10.aspx
  19. *
  20. */
  21. /**
  22. * Function prototypes for external "C" interfaces into the DLL.
  23. *
  24. * This project builds a "hybrid" DLL that will work either from
  25. * a MSI Custom Action environment or from an external C program.
  26. * The former routes through "C" interface functions defined in
  27. * CustomAction.def. The latter uses the interfaces defined here.
  28. *
  29. * This header is suitable for inclusion by a project wanting to
  30. * call these methods. Note that _NCMSIHELPER_EXPORTS should not be
  31. * defined for the accessing application source code.
  32. */
  33. #pragma once
  34. #include <windows.h>
  35. #ifdef _NCMSIHELPER_EXPORTS
  36. # pragma comment (lib, "newdev")
  37. # pragma comment (lib, "setupapi")
  38. # pragma comment (lib, "msi")
  39. # pragma comment (lib, "dutil")
  40. # pragma comment (lib, "wcautil")
  41. # pragma comment (lib, "Version")
  42. # include <cstdlib>
  43. # include <string>
  44. # include <tchar.h>
  45. # include <msiquery.h>
  46. # include <lmerr.h>
  47. // WiX Header Files:
  48. # include <wcautil.h>
  49. # include <strutil.h>
  50. # define NCMSIHELPER_API __declspec(dllexport)
  51. #else
  52. # define NCMSIHELPER_API __declspec(dllimport)
  53. #endif
  54. /**
  55. * Runs the NSIS uninstaller and waits for its completion.
  56. *
  57. * argc MUST be 2.
  58. *
  59. * argv[0] is APPLICATION_EXECUTABLE, e.g. "nextcloud"
  60. * argv[1] is the full path to "Uninstall.exe"
  61. *
  62. * @param argc The count of valid arguments in argv.
  63. * @param argv An array of string arguments for the function.
  64. * @return Returns an HRESULT indicating success or failure.
  65. */
  66. HRESULT NCMSIHELPER_API DoExecNsisUninstaller(int argc, LPWSTR *argv);
  67. /**
  68. * Removes the Explorer's Navigation Pane entries.
  69. *
  70. * argc MUST be 1.
  71. *
  72. * argv[0] is APPLICATION_NAME, e.g. "Nextcloud"
  73. *
  74. * @param argc The count of valid arguments in argv.
  75. * @param argv An array of string arguments for the function.
  76. * @return Returns an HRESULT indicating success or failure.
  77. */
  78. HRESULT NCMSIHELPER_API DoRemoveNavigationPaneEntries(int argc, LPWSTR *argv);
  79. /**
  80. * Standardized function prototype for NCMsiHelper.
  81. *
  82. * Functions in NCMsiHelper can be called through the MSI Custom
  83. * Action DLL or through an external C program. Both
  84. * methods expect to wrap things into this function prototype.
  85. *
  86. * As a result, all functions defined in this header should
  87. * conform to this function prototype.
  88. */
  89. using CUSTOM_ACTION_ARGC_ARGV = NCMSIHELPER_API HRESULT(*)(int argc, LPWSTR *argv);