#include <Windows.h>
#include <shlobj_core.h> #pragma comment(lib,"Shell32.lib") class ProcessReference : public IUnknown {
public:
STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IUnknown) {
*ppv = static_cast<IUnknown*>(this);
AddRef();
return S_OK;
}
*ppv = NULL; return E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) AddRef()
{
return InterlockedIncrement(&m_cRef);
}
STDMETHODIMP_(ULONG) Release()
{
LONG lRef = InterlockedDecrement(&m_cRef);
if (lRef == ) PostThreadMessage(m_dwThread, WM_NULL, , );
return lRef;
}
ProcessReference()
: m_cRef(), m_dwThread(GetCurrentThreadId())
{
SHSetInstanceExplorer(this);
}
~ProcessReference()
{
SHSetInstanceExplorer(NULL);
Release();
MSG msg;
while (m_cRef && GetMessage(&msg, NULL, , )) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
private:
LONG m_cRef;
DWORD m_dwThread;
}; int main()
{
struct CoInit { HRESULT m_hr; CoInit() { m_hr = CoInitialize(); } ~CoInit() { if (SUCCEEDED(m_hr)) CoUninitialize(); } } coinit;
ProcessReference ref;
IShellItem*pSI;
HRESULT hr = SHCreateItemInKnownFolder(FOLDERID_Windows, KF_FLAG_DEFAULT, L"Explorer.exe", IID_IShellItem, (void**)&pSI);
if (hr) return hr;
IContextMenu*pCM;
hr = pSI->BindToHandler(NULL, BHID_SFUIObject, IID_IContextMenu, (void**)&pCM);
pSI->Release();
if (hr) return hr;
SHELLEXECUTEINFO info = { }; info.cbSize = sizeof info;
info.lpFile = "C:\\Users\\strives\\Desktop\\print.txt";
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_INVOKEIDLIST;
info.lpVerb = "properties"; ShellExecuteEx(&info);
}

另外参考: Reading a contract from the other side: SHSetInstanceExplorer and SHGetInstanceExplorer

链接是介绍 SHSetInstanceExplorer 的用法

最新文章

  1. 部署额外域控制器,Active Directory
  2. 自动备份文件到GITHUB的方法
  3. Atitit.&#160;Atiposter&#160;发帖机 新特性 poster new feature v11 &#160;.docx
  4. [CSS]理解line-height
  5. Android应用开发学习笔记之Intent
  6. 【转】深受开发者喜爱的10大Core Data工具和开源库
  7. 记录下sublime text快捷方式
  8. Broken line - SGU 124(判断点与多边形的关系)
  9. [Android]Dalvik的BOOTCLASSPATH和dexopt流程
  10. HEVC码率控制浅析——HM代码阅读之二
  11. 【转】在PC上测试移动端网站和模拟手机浏览器的5大方法
  12. 【2017-04--28】Winform中ListView控件
  13. informatica 学习总结
  14. SeaJS之shim插件:解决非cmd规范的插件与sea的区别
  15. TensorFlow实现线性回归模型代码
  16. iOS 小米推送总结和遇到的坑
  17. Windows下Oracle 11g的下载与安装
  18. awk 和 sed (Stream Editor)
  19. 如何看待阿里 AI 每秒制作 8000 张海报?
  20. Web API: Security: Authentication and Authority

热门文章

  1. 从txt导入数据到mysql
  2. 使用conda安装命令时一直出现问题,因为从2019年4月添加的国内镜像都不能用了
  3. 创建策略(Creation Policy )和生命周期(Life Cycle)
  4. 阶段3 2.Spring_09.JdbcTemplate的基本使用_6 JdbcDaoSupport的使用以及Dao的两种编写方式
  5. mybatis整合spring,使用org.mybatis.spring.mapper.MapperScannerConfigurer扫描出现问题
  6. java课堂疑问解答与思考1
  7. SSM笔记
  8. POJ 2253 Frogger(dijkstra 最短路
  9. Luogu P1650 田忌赛马
  10. golang 反射中调用方法