Я думаю, вы также можете сделать это динамически.Я делюсь кодом для c ++:
Где-то рядом с началом:
#include <atlbase.h>
#pragma warning( disable : 4278 )
#pragma warning( disable : 4146 )
//The following #import imports EnvDTE based on its LIBID.
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") lcid("0") raw_interfaces_only named_guids
//The following #import imports EnvDTE80 based on its LIBID.
#import "libid:1A31287A-4D7D-413e-8E32-3B374931BD89" version("8.0") lcid("0") raw_interfaces_only named_guids
//The following #import imports EnvDTE90 based on its LIBID.
#import "libid:2ce2370e-d744-4936-a090-3fffe667b0e1" version("9.0") lcid("0") raw_interfaces_only named_guids
//The following #import imports EnvDTE100 based on its LIBID. - This doesn't work for me
//#import "libid:26ad1324-4b7c-44bc-84f8-b86aed45729f" version("10.0") lcid("0") raw_interfaces_only named_guids
#pragma warning( default : 4146 )
#pragma warning( default : 4278 )
Тогда что-то в основном:
CoInitialize(NULL);
CComPtr<EnvDTE::_DTE> m_pDTE;
CComPtr<EnvDTE80::DTE2> m_pDTE2;
CLSID clsid;
CLSID clsid2;
CLSIDFromProgID(L"VisualStudio.DTE.10.0",&clsid);
CLSIDFromProgID(L"VisualStudio.DTE.10.0",&clsid2);
CComPtr<IUnknown> punk;
CComPtr<IUnknown> punk2;
// Get a running instance of Visual Studio.
HRESULT hr = GetActiveObject(clsid,NULL,&punk);
hr = GetActiveObject(clsid2,NULL,&punk2);
m_pDTE = punk;
m_pDTE2 = punk2;
EnvDTE::DebuggerPtr p_dbg;
while(FAILED(m_pDTE2->get_Debugger(&p_dbg)))
{
}
bool Sucess = false;
do
{
EnvDTE::ProcessesPtr p_processes;
while(FAILED(p_dbg->get_LocalProcesses(&p_processes)))
{
}
long max;
if(FAILED(p_processes->get_Count(&max)))
{
std::cerr << "Failed to obtain process count.";
return 2;
}
for(long i = 0; i < max; ++i)
{
EnvDTE::ProcessPtr p_process;
// Get item and check for process id if any
if(FAILED(p_processes->Item(variant_t(i), &p_process)))
continue;
if(p_process != nullptr)
{
long process_id;
while(FAILED(p_process->get_ProcessID(&process_id)))
{
}
if(process_id == GetProcessId(GetCurrentProcess()))
{
p_process->Attach();
Sucess = true;
break;
}
}
}
} while(!Sucess);
Надеюсь, это кому-нибудь поможет.