I have a C++ VSPackage that is command-line only. Setting the following Autoload registry key in my pkgdef file, does not force the VSPackage to get loaded when running devenv from the command line.
[$RootKey$\AutoLoadPackages\{ADFC4E64-0397-11D1-9F4E-00A0C911004F}]
"{75726504-cacb-4781-b384-63815a289e0a}"=dword:00000000
@="UICONTEXT_NoSolution"
However, if I add a command-line parameter, I can get the VSPackage to load as required:
[$RootKey$\AppCommandLine]
"vsp"="{75726504-cacb-4781-b384-63815a289e0a}"
[$RootKey$\AppCommandLine\vsp]
"Arguments"="0"
"DemandLoad"=dword:00000001
"Package"="{75726504-cacb-4781-b384-63815a289e0a}"
"HelpString"="#102"
The problem is that when I try to get the DTE object in the OnAfterOpenSolution event, it fails. The same code works when I run devenv in GUI mode.
Is there a better way to get my command-line vspackage to load on startup, or is there a way to get the DTE object using method I'm using above?
Here is the code I use to get DTE:
CComPtr<EnvDTE::_DTE> SinkSolutionEvents::GetDTE(CString program)
{
CString rotEntry;
rotEntry.Format(L"!VisualStudio.DTE.14.0:%d", program, GetCurrentProcessId());
IRunningObjectTable *rot = NULL;
GetRunningObjectTable(0, &rot);
IEnumMoniker *enumMoniker;
rot->EnumRunning(&enumMoniker);
enumMoniker->Reset();
ULONG fetched = 0;
IMoniker *moniker = NULL;
while (enumMoniker->Next(1, &moniker, &fetched) == 0)
{
IBindCtx *bindCtx = NULL;
CreateBindCtx(0, &bindCtx);
LPOLESTR pwszName;
HRESULT hr = moniker->GetDisplayName(bindCtx, NULL, &pwszName);
CString displayName;
if (SUCCEEDED(hr)) {
displayName = pwszName;
CoTaskMemFree(pwszName);
if (displayName == rotEntry)
{
CComPtr<IUnknown> punk;
rot->GetObject(moniker, &punk);
CComPtr<EnvDTE::_DTE> dte;
dte = punk;
return dte;
}
}
}
return NULL;
}