|
#include "stdafx.h"
#include "resource.h"
#include "ESBServerComModule.h"
ESBServerComModule _Module;
#include <atlcom.h>
#include "IESBServer.h"
#include "IESBServerImpl.h"
#include "ESBServer_i.c"
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_ESBServerCoClass, IESBServerImpl)
END_OBJECT_MAP()
ESBServerComModule::ESBServerComModule()
: mIsATLInitialized(false)
{
}
ESBServerComModule& ESBServerComModule::instance()
{
return _Module;
}
extern ESBServerComModule _Module;
LONG ESBServerComModule::Unlock()
{
AfxOleUnlockApp();
return 0;
}
LONG ESBServerComModule::Lock()
{
AfxOleLockApp();
return 1;
}
LPCTSTR ESBServerComModule::FindOneOf(LPCTSTR p1, LPCTSTR p2)
{
while (*p1 != NULL)
{
LPCTSTR p = p2;
while (*p != NULL)
{
if (*p1 == *p)
return CharNext(p1);
p = CharNext(p);
}
p1++;
}
return NULL;
}
void ESBServerComModule::UninitializeATL()
{
if(mIsATLInitialized)
{
RevokeClassObjects();
Term();
CoUninitialize();
mIsATLInitialized = false;
}
}
bool ESBServerComModule::InitializeATL()
{
mIsATLInitialized = true;
#if _WIN32_WINNT >= 0x0400
HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
HRESULT hRes = CoInitialize(NULL);
#endif
if (FAILED(hRes))
{
mIsATLInitialized = FALSE;
return FALSE;
}
Init(ObjectMap, AfxGetInstanceHandle());
dwThreadID = GetCurrentThreadId();
LPTSTR lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT
TCHAR szTokens[] = _T("-/");
BOOL bRun = TRUE;
LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
while (lpszToken != NULL)
{
if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
{
UpdateRegistryFromResource(IDR_ESBSERVER, FALSE);
UnregisterServer(TRUE); //TRUE means typelib is unreg'd
bRun = FALSE;
break;
}
if (lstrcmpi(lpszToken, _T("RegServer"))==0)
{
UpdateRegistryFromResource(IDR_ESBSERVER, TRUE);
RegisterServer(TRUE);
bRun = FALSE;
break;
}
lpszToken = FindOneOf(lpszToken, szTokens);
}
if (!bRun)
{
mIsATLInitialized = FALSE;
Term();
CoUninitialize();
return FALSE;
}
hRes = RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
if (FAILED(hRes))
{
mIsATLInitialized = FALSE;
CoUninitialize();
return FALSE;
}
return TRUE;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.