كيفية القيام بما يلي: يحصل مراجع إلى الكائنات و DTE2 DTE

في the EnvDTE تجميع, the DTE كائن represents the Visual Studio integrated development بيئة (IDE) و هو the الأعلى المستوى كائن في the automation model هيكلي. الجميع automation applications must have a مرجع إلى this كائن إلى gain الوصول إلى the core automation model. That continues إلى be the حالة مع Visual Studio.

But the addition of the EnvDTE80 تجميع provides a replacement الأعلى-المستوى كائن named DTE2 which supersedes the DTE كائن. كلاهما الكائنات act و برنامج similarly, but DTE2 يحتوي على جديد functionality و hosts a رقم of جديد و محدث الكائنات و collections.

كـ a النتيجة, when creating جديد automation applications و إضافة-زر 'Ins', you should إنشاء مراجع إلى كلاهما الكائنات. The جديد DTE2 كائن provides الوصول إلى the جديد functionality, while the DTE كائن provides الوصول إلى the remainder of the core automation functionality. The جديد الكائنات و collections under DTE2 should be used instead of the الكائنات و collections في DTE whenever possible.

The following إجراءات إظهار how إلى يحصل a مرجع إلى the DTE2 كائن. (The same إجراء applies إلى the DTE كائن.) قبل adding references إلى the الكائنات, you must إضافة مراجع إلى the appropriate تجميعات و نوع مكتبة. لمزيد من المعلومات، راجع كيفية القيام بما يلي: إضافة مراجع إلى مساحات الاسم التنفيذ التلقائي.

The programmatic معرّف (‏‏معرّف البرنامج) إلى استخدم هو VisualStudio.DTE.8.0. You can then cast the returned كائن في a DTE2 واجهة.

The DTE2 خصائص, وظائف, و أحداث, when called, return the DTE أنواع. For مثال, Solution إرجاع a Solution كائن, not a Solution2 كائن كـ you might expect. This هو why, when using the DTE2 الأعضاء أو غير ذلك نوع الأعضاء, you must بوضوح typecast them. This was done intentionally for a رقم of reasons. The أول reason هو إلى يرقّي consistency و reduce confusion. The EnvDTE80 تجميع consistently إرجاع the same واجهة for الجميع of the DTE2 خصائص. Returning the latest واجهة الإصدار would be confusing. For مثال, if a future الإصدار of Visual Studio has a DTE3 نوع, then some الواجهات could return DTE, some DTE2, و some DTE3. Furthermore, it would pose توافق COM problems because the "2" الواجهات في EnvDTE80 derive من the EnvDTE الواجهات. For مثال, Window2 derives من Window. If a DTE خاصية were تمت الإضافة إلى Window2, then it would إخفاء the Windows خاصية و would not work correctly مع COM applications.

ملاحظة

قد تختلف مربعات الحوار وأوامر القائمة التى تشاهدها الان عن تلك الموصوفة في التعليمات اعتماداً على الإعدادات النشطة أو الإصدار الخاص بك. تم تطوير هذه الإجراءات من خلال "إعدادات تطوير عام" النشط. To change your settings, choose Import and Export Settings on the Tools menu. لمزيد من المعلومات، راجع العمل مع إعدادات.

إلى مرجع the DTE2 كائن في Visual أساسى

  • في your تعليمات برمجية, إضافة the following:

    ' Get an instance of the currently running Visual Studio IDE.
    Dim DTE2 as EnvDTE80.DTE2
    DTE2 = System.Runtime.InteropServices.Marshal. _
    GetActiveObject("VisualStudio.DTE2")
    
  • إلى مرجع the وحدات الماكرو IDE كائن, في your تعليمات برمجية, إضافة the following:

    ' Get an instance of the currently running Macros IDE.
    Dim DTE2 as EnvDTE80.DTE2
    Dim MacrosDTE2 as EnvDTE80.DTE2
    DTE2 = System.Runtime.InteropServices.Marshal.GetActiveObject_
    ("VisualStudio.DTE2")
    MacrosDTE2 = DTE2.MacrosIDE
    

إلى مرجع the DTE2 كائن في Visual C#‎

  • في your تعليمات برمجية, إضافة the following:

    // Get an instance of the currently running Visual Studio IDE.
    EnvDTE80.DTE2 dte2;
    dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.
    GetActiveObject("VisualStudio.DTE.8.0");
    
  • إلى مرجع the وحدات الماكرو IDE كائن, في your تعليمات برمجية, إضافة the following:

    // Get an instance of the currently running Macros IDE.
    EnvDTE80.DTE2 dte2;
    EnvDTE80.DTE2 MacrosDTE2;
    dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.
    GetActiveObject("VisualStudio.DTE.8.0");
    MacrosDTE2 = (Env80.DTE2) dte2.MacrosIDE;
    

إلى مرجع the DTE أو DTE2 كائن في Visual C++ (ATL)

  • في your تعليمات برمجية, Enter الزر the following:

    CComPtr<EnvDTE::_DTE> m_pDTE;
    CComPtr<EnvDTE80::_DTE2> m_pDTE2;
    CLSID clsid;
    CLSID clsid2;
    // The 7.1 reference works only if you have Visual Studio .NET 2003 // installed.
    CLSIDFromProgID(L"VisualStudio.DTE.7.1",&clsid);
    CLSIDFromProgID(L"VisualStudio.DTE.8.0",&clsid2);
    CComPtr<IUnknown> punk;
    CComPtr<IUnknown> punk2;
    // Get a running instance of Visual Studio.
    // The clsid reference works only if you have Visual Studio .NET 
    // 2003 installed.
    HRESULT hr = GetActiveObject(clsid,NULL,&punk);
    HRESULT hr = GetActiveObject(clsid2,NULL,&punk2);
    m_pDTE = punk;
    m_pDTE2 = punk2;
    
  • إلى مرجع the وحدات الماكرو IDE كائن, في your تعليمات برمجية, إضافة the following:

    // Get an instance of the currently runnig Macros IDE.
    CComPtr<EnvDTE80::_DTE2> m_pDTE2;
    CComPtr<EnvDTE80::_DTE2> m_pMacrosIDE;
    CLSID clsid;
    CLSIDFromProgID(L"VisualStudio.DTE.8.0",&clsid);
    CComPtr<IUnknown> punk;
    HRESULT hr = GetActiveObject(clsid,NULL,&punk);
    m_pDTE = punk;
    m_pDTE->get_MacrosIDE((void **)&m_pMacrosIDE);
    

راجع أيضًا:

المهام

كيفية القيام بما يلي: إضافة مراجع إلى مساحات الاسم التنفيذ التلقائي

كيفية القيام بما يلي: عنصر تحكم إضافة الإضافية باستخدام إدارة زر 'Ins' الإضافية

المبادئ

وصل إلى مثيلات IDE محددة

إضافة-في التسجيل

مخطط نموذج كائن تلقائي

موارد أخرى

إنشاء إضافة-زر 'Ins' ومعالجات