[399] | 1 | //////////////////////////////////////////////////////////// |
---|
| 2 | // Copyright (C) Roman Ryltsov, 2015 |
---|
| 3 | // Created by Roman Ryltsov roman@alax.info, http://alax.info |
---|
| 4 | |
---|
| 5 | #include "stdafx.h" |
---|
| 6 | |
---|
| 7 | VOID Try(const CLSID& ClassIdentifier) |
---|
| 8 | { |
---|
| 9 | CComPtr<IDispatch> pDispatch; |
---|
| 10 | ATLENSURE_SUCCEEDED(pDispatch.CoCreateInstance(ClassIdentifier)); |
---|
| 11 | CComVariant vMainWindow; |
---|
| 12 | ATLENSURE_SUCCEEDED(pDispatch.GetPropertyByName(L"MainWindow", &vMainWindow)); |
---|
| 13 | ATLASSERT(vMainWindow.vt == VT_DISPATCH); |
---|
| 14 | CComPtr<IDispatch> pMainWindowDispatch = vMainWindow.pdispVal; |
---|
| 15 | #pragma region Type Information |
---|
| 16 | UINT nTypeInfoCount; |
---|
| 17 | ATLENSURE_SUCCEEDED(pMainWindowDispatch->GetTypeInfoCount(&nTypeInfoCount)); |
---|
| 18 | _tprintf(_T("nTypeInfoCount %d\n"), nTypeInfoCount); |
---|
| 19 | ATLASSERT(nTypeInfoCount == 1); |
---|
| 20 | CComPtr<ITypeInfo> pTypeInfo; |
---|
| 21 | ATLENSURE_SUCCEEDED(pMainWindowDispatch->GetTypeInfo(0, LOCALE_USER_DEFAULT, &pTypeInfo)); |
---|
| 22 | _tprintf(_T("pTypeInfo 0x%p\n"), pTypeInfo); |
---|
| 23 | CComPtr<ITypeLib> pTypeLib; |
---|
| 24 | UINT nTypeLibIndex; |
---|
| 25 | ATLENSURE_SUCCEEDED(pTypeInfo->GetContainingTypeLib(&pTypeLib, &nTypeLibIndex)); |
---|
| 26 | _tprintf(_T("pTypeLib 0x%p, nTypeLibIndex %d\n"), pTypeLib, nTypeLibIndex); |
---|
| 27 | CComBSTR sName, sDocumentation; |
---|
| 28 | DWORD nHelpContext; |
---|
| 29 | CComBSTR sHelpPath; |
---|
| 30 | ATLENSURE_SUCCEEDED(pTypeLib->GetDocumentation(-1, &sName, &sDocumentation, &nHelpContext, &sHelpPath)); |
---|
| 31 | _tprintf(_T("sName \"%s\", sDocumentation \"%s\"\n"), CString(sName), CString(sDocumentation)); |
---|
| 32 | TLIBATTR* pLibAttr; |
---|
| 33 | ATLENSURE_SUCCEEDED(pTypeLib->GetLibAttr(&pLibAttr)); |
---|
| 34 | OLECHAR pszTypeLibraryIdentifier[64]; |
---|
| 35 | ATLVERIFY(StringFromGUID2(pLibAttr->guid, pszTypeLibraryIdentifier, _countof(pszTypeLibraryIdentifier))); |
---|
| 36 | _tprintf(_T("pLibAttr->guid %ls, lcid 0x%04X, syskind %d, wMajorVerNum %d, wMinorVerNum %d, wLibFlags 0x%X\n"), |
---|
| 37 | pszTypeLibraryIdentifier, |
---|
| 38 | pLibAttr->lcid, |
---|
| 39 | pLibAttr->syskind, |
---|
| 40 | pLibAttr->wMajorVerNum, |
---|
| 41 | pLibAttr->wMinorVerNum, |
---|
| 42 | pLibAttr->wLibFlags, |
---|
| 43 | 0); |
---|
| 44 | //pTypeLib->ReleaseTLibAttr |
---|
| 45 | #pragma endregion |
---|
| 46 | CComVariant vVisible; |
---|
| 47 | ATLENSURE_SUCCEEDED(pMainWindowDispatch.GetPropertyByName(L"Visible", &vVisible)); |
---|
| 48 | _tprintf(_T("vVisible.vt 0x%X\n"), vVisible.vt); |
---|
| 49 | _tprintf(_T("\n")); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | int _tmain(int argc, _TCHAR* argv[]) |
---|
| 53 | { |
---|
| 54 | _ATLTRY |
---|
| 55 | { |
---|
| 56 | ATLENSURE_SUCCEEDED(CoInitialize(NULL)); |
---|
| 57 | CLSID ClassIdentifier9, ClassIdentifier10; |
---|
| 58 | ATLENSURE_SUCCEEDED(CLSIDFromProgID(L"VisualStudio.DTE.9.0", &ClassIdentifier9)); |
---|
| 59 | ATLENSURE_SUCCEEDED(CLSIDFromProgID(L"VisualStudio.DTE.10.0", &ClassIdentifier10)); |
---|
| 60 | _tprintf(_T("Trying VisualStudio.DTE.9.0\n")); |
---|
| 61 | Try(ClassIdentifier9); |
---|
| 62 | _tprintf(_T("Trying VisualStudio.DTE.10.0\n")); |
---|
| 63 | Try(ClassIdentifier10); |
---|
| 64 | } |
---|
| 65 | _ATLCATCH(Exception) |
---|
| 66 | { |
---|
| 67 | _tprintf(_T("Exception 0x%08X\n"), (HRESULT) Exception); |
---|
| 68 | } |
---|
| 69 | return 0; |
---|
| 70 | } |
---|
| 71 | |
---|