COM.nsh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. -------------
  3. COM.nsh
  4. -------------
  5. COM defines and helper macros
  6. ; Example usage:
  7. !include LogicLib.nsh
  8. !include Win\COM.nsh
  9. !include Win\Propkey.nsh
  10. !insertmacro ComHlpr_CreateInProcInstance ${CLSID_ShellLink} ${IID_IShellLink} r0 ""
  11. ${If} $0 P<> 0
  12. ${IShellLink::SetPath} $0 '("%COMSPEC%").r1'
  13. ${IShellLink::SetArguments} $0 '("/k echo HelloWorld").r2'
  14. ${If} $1 = 0
  15. ${AndIf} $2 = 0
  16. ${IUnknown::QueryInterface} $0 '("${IID_IPropertyStore}",.r1)'
  17. ${If} $1 P<> 0
  18. System::Call '*${SYSSTRUCT_PROPERTYKEY}(${PKEY_AppUserModel_StartPinOption})p.r2'
  19. System::Call '*${SYSSTRUCT_PROPVARIANT}(${VT_UI4},,&i4 ${APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL})p.r3'
  20. ${IPropertyStore::SetValue} $1 '($2,$3)'
  21. ; Reuse the PROPERTYKEY & PROPVARIANT buffers to set another property
  22. System::Call '*$2${SYSSTRUCT_PROPERTYKEY}(${PKEY_AppUserModel_ExcludeFromShowInNewInstall})'
  23. System::Call '*$3${SYSSTRUCT_PROPVARIANT}(${VT_BOOL},,&i2 ${VARIANT_TRUE})'
  24. ${IPropertyStore::SetValue} $1 '($2,$3)'
  25. System::Free $2
  26. System::Free $3
  27. ${IPropertyStore::Commit} $1 ""
  28. ${IUnknown::Release} $1 ""
  29. ${EndIf}
  30. ${IUnknown::QueryInterface} $0 '("${IID_IPersistFile}",.r1)'
  31. ${If} $1 P<> 0
  32. ${IPersistFile::Save} $1 '("$SMPrograms\nsis_test.lnk",1)'
  33. ${IUnknown::Release} $1 ""
  34. ${EndIf}
  35. ${EndIf}
  36. ${IUnknown::Release} $0 ""
  37. ${EndIf}
  38. */
  39. !ifndef __WIN_COM__INC
  40. !define __WIN_COM__INC ${NSIS_CHAR_SIZE}
  41. !verbose push
  42. !verbose 3
  43. !define /ifndef CLSCTX_INPROC_SERVER 0x1
  44. !define /ifndef CLSCTX_INPROC_HANDLER 0x2
  45. !define /ifndef CLSCTX_LOCAL_SERVER 0x4
  46. !define /ifndef CLSCTX_REMOTE_SERVER 0x10
  47. !define /ifndef CLSCTX_ACTIVATE_32_BIT_SERVER 0x40000
  48. !define /ifndef CLSCTX_ACTIVATE_64_BIT_SERVER 0x80000
  49. !define /ifndef CLSCTX_ENABLE_CLOAKING 0x100000
  50. !define NSISCOMCALL "!insertmacro NSISCOMCALL "
  51. !macro NSISCOMCALL vtblidx decl ptr params
  52. !if ${NSIS_CHAR_SIZE} <> ${__WIN_COM__INC}
  53. ; Warn if QueryInterface() for IID_IShellLink etc will return the wrong interface
  54. !warning "NSIS_CHAR_SIZE changed, existing defines and macros might not work correctly!"
  55. !endif
  56. System::Call `${ptr}->${vtblidx}${decl}${params}`
  57. !macroend
  58. !define NSISCOMIFACEDECL "!insertmacro NSISCOMIFACEDECL "
  59. !macro NSISCOMIFACEDECL iface method vtblidx decl
  60. !define ${iface}::${method} `${NSISCOMCALL} ${vtblidx} ${decl} `
  61. !macroend
  62. !macro ComHlpr_CreateInstance clsid iid sysoutvarIFacePtr sysret
  63. System::Call 'OLE32::CoCreateInstance(g"${clsid}",i0,i23,g"${iid}",*p.${sysoutvarIFacePtr})i${sysret}'
  64. !macroend
  65. !macro ComHlpr_CreateInProcInstance clsid iid sysoutvarIFacePtr sysret
  66. System::Call 'OLE32::CoCreateInstance(g"${clsid}",i0,i${CLSCTX_INPROC_SERVER},g"${iid}",*p.${sysoutvarIFacePtr})i${sysret}'
  67. !macroend
  68. !macro ComHlpr_SafeRelease _p
  69. ${If} ${_p} P<> 0
  70. ${IUnknown::Release} ${_p} ""
  71. ${EndIf}
  72. !macroend
  73. !macro ComHlpr_SafeReleaseAndNull _p
  74. ${If} ${_p} P<> 0
  75. ${IUnknown::Release} ${_p} ""
  76. StrCpy ${_p} 0
  77. ${EndIf}
  78. !macroend
  79. !ifndef IID_IUnknown
  80. !define IID_IUnknown {00000000-0000-0000-C000-000000000046}
  81. ${NSISCOMIFACEDECL}IUnknown QueryInterface 0 (g,*p)i
  82. ${NSISCOMIFACEDECL}IUnknown AddRef 1 ()i
  83. ${NSISCOMIFACEDECL}IUnknown Release 2 ()i
  84. !endif
  85. !ifndef IID_IPersist
  86. !define IID_IPersist {0000010c-0000-0000-C000-000000000046}
  87. ${NSISCOMIFACEDECL}IPersist GetClassID 3 (g)i
  88. !endif
  89. !ifndef IID_IPersistFile
  90. !define IID_IPersistFile {0000010b-0000-0000-C000-000000000046}
  91. ${NSISCOMIFACEDECL}IPersistFile IsDirty 4 ()i
  92. ${NSISCOMIFACEDECL}IPersistFile Load 5 (w,i)i
  93. ${NSISCOMIFACEDECL}IPersistFile Save 6 (w,i)i
  94. ${NSISCOMIFACEDECL}IPersistFile SaveCompleted 7 (w)i
  95. ${NSISCOMIFACEDECL}IPersistFile GetCurFile 8 (*w)i
  96. !endif
  97. !ifndef CLSID_ShellLink
  98. !define CLSID_ShellLink {00021401-0000-0000-c000-000000000046}
  99. !endif
  100. !ifndef IID_IShellLink
  101. !define IID_IShellLinkA {000214ee-0000-0000-c000-000000000046}
  102. !define IID_IShellLinkW {000214f9-0000-0000-c000-000000000046}
  103. !ifdef NSIS_UNICODE
  104. !define IID_IShellLink ${IID_IShellLinkW}
  105. !else
  106. !define IID_IShellLink ${IID_IShellLinkA}
  107. !endif
  108. ${NSISCOMIFACEDECL}IShellLink GetPath 3 (t,i,p,i)i
  109. ${NSISCOMIFACEDECL}IShellLink GetIDList 4 (*p)i
  110. ${NSISCOMIFACEDECL}IShellLink SetIDList 5 (p)i
  111. ${NSISCOMIFACEDECL}IShellLink GetDescription 6 (t,i)i
  112. ${NSISCOMIFACEDECL}IShellLink SetDescription 7 (t)i
  113. ${NSISCOMIFACEDECL}IShellLink GetWorkingDirectory 8 (t,i)i
  114. ${NSISCOMIFACEDECL}IShellLink SetWorkingDirectory 9 (t)i
  115. ${NSISCOMIFACEDECL}IShellLink GetArguments 10 (t,i)i
  116. ${NSISCOMIFACEDECL}IShellLink SetArguments 11 (t)i
  117. ${NSISCOMIFACEDECL}IShellLink GetHotkey 12 (*i0)i
  118. ${NSISCOMIFACEDECL}IShellLink SetHotkey 13 (&i2)i
  119. ${NSISCOMIFACEDECL}IShellLink GetShowCmd 14 (*i)i
  120. ${NSISCOMIFACEDECL}IShellLink SetShowCmd 15 (i)i
  121. ${NSISCOMIFACEDECL}IShellLink GetIconLocation 16 (t,i,*i)i
  122. ${NSISCOMIFACEDECL}IShellLink SetIconLocation 17 (t,i)i
  123. ${NSISCOMIFACEDECL}IShellLink SetRelativePath 18 (t,i)i
  124. ${NSISCOMIFACEDECL}IShellLink Resolve 19 (p,i)i
  125. ${NSISCOMIFACEDECL}IShellLink SetPath 20 (t)i
  126. !endif
  127. !ifndef IID_IShellLinkDataList
  128. !define IID_IShellLinkDataList {45e2b4ae-b1c3-11d0-b92f-00a0c90312e1}
  129. ${NSISCOMIFACEDECL}IShellLinkDataList AddDataBlock 3 (p)i
  130. ${NSISCOMIFACEDECL}IShellLinkDataList CopyDataBlock 4 (i,*p)i
  131. ${NSISCOMIFACEDECL}IShellLinkDataList RemoveDataBlock 5 (i)i
  132. ${NSISCOMIFACEDECL}IShellLinkDataList GetFlags 6 (*i)i
  133. ${NSISCOMIFACEDECL}IShellLinkDataList SetFlags 7 (i)i
  134. !endif
  135. !define /ifndef EXP_SZ_LINK_SIG 0xA0000001
  136. !define /ifndef NT_CONSOLE_PROPS_SIG 0xA0000002
  137. !define /ifndef NT_FE_CONSOLE_PROPS_SIG 0xA0000004
  138. !define /ifndef EXP_SPECIAL_FOLDER_SIG 0xA0000005
  139. !define /ifndef EXP_DARWIN_ID_SIG 0xA0000006
  140. !define /ifndef EXP_SZ_ICON_SIG 0xA0000007
  141. !define /ifndef EXP_PROPERTYSTORAGE_SIG 0xA0000009
  142. ;SHELL_LINK_DATA_FLAGS
  143. !define /ifndef SLDF_HAS_ID_LIST 0x00000001
  144. !define /ifndef SLDF_HAS_LINK_INFO 0x00000002
  145. !define /ifndef SLDF_HAS_NAME 0x00000004
  146. !define /ifndef SLDF_HAS_RELPATH 0x00000008
  147. !define /ifndef SLDF_HAS_WORKINGDIR 0x00000010
  148. !define /ifndef SLDF_HAS_ARGS 0x00000020
  149. !define /ifndef SLDF_HAS_ICONLOCATION 0x00000040
  150. !define /ifndef SLDF_UNICODE 0x00000080
  151. !define /ifndef SLDF_FORCE_NO_LINKINFO 0x00000100
  152. !define /ifndef SLDF_HAS_EXP_SZ 0x00000200
  153. !define /ifndef SLDF_RUN_IN_SEPARATE 0x00000400
  154. !define /ifndef SLDF_HAS_LOGO3ID 0x00000800
  155. !define /ifndef SLDF_HAS_DARWINID 0x00001000
  156. !define /ifndef SLDF_RUNAS_USER 0x00002000
  157. !define /ifndef SLDF_HAS_EXP_ICON_SZ 0x00004000
  158. !define /ifndef SLDF_NO_PIDL_ALIAS 0x00008000
  159. !define /ifndef SLDF_FORCE_UNCNAME 0x00010000
  160. !define /ifndef SLDF_RUN_WITH_SHIMLAYER 0x00020000
  161. !define /ifndef SLDF_FORCE_NO_LINKTRACK 0x00040000 ;[Vista+]
  162. !define /ifndef SLDF_ENABLE_TARGET_METADATA 0x00080000
  163. !define /ifndef SLDF_DISABLE_LINK_PATH_TRACKING 0x00100000 ;[Seven+]
  164. !define /ifndef SLDF_DISABLE_KNOWNFOLDER_RELATIVE_TRACKING 0x00200000
  165. !define /ifndef SLDF_NO_KF_ALIAS 0x00400000
  166. !define /ifndef SLDF_ALLOW_LINK_TO_LINK 0x00800000
  167. !define /ifndef SLDF_UNALIAS_ON_SAVE 0x01000000
  168. !define /ifndef SLDF_PREFER_ENVIRONMENT_PATH 0x02000000
  169. !define /ifndef SLDF_KEEP_LOCAL_IDLIST_FOR_UNC_TARGET 0x04000000
  170. !define /ifndef SLDF_PERSIST_VOLUME_ID_RELATIVE 0x08000000 ;[Eight+]
  171. !ifndef IID_IShellItem
  172. !define IID_IShellItem {43826d1e-e718-42ee-bc55-a1e261c37bfe}
  173. ${NSISCOMIFACEDECL}IShellItem BindToHandler 3 (p,g,g,*p)i
  174. ${NSISCOMIFACEDECL}IShellItem GetParent 4 (*p)i
  175. ${NSISCOMIFACEDECL}IShellItem GetDisplayName 5 (i,*p)i
  176. ${NSISCOMIFACEDECL}IShellItem GetAttributes 6 (i,*i)i
  177. ${NSISCOMIFACEDECL}IShellItem Compare 7 (p,i,*i)i
  178. !endif
  179. !ifndef CLSID_StartMenuPin
  180. !define CLSID_StartMenuPin {a2a9545d-a0c2-42b4-9708-a0b2badd77c8}
  181. !endif
  182. !ifndef IID_IStartMenuPinnedList
  183. !define IID_IStartMenuPinnedList {4CD19ADA-25A5-4A32-B3B7-347BEE5BE36B}
  184. ${NSISCOMIFACEDECL}IStartMenuPinnedList RemoveFromList 3 (p)i
  185. !endif
  186. !ifndef IID_IPropertyStore
  187. !define IID_IPropertyStore {886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99}
  188. ${NSISCOMIFACEDECL}IPropertyStore GetCount 3 (*i)i
  189. ${NSISCOMIFACEDECL}IPropertyStore GetAt 4 (i,p)i
  190. ${NSISCOMIFACEDECL}IPropertyStore GetValue 5 (p,p)i
  191. ${NSISCOMIFACEDECL}IPropertyStore SetValue 6 (p,p)i
  192. ${NSISCOMIFACEDECL}IPropertyStore Commit 7 ()i
  193. !endif
  194. !ifndef CLSID_ApplicationAssociationRegistration
  195. !define CLSID_ApplicationAssociationRegistration {591209c7-767b-42b2-9fba-44ee4615f2c7}
  196. !endif
  197. !ifndef IID_IApplicationAssociationRegistration
  198. !define IID_IApplicationAssociationRegistration {4e530b0a-e611-4c77-a3ac-9031d022281b} ;[Vista+]
  199. ${NSISCOMIFACEDECL}IApplicationAssociationRegistration QueryCurrentDefault 3 (w,i,i,*p)i
  200. ${NSISCOMIFACEDECL}IApplicationAssociationRegistration QueryAppIsDefault 4 (w,i,i,w,*i)i
  201. ${NSISCOMIFACEDECL}IApplicationAssociationRegistration QueryAppIsDefaultAll 5 (i,w,*i)i
  202. ${NSISCOMIFACEDECL}IApplicationAssociationRegistration SetAppAsDefault 6 (w,w,i)i
  203. ${NSISCOMIFACEDECL}IApplicationAssociationRegistration SetAppAsDefaultAll 7 (w)i
  204. ${NSISCOMIFACEDECL}IApplicationAssociationRegistration ClearUserAssociations 8 ()i
  205. !endif
  206. !ifndef CLSID_ApplicationAssociationRegistrationUI
  207. !define CLSID_ApplicationAssociationRegistrationUI {1968106d-f3b5-44cf-890e-116fcb9ecef1}
  208. !endif
  209. !ifndef IID_IApplicationAssociationRegistrationUI
  210. !define IID_IApplicationAssociationRegistrationUI {1f76a169-f994-40ac-8fc8-0959e8874710} ;[Vista+]
  211. ${NSISCOMIFACEDECL}IApplicationAssociationRegistrationUI LaunchAdvancedAssociationUI 3 (w)i
  212. !endif
  213. !ifndef CLSID_GameExplorer
  214. !define CLSID_GameExplorer {9A5EA990-3034-4D6F-9128-01F3C61022BC}
  215. !endif
  216. !ifndef IID_IGameExplorer
  217. !define IID_IGameExplorer {E7B2FB72-D728-49B3-A5F2-18EBF5F1349E} ;[Vista+]
  218. ${NSISCOMIFACEDECL}IGameExplorer AddGame 3 (p,p,i,g)i
  219. ${NSISCOMIFACEDECL}IGameExplorer RemoveGame 4 (i,i,i,i)i ; The parameter is a GUID, not REFGUID so the 'g' type cannot be used!
  220. ${NSISCOMIFACEDECL}IGameExplorer UpdateGame 5 (i,i,i,i)i
  221. ${NSISCOMIFACEDECL}IGameExplorer VerifyAccess 6 (p,*i)i
  222. !endif
  223. !define /ifndef GIS_NOT_INSTALLED 1
  224. !define /ifndef GIS_CURRENT_USER 2
  225. !define /ifndef GIS_ALL_USERS 3
  226. !ifndef IID_IGameExplorer2
  227. !define IID_IGameExplorer2 {86874AA7-A1ED-450d-A7EB-B89E20B2FFF3} ;[Seven+]
  228. ${NSISCOMIFACEDECL}IGameExplorer2 InstallGame 3 (w,w,i)i
  229. ${NSISCOMIFACEDECL}IGameExplorer2 UninstallGame 4 (w)i
  230. ${NSISCOMIFACEDECL}IGameExplorer2 CheckAccess 5 (w,*i)i
  231. !endif
  232. !ifndef CLSID_GameStatistics
  233. !define CLSID_GameStatistics {DBC85A2C-C0DC-4961-B6E2-D28B62C11AD4}
  234. !endif
  235. !ifndef IID_IGameStatisticsMgr
  236. !define IID_IGameStatisticsMgr {AFF3EA11-E70E-407d-95DD-35E612C41CE2} ;[Seven+]
  237. ${NSISCOMIFACEDECL}IGameStatisticsMgr GetGameStatistics 3 (w,i,*i,*p)i
  238. ${NSISCOMIFACEDECL}IGameStatisticsMgr RemoveGameStatistics 4 (w)i
  239. !endif
  240. !verbose pop
  241. !endif /* __WIN_COM__INC */