INF: Building an ODS Application with MFCLast reviewed: April 9, 1997Article ID: Q157919 |
The information in this article applies to:
SUMMARYThis article describes the steps necessary to build an ODS application using MFC. The major issue is that without the _cdecl specifications, the C++ compiler cannot locate the standard C API calls.
BOOL CODSSampleDlg::OnInitDialog() { CDialog::OnInitDialog(); pDlg = this; // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // ************************************************ // BEGIN: ODS Code Initialization // ************************************************ if(pconfig = srv_config_alloc()) { if(srv_config(pconfig, SRV_ANSI_CODEPAGE, "TRUE", SRV_NULLTERM) ==SUCCEED) { if(srv_config(pconfig, SRV_MINWORKINGTHREADS, "10", SRV_NULLTERM)== SUCCEED) { if(srv_config(pconfig, SRV_MAXWORKINGTHREADS, "25",SRV_NULLTERM) == SUCCEED) { if(srv_config(pconfig, SRV_THREADTIMEOUT, "1", SRV_NULLTERM)== SUCCEED) { srv_errhandle(iODSErrorHandler); if(pserver = (PSRV_SERVER) srv_init(pconfig, "ODS",SRV_NULLTERM)) { vAddLine(">>> ODS Sample Starting."); srv_handle(pserver, SRV_START, (int (__cdecl *)(void*))iODSEventHandler);
// // Lets get things started // DWORD dwThread = 0; hThread = CreateThread(NULL, 0 ,(LPTHREAD_START_ROUTINE)iServerRunThread, NULL, 0, &dwThread); if(!hThread) vAddLine("*** attempt to start ODS server threadfailed.");
} else vAddLine("*** attempt to initialize server failed."); } else vAddLine("*** attempt to set thread timeout failed."); } else vAddLine("*** attempt to set max worker threads failed."); } else vAddLine("*** attempt to set min worker threads failed."); } else vAddLine("*** attempt to set ANSI codepage failed."); } else vAddLine("*** srv_config_alloc() failed."); // ************************************************ // END: ODS Code Initialization // ************************************************ return TRUE; // return TRUE unless you set the focus to a control}
#ifdef __cplusplus extern "C" {#endif
// // ODS Handlers // int iODSErrorHandler(PSRV_SERVER pserver, PSRV_PROC psrvproc, int iErrorNo,BYTE bSeverity, BYTE bState, int iOSErrorNo, DBCHAR * strError, intiErrorLen, DBCHAR *strOSError, int iOSErrorLen) { CString cstrError; int iRc = SRV_CONTINUE; pDlg->vAddLine(""); cstrError.Format("*** OS Error %d: %s.", iOSErrorNo, strOSError); pDlg->vAddLine((LPCTSTR)cstrError); cstrError.Format("*** Error: (%d) Sev: (%d) State: (%d) %s.", iErrorNo,bSeverity, bState, strError); pDlg->vAddLine((LPCTSTR)cstrError); pDlg->vAddLine(""); return iRc;}
int iODSEventHandler(PSRV_SERVER pserver){
pDlg->vAddLine(">>> SRV_START called."); // // Setup ODS handlers // srv_handle(pserver, SRV_CONNECT, (int (__cdecl *)(void *))iConnectionHandler); // srv_handle(pserver, SRV_LANGUAGE, iLangExecHandler); // srv_handle(pserver, SRV_DISCONNECT, iExitConnectHandler); // srv_handle(pserver, SRV_ATTENTION, iAttentionHandler); return(SRV_CONTINUE);}
int iServerRunThread(void){ srv_run(pDlg->pserver); return 1;}
int iConnectionHandler(PSRV_PROC psrvproc){ CString cstrData; EnterCriticalSection(&pDlg->csSync); cstrData.Format(">>> User name ............ \"%s\"",srv_pfield(psrvproc, SRV_USER, NULL)); pDlg->vAddLine((LPCTSTR)cstrData); cstrData.Format(">>> Password ............. \"%s\"",srv_pfield(psrvproc, SRV_PWD, NULL)); pDlg->vAddLine((LPCTSTR)cstrData); LeaveCriticalSection(&pDlg->csSync); return SRV_DISCONNECT;}
#ifdef __cplusplus }#endif
|
Additional query words:
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |