home *** CD-ROM | disk | FTP | other *** search
- // cbisapi.cpp : Defines the initialization routines for the DLL.
- //
-
- #include "stdafx.h"
- #include "cbisapi.h"
- #include "IServer.h"
- #include <malloc.h>
- #include <afxconv.h>
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CCbisapiApp
-
- BEGIN_MESSAGE_MAP(CCbisapiApp, CWinApp)
- //{{AFX_MSG_MAP(CCbisapiApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CCbisapiApp construction
-
- CCbisapiApp::CCbisapiApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CCbisapiApp object
-
- CCbisapiApp theApp;
-
- /////////////////////////////////////////////////////////////////////////////
- // CCbisapiApp initialization
-
- BOOL CCbisapiApp::InitInstance()
- {
- // Register all OLE server (factories) as running. This enables the
- // OLE libraries to create objects from other applications.
- COleObjectFactory::RegisterAll();
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // Special entry points required for inproc servers
-
- STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- return AfxDllGetClassObject(rclsid, riid, ppv);
- }
-
- STDAPI DllCanUnloadNow(void)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- return AfxDllCanUnloadNow();
- }
-
- // by exporting DllRegisterServer, you can use regsvr.exe
- STDAPI DllRegisterServer(void)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- COleObjectFactory::UpdateRegistryAll();
- return S_OK;
- }
-
- // ISAPI Functions
- BOOL WINAPI GetExtensionVersion (HSE_VERSION_INFO *pVer)
- {
- pVer->dwExtensionVersion=MAKELONG(HSE_VERSION_MINOR,HSE_VERSION_MAJOR);
- lstrcpyn(pVer->lpszExtensionDesc,
- "OLE object ISAPI Gateway. Copyright 1997 by Al Williams",
- HSE_MAX_EXT_DLL_NAME_LEN);
- return TRUE;
- }
-
- DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *lpEcb)
- {
- // create IsapiServer object
- USES_CONVERSION;
- CoInitialize(NULL);
- CIsapiServer svr;
- svr.SetECB(lpEcb);
- // create user's object
- COleDispatchDriver obj;
- COleException x;
- DWORD siz;
- CString str;
- OLECHAR *name;
- char *plus,*colon;
- colon=strchr(lpEcb->lpszQueryString,':');
- plus=strchr(lpEcb->lpszQueryString,'+');
- if (plus) *plus='\0';
- if (colon)
- {
- *colon='\0';
- name=A2W(colon+1);
- }
- else
- name=L"ISAPI";
- if (!obj.CreateDispatch(lpEcb->lpszQueryString,&x))
- {
- str.Format("Can't create %s %x",lpEcb->lpszQueryString,x.m_sc);
- siz=str.GetLength();
- lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
- return HSE_STATUS_SUCCESS;
- }
- if (plus) *plus='+';
- *colon=':';
- // call user's object ISAPI method passing IsapiServer object
- DISPID dispid;
- static BYTE params[]= VTS_DISPATCH;
- IDispatch * dsptch=svr.GetIDispatch(FALSE);
- if (FAILED(obj.m_lpDispatch->GetIDsOfNames(IID_NULL,&name,1, LOCALE_SYSTEM_DEFAULT,&dispid)))
- {
- str.Format("Can't find method %s",colon?colon+1:"ISAPI");
- siz=str.GetLength();
- lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
- return HSE_STATUS_SUCCESS;
- }
- try
- {
- obj.InvokeHelper(dispid,DISPATCH_METHOD,VT_EMPTY,NULL,params,dsptch);
- }
- catch (COleException *e)
- {
- str.Format("COleException: &H%x", e->m_sc);
- siz=str.GetLength();
- lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
- }
- catch (COleDispatchException *e)
- {
- str.Format("COleDispatchException: %s", e->m_strDescription);
- siz=str.GetLength();
- lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
- }
- catch (...)
- {
- str.Format("Unknown Exception!");
- siz=str.GetLength();
- lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
- }
- // return status
- CoUninitialize();
- return svr.GetRV(); // init
- }