Сущность технологии СОМ. Библиотека программиста :: Бокс Дональд
Страница: 198 из 199 | |||
| ||||||||||||||
| ||||||||||||||
КАТЕГОРИИ КНИГПОСЛЕДНИЕ ОТЗЫВЫ О КНИГАХМихаил (19.04.2017 - 06:11:11) Антихрист666 (18.04.2017 - 21:05:58) Ладно, теперь поспешили вы... (18.04.2017 - 20:50:34) Роман (18.04.2017 - 18:12:26) АНДРЕЙ (18.04.2017 - 16:42:55) СЛУЧАЙНОЕ ПРОИЗВЕДЕНИЕНе жди, в моих глазах печали нет. 30.06.10 - 05:35 Хотите чтобы ваше произведение или ваш любимый стишок появились здесь? добавьте его! |
Поделись ссылкой Сущность технологии СОМ. Библиотека программиста :: Бокс Дональд
erase(it);
hr = S_OK; } Unlock(); } else hr = E_ACCESSDENIED; CoTaskMemFree(pwszUser); return hr; } // class SessionNamesEnumerator vector SessionNamesEnumerator::Strings(void) { if (m_pStrings) return *m_pStrings; else return *(m_pCloneSource->m_pStrings); } void SessionNamesEnumerator::Lock(void) { EnterCriticalSection(&m_csLock); } void SessionNamesEnumerator::Unlock(void) { LeaveCriticalSection(&m_csLock); } SessionNamesEnumerator::SessionNamesEnumerator( ChatSessionClass *pSessionClass) : m_cRef(0), m_pStrings(0), m_pCloneSource(0) { typedef ChatSessionClass::SESSIONMAP::iterator iterator; ChatSessionClass::SESSIONMAP &sessions = pSessionClass->m_sessions; m_pStrings = new vector pSessionClass->Lock(); for (iterator it = sessions.begin(); it != sessions.end(); it++) { m_pStrings->push_back((*it).first); } pSessionClass->Unlock(); m_cursor = Strings().begin(); InitializeCriticalSection(&m_csLock); } SessionNamesEnumerator::SessionNamesEnumerator( SessionNamesEnumerator *pCloneSource) : m_cRef(0), m_pStrings(0), m_pCloneSource(pCloneSource) { m_pCloneSource->AddRef(); m_cursor = Strings().begin(); InitializeCriticalSection(&m_csLock); } SessionNamesEnumerator::~SessionNamesEnumerator(void) { if (m_pCloneSource) m_pCloneSource->Release(); else if (m_pStrings) delete m_pStrings; DeleteCriticalSection(&m_csLock); } // IUnknown methods STDMETHODIMP SessionNamesEnumerator::QueryInterface(REFIID riid, void **ppv) { if (riid == IID_IUnknown) *ppv = static_cast else if (riid == IID_IEnumString) *ppv = static_cast else return (*ppv = 0), E_NOINTERFACE; reinterpret_cast return S_OK; } STDMETHODIMP_(ULONG) SessionNamesEnumerator::AddRef(void) { ModuleLock(); return InterlockedIncrement(&m_cRef); } STDMETHODIMP_(ULONG) SessionNamesEnumerator::Release(void) { LONG res = InterlockedDecrement(&m_cRef); if (res == 0) delete this; ModuleUnlock(); return res; } // IEnumString methods STDMETHODIMP SessionNamesEnumerator::Next(ULONG cElems, OLECHAR **rgElems, ULONG *pcFetched) { if (cElems > 1 && pcFetched == 0) return E_INVALIDARG; ULONG cActual = 0; vector Lock(); while (cActual < cElems && m_cursor != rstrings.end()) { if (rgElems[cActual] = OLESTRDUP((*m_cursor).c_str())) { m_cursor++; cActual++; } else // allocation error, unwind { while (cActual > 0) { cActual–; CoTaskMemFree(rgElems[cActual]); rgElems[cActual] = 0; } break; } } Unlock(); if (cActual) *pcFetched = cActual; return cActual == cElems ? S_OK : S_FALSE; } STDMETHODIMP SessionNamesEnumerator::Skip(ULONG cElems) { ULONG cActual = 0; vector Lock(); while (cActual < cElems && m_cursor != rstrings.end()) { m_cursor++; cActual++; } Unlock(); return cActual == cElems ? S_OK : S_FALSE; } STDMETHODIMP SessionNamesEnumerator::Reset(void) { Lock(); m_cursor = Strings().begin(); Unlock(); return S_OK; } STDMETHODIMP SessionNamesEnumerator::Clone(IEnumString **ppes) { if (ppes == 0) return E_INVALIDARG; SessionNamesEnumerator *pCloneSource = m_pCloneSource; if (pCloneSource == 0) // we are the source m_pCloneSource = this; *ppes = new SessionNamesEnumerator(pCloneSource); if (*ppes) { (*ppes)->AddRef(); return S_OK; } return E_OUTOFMEMORY; } svc.cpp ///////////////////////////////////////////////////// // // svc.cpp // // Copyright 1997, Don Box/Addison Wesley // // This code accompanies the book "The Component // Object Model" from Addison Wesley. Blah blah blah // // #define _WIN32_WINNT 0x403 #include #include #include #include #include «ChatSession.h» #include «../include/COMChat_i.c» #if !defined(HAVE_IID_IACCESSCONTROL) // there is a common bug is the SDK headers and libs // that causes IID_IAccessControl to be undefined. // We define it here to give the GUID linkage. DEFINE_GUID(IID_IAccessControl,0xEEDD23E0, 0x8410, 0x11CE, 0xA1, 0xC3, 0x08, 0x00, 0x2B, 0x2B, 0x8D, 0x8F); #endif // standard MTA lifetime management helpers HANDLE g_heventDone = CreateEvent(0, TRUE, FALSE, 0); void ModuleLock(void) { CoAddRefServerProcess(); } void ModuleUnlock(void) { if (CoReleaseServerProcess() == 0) SetEvent(g_heventDone); } // standard self-registration table const char *g_RegTable[][3] = { { «CLSID\\», 0, «ChatSession» }, { «CLSID\\», «AppId», «» }, { «CLSID\\\\LocalServer32», 0, (const char*)-1 // rogue value indicating file name }, { «AppID\\», 0, «ChatSession Server» }, { «AppID\\», «RunAs», «Domain\\ReplaceMe» }, { «AppID\\», «Chat Admins Group», «Domain\\ReplaceMe» }, { «AppID\\», «Chat Users Group», «Domain\\ReplaceMe» }, { «AppID\\COMChat.exe», «AppId», «» }, }; // self-unregistration routine STDAPI UnregisterServer(void) { HRESULT hr = S_OK; int nEntries = sizeof(g_RegTable)/sizeof(*g_RegTable); for (int i = nEntries – 1; i >= 0; i–){ const char *pszKeyName = g_RegTable[i][0]; long err = RegDeleteKeyA(HKEY_CLASSES_ROOT, pszKeyName); if (err != ERROR_SUCCESS) hr = S_FALSE; } return hr; } // self-registration routine STDAPI RegisterServer(HINSTANCE hInstance = 0) { HRESULT hr = S_OK; // look up server's file name char szFileName[MAX_PATH]; GetModuleFileNameA(hInstance, szFileName, MAX_PATH); // register entries from table int nEntries = sizeof(g_RegTable)/sizeof(*g_RegTable); for (int i = 0; SUCCEEDED(hr) && i < nEntries; i++) { const char *pszKeyName = g_RegTable[i][0]; const char *pszValueName = g_RegTable[i][1]; const char *pszValue = g_RegTable[i][2]; // map rogue value to module file name if (pszValue == (const char*)-1) pszValue = szFileName; HKEY hkey; // create the key long err = RegCreateKeyA(HKEY_CLASSES_ROOT, pszKeyName, &hkey); if (err == ERROR_SUCCESS) { // set the value err = RegSetValueExA(hkey, pszValueName, 0, REG_SZ, (const BYTE*)pszValue, (strlen(pszValue) + 1)); RegCloseKey(hkey); } if (err != ERROR_SUCCESS) { // if cannot add key or value, back out and fail UnregisterServer(); hr = SELFREG_E_CLASS; } } return hr; } // these point to standard access control objects |
ИНТЕРЕСНОЕ О ЛИТЕРАТУРЕ
ТОП 20 КНИГ
ТОП 20 АВТОРОВ
| ||||||||||||
|