Skip to content

Instantly share code, notes, and snippets.

@lxfly2000
Created July 25, 2022 09:24
Show Gist options
  • Save lxfly2000/bfdf2a900b065cce405f1dfa8630e579 to your computer and use it in GitHub Desktop.
Save lxfly2000/bfdf2a900b065cce405f1dfa8630e579 to your computer and use it in GitHub Desktop.
VC++调用WSH(COM组件)的方法
#include <Windows.h>
#undef GetFreeSpace
//若不在行尾加no_namespace则需要在引用接口时使用IWshRuntimeLibrary命名空间
#import "C:\Windows\System32\wshom.ocx"
#include "Debug\wshom.tlh"
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")//使用视觉样式
int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
{
SetProcessDPIAware();
CoInitialize(0);
IWshRuntimeLibrary::IWshShell3Ptr wsh;
wsh.CreateInstance(TEXT("WScript.Shell"));
wsh->Popup(_bstr_t("Hello COM!"), &_variant_t(10), &_variant_t("wsh"),&_variant_t(64));
wsh.Release();
CoUninitialize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment