Annotation of mstools/ole20/samples/dspcalc2/main.cpp, revision 1.1

1.1     ! root        1: /*** 
        !             2: *main.cpp
        !             3: *
        !             4: *  Copyright (C) 1992, Microsoft Corporation.  All Rights Reserved.
        !             5: *  Information Contained Herein Is Proprietary and Confidential.
        !             6: *
        !             7: *Purpose:
        !             8: *  This module is the main entry point of the sample IDispatch
        !             9: *  calculator, dspcalc2.exe.
        !            10: *
        !            11: *  This program is intended to demonstrate an implementation of
        !            12: *  the IDispatch interface.
        !            13: *
        !            14: *Implementation Notes:
        !            15: *
        !            16: *****************************************************************************/
        !            17: 
        !            18: #include <windows.h>
        !            19: #include <ole2.h>
        !            20: #if !defined(WIN32)
        !            21: #include <olenls.h>
        !            22: #endif
        !            23: #include <dispatch.h>
        !            24: 
        !            25: #include "resource.h"
        !            26: #include "dspcalc2.h"
        !            27: 
        !            28: 
        !            29: HANDLE g_hinst = 0;
        !            30: 
        !            31: DWORD g_dwCCalcCF = 0;
        !            32: DWORD g_dwRegisterCCalc = 0;
        !            33: CCalc FAR* g_pcalc = NULL;
        !            34: 
        !            35: char g_szAppName[] = "DspCalc2";
        !            36: 
        !            37: 
        !            38: HRESULT InitOle(void);
        !            39: void UninitOle(void);
        !            40: BOOL InitApplication(HANDLE);
        !            41: BOOL InitInstance(HANDLE, int);
        !            42: 
        !            43: 
        !            44: extern "C" {
        !            45: long FAR PASCAL WndProc(HWND, UINT, WPARAM, LPARAM);
        !            46: int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
        !            47: }
        !            48: 
        !            49: 
        !            50: extern "C" int PASCAL
        !            51: WinMain(
        !            52:     HANDLE hinst,
        !            53:     HANDLE hPrevInstance,
        !            54:     LPSTR lpCmdLine,
        !            55:     int nCmdShow)
        !            56: {
        !            57:     MSG msg;
        !            58: 
        !            59:     if(!hPrevInstance)
        !            60:       if(!InitApplication(hinst))
        !            61:        return FALSE;
        !            62: 
        !            63:     if(InitOle() != NOERROR)
        !            64:       return FALSE;
        !            65: 
        !            66:     if(!InitInstance(hinst, nCmdShow)){
        !            67:       UninitOle();
        !            68:       return FALSE;
        !            69:     }
        !            70: 
        !            71:     while(GetMessage(&msg, NULL, NULL, NULL)) {
        !            72:       TranslateMessage(&msg);
        !            73:       DispatchMessage(&msg);
        !            74:     }
        !            75: 
        !            76:     UninitOle();
        !            77: 
        !            78:     return msg.wParam;
        !            79: }
        !            80: 
        !            81: 
        !            82: BOOL
        !            83: InitApplication(HANDLE hinst)
        !            84: {
        !            85:     WNDCLASS  wc;
        !            86: 
        !            87:     wc.style           = CS_HREDRAW | CS_VREDRAW;
        !            88:     wc.lpfnWndProc     = WndProc;
        !            89:     wc.cbClsExtra      = 0;
        !            90:     wc.cbWndExtra      = DLGWINDOWEXTRA;
        !            91:     wc.hInstance       = hinst;
        !            92:     wc.hIcon           = LoadIcon(hinst, g_szAppName);
        !            93:     wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
        !            94:     wc.hbrBackground   = (HBRUSH)(COLOR_APPWORKSPACE+1);
        !            95:     wc.lpszMenuName    = NULL;
        !            96:     wc.lpszClassName   = g_szAppName;
        !            97: 
        !            98:     if(!RegisterClass(&wc))
        !            99:       return FALSE;
        !           100: 
        !           101:     return TRUE;
        !           102: }
        !           103: 
        !           104: 
        !           105: BOOL
        !           106: InitInstance(HANDLE hinst, int nCmdShow)
        !           107: {
        !           108:     g_hinst = hinst;
        !           109: 
        !           110:     g_pcalc->m_hwnd = CreateDialog(hinst, g_szAppName, 0, NULL);
        !           111: 
        !           112:     ShowWindow(g_pcalc->m_hwnd, nCmdShow);
        !           113: 
        !           114:     g_pcalc->m_arith.Display();
        !           115: 
        !           116:     return TRUE;
        !           117: }
        !           118: 
        !           119: 
        !           120: extern "C" long FAR PASCAL
        !           121: WndProc(
        !           122:     HWND hwnd,
        !           123:     UINT message,
        !           124:     WPARAM wParam,
        !           125:     LPARAM lParam)
        !           126: {
        !           127:     switch(message){
        !           128:     case WM_COMMAND:
        !           129:       switch(wParam){
        !           130:       case IDC_ZERO:
        !           131:       case IDC_ONE:
        !           132:       case IDC_TWO:
        !           133:       case IDC_THREE:
        !           134:       case IDC_FOUR:
        !           135:       case IDC_FIVE:
        !           136:       case IDC_SIX:
        !           137:       case IDC_SEVEN:
        !           138:       case IDC_EIGHT:
        !           139:       case IDC_NINE:
        !           140:       case IDC_PLUS:
        !           141:       case IDC_MINUS:
        !           142:       case IDC_MULT:
        !           143:       case IDC_DIV:
        !           144:       case IDC_CLEAR:
        !           145:       case IDC_EQUALS:
        !           146:        g_pcalc->m_arith.ButtonPush(wParam);
        !           147:        return 0;
        !           148:       }
        !           149:       break;
        !           150: 
        !           151:     case WM_DESTROY:
        !           152:       PostQuitMessage(0);
        !           153:       return 0;
        !           154:     }
        !           155:     return DefWindowProc(hwnd, message, wParam, lParam);
        !           156: }
        !           157: 
        !           158: 
        !           159: /***
        !           160: *HRESULT InitOle(void)
        !           161: *Purpose:
        !           162: *  Initialize Ole, and register our class factories.
        !           163: *
        !           164: *Entry:
        !           165: *  None
        !           166: *
        !           167: *Exit:
        !           168: *  None
        !           169: *
        !           170: ***********************************************************************/
        !           171: HRESULT
        !           172: InitOle()
        !           173: {
        !           174:     HRESULT hresult;
        !           175:     IClassFactory FAR* pcf;
        !           176: 
        !           177: 
        !           178:     if((hresult = OleInitialize(NULL)) != NOERROR)
        !           179:       goto LError0;
        !           180: 
        !           181:     // create the single global instance of CCalc
        !           182:     if((g_pcalc = CCalc::Create()) == NULL){
        !           183:       hresult = ResultFromScode(E_OUTOFMEMORY);
        !           184:       goto LError0;
        !           185:     }
        !           186: 
        !           187:     if((pcf = CCalcCF::Create()) == NULL)
        !           188:       goto LError1;
        !           189: 
        !           190:     hresult = CoRegisterClassObject(
        !           191:       CLSID_CCalc2,
        !           192:       pcf,
        !           193:       CLSCTX_LOCAL_SERVER,
        !           194:       REGCLS_MULTIPLEUSE,
        !           195:       &g_dwCCalcCF);
        !           196:     if(hresult != NOERROR)
        !           197:       goto LError2;
        !           198: 
        !           199:     hresult = RegisterActiveObject(
        !           200:       g_pcalc, CLSID_CCalc2, NULL, &g_dwRegisterCCalc);
        !           201:     if(hresult != NOERROR)
        !           202:       goto LError2;
        !           203: 
        !           204:     pcf->Release();
        !           205: 
        !           206:     return NOERROR;
        !           207: 
        !           208: LError2:;
        !           209:     pcf->Release();
        !           210: 
        !           211: LError1:;
        !           212:     UninitOle();
        !           213: 
        !           214: LError0:;
        !           215:     return hresult;
        !           216: }
        !           217: 
        !           218: 
        !           219: void
        !           220: UninitOle()
        !           221: {
        !           222:     if(g_dwRegisterCCalc != 0)
        !           223:       RevokeActiveObject(g_dwRegisterCCalc, NULL);
        !           224: 
        !           225:     if(g_dwCCalcCF != 0)
        !           226:       CoRevokeClassObject(g_dwCCalcCF);
        !           227: 
        !           228:     OleUninitialize();
        !           229: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.