Annotation of mstools/ole20/samples/spoly/misc.cpp, revision 1.1.1.1

1.1       root        1: /*** 
                      2: *misc.cpp
                      3: *
                      4: *  Copyright (C) 1992-93, Microsoft Corporation.  All Rights Reserved.
                      5: *
                      6: *Purpose:
                      7: *  This module contains a the of IDispatch related helper(s) that
                      8: *  are common to both the CPoly and CPoint implementations of IDispatch.
                      9: *
                     10: *Implementation Notes:
                     11: *
                     12: *****************************************************************************/
                     13: 
                     14: #include "spoly.h"
                     15: #include "cpoint.h"
                     16: #include "cpoly.h"
                     17: 
                     18: #include <stdio.h>
                     19: 
                     20: #if _MAC
                     21: # include <string.h>
                     22: # include <ctype.h>
                     23: #endif
                     24: 
                     25: int g_fExitOnLastRelease = 0;
                     26: 
                     27: unsigned long g_dwPolyCF = 0;
                     28: unsigned long g_dwPointCF = 0;
                     29: 
                     30: IClassFactory FAR* g_ppolyCF = NULL;
                     31: IClassFactory FAR* g_ppointCF = NULL;
                     32: 
                     33: 
                     34: void
                     35: Assert(int fCond, char FAR* file, int line, char FAR* message)
                     36: {
                     37:     char * fmt;
                     38:     char buf[128];
                     39: 
                     40:     if(fCond)
                     41:       return;
                     42: 
                     43:     fmt = (message == NULL)
                     44:       ? "Assertion failed: %s(%d)"
                     45:       : "Assertion failed: %s(%d) '%s'";
                     46:     sprintf(buf, fmt, file, line, message);
                     47: 
                     48: #ifdef _MAC
                     49:     DebugStr(c2pstr(buf));
                     50: #else
                     51:     OutputDebugString(buf);
                     52:     DebugBreak();
                     53: #endif
                     54: }
                     55: 
                     56: 
                     57: #ifdef WIN32
                     58: 
                     59: //---------------------------------------------------------------------
                     60: //           ASCII NLS Wrapper Functions (for Win32)
                     61: //---------------------------------------------------------------------
                     62: 
                     63: static int WINAPI
                     64: CompareStringA(
                     65:     LCID lcid,
                     66:     DWORD dwFlags,
                     67:     LPSTR lpStr1, int cch1,
                     68:     LPSTR lpStr2, int cch2)
                     69: {
                     70:     WCHAR lpwStr1[32], lpwStr2[32];
                     71:        
                     72:     MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpStr1, cch1, lpwStr1, 32);
                     73:     MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpStr2, cch2, lpwStr2, 32);
                     74:     return(CompareStringW(lcid, dwFlags, lpwStr1, cch1, lpwStr2, cch2));
                     75: }
                     76: 
                     77: #endif
                     78: 
                     79: 
                     80: #ifdef _MAC
                     81: pascal int stricmp(char *first, char *last)
                     82: {
                     83:     unsigned short f, l;
                     84: 
                     85:     do{
                     86:        f = tolower(*first++);
                     87:        l = tolower(*last++);
                     88:     }while(f && f == l);
                     89: 
                     90:     return f - l;
                     91: }
                     92: #endif
                     93: 
                     94: 
                     95: /***
                     96: *HRESULT InitOle(void)
                     97: *Purpose:
                     98: *  Initialize Ole, and register our class factories.
                     99: *
                    100: *Entry:
                    101: *  None
                    102: *
                    103: *Exit:
                    104: *  None
                    105: *
                    106: ***********************************************************************/
                    107: STDAPI
                    108: InitOle()
                    109: {
                    110:     HRESULT hresult;
                    111: 
                    112:     if((hresult = OleInitialize(NULL)) != NOERROR)
                    113:       goto LError0;
                    114: 
                    115:     // Register the CPoint Class Factory
                    116:     //
                    117:     if((g_ppointCF = CPointCF::Create()) == NULL){
                    118:       hresult = ResultFromScode(E_OUTOFMEMORY);
                    119:       goto LError1;
                    120:     }
                    121: 
                    122:     hresult = CoRegisterClassObject(
                    123:       CLSID_CPoint,
                    124:       g_ppointCF,
                    125:       CLSCTX_LOCAL_SERVER,
                    126:       REGCLS_MULTIPLEUSE,
                    127:       &g_dwPointCF);
                    128:     if(hresult != NOERROR)
                    129:       goto LError1;
                    130: 
                    131:     // Register the CPoly Class Factory.
                    132:     //
                    133:     if((g_ppolyCF = CPolyCF::Create()) == NULL){
                    134:       hresult = ResultFromScode(E_OUTOFMEMORY);
                    135:       goto LError1;
                    136:     }
                    137: 
                    138:     hresult = CoRegisterClassObject(
                    139:       CLSID_CPoly,
                    140:       g_ppolyCF,
                    141:       CLSCTX_LOCAL_SERVER,
                    142:       REGCLS_MULTIPLEUSE,
                    143:       &g_dwPolyCF);
                    144:     if(hresult != NOERROR)
                    145:       goto LError1;
                    146: 
                    147:     g_ppolyCF->Release();
                    148: 
                    149:     g_ppointCF->Release();
                    150: 
                    151:     return NOERROR;
                    152: 
                    153: 
                    154: LError1:;
                    155:     if(g_ppolyCF != NULL)
                    156:       g_ppolyCF->Release();
                    157: 
                    158:     if(g_ppointCF != NULL)
                    159:       g_ppointCF->Release();
                    160: 
                    161:     UninitOle();
                    162: 
                    163: LError0:;
                    164:     return hresult;
                    165: }
                    166: 
                    167: 
                    168: STDAPI
                    169: UninitOle()
                    170: {
                    171:     // Tell Ole to release our class factories.
                    172:     //
                    173:     if(g_dwPointCF != 0L)
                    174:       CoRevokeClassObject(g_dwPointCF);
                    175: 
                    176:     if(g_dwPolyCF != 0L)
                    177:       CoRevokeClassObject(g_dwPolyCF);
                    178: 
                    179:     OleUninitialize();
                    180: 
                    181:     return NOERROR;
                    182: }
                    183: 
                    184: 
                    185: /***
                    186: *HRESULT SPolyGetIDsOfNames(MEMBERDESC*, unsigned int, char**, unsigned int, LCID, long*)
                    187: *Purpose:
                    188: *  This is the table driven implementation of IDispatch::GetIDsOfNames
                    189: *  deferred to by both the CPoint and CPoly objects.
                    190: *
                    191: *Entry:
                    192: *  rgmd = pointer to an array of method descriptors
                    193: *  cMethods = number of elements in the array of method descriptors
                    194: *  rgszNames = pointer to an array of names
                    195: *  cNames = the number of names in the rgszNames array
                    196: *  lcid = the callers locale ID
                    197: *
                    198: *Exit:
                    199: *  return value = HRESULT
                    200: *  rgdispid = array of name IDs corresponding to the rgszNames array
                    201: *    this array will contain -1 for each entry that is not known.
                    202: *
                    203: ***********************************************************************/
                    204: STDAPI
                    205: SPolyGetIDsOfNames(
                    206:     MEMBERDESC FAR* rgmd,
                    207:     unsigned int cMethods,
                    208:     char FAR* FAR* rgszNames,
                    209:     unsigned int cNames,
                    210:     LCID lcid,
                    211:     DISPID FAR* rgdispid)
                    212: {
                    213:     HRESULT hresult;
                    214:     PARAMDESC FAR* ppd;
                    215:     MEMBERDESC FAR* pmd;
                    216:     unsigned int iName, iTry, cParams;
                    217: 
                    218:     hresult = NOERROR;
                    219: 
                    220:     // first lookup the member name.
                    221:     //
                    222:     for(pmd = rgmd;; ++pmd){
                    223:       if(pmd == &rgmd[cMethods])
                    224:         goto LMemberNotFound;
                    225: 
                    226: #ifdef _MAC
                    227:       if(!stricmp(rgszNames[0], pmd->szName))
                    228: #else
                    229:       if(CompareStringA(
                    230:         lcid, NORM_IGNORECASE, rgszNames[0], -1, pmd->szName, -1) == 2)
                    231: #endif
                    232:       {
                    233:        rgdispid[0] = pmd->id;
                    234:        break;
                    235:       }
                    236:     }
                    237: 
                    238:     // Lookup the named parameters, if there are any.
                    239:     if(cNames > 1){
                    240:       cParams = pmd->cParams;
                    241:       for(iName = 1; iName < cNames; ++iName){
                    242:        for(iTry = 0;; ++iTry){
                    243:          if(iTry == cParams){
                    244:            hresult = ResultFromScode(DISP_E_UNKNOWNNAME);
                    245:            rgdispid[iName] = -1;
                    246:            break;
                    247:          }
                    248:          ppd = &pmd->rgpd[iTry];
                    249: 
                    250: #ifdef _MAC
                    251:           if(!stricmp(rgszNames[iName], ppd->szName))
                    252: #else
                    253:          if(CompareStringA(
                    254:             lcid, NORM_IGNORECASE, rgszNames[iName], -1, ppd->szName, -1) == 2)
                    255: #endif
                    256:          {
                    257:            // The DISPID for a named parameter is defined to be its
                    258:            // zero based positional index.  This routine assumes that
                    259:            // that PARAMDESC array was declared in correct textual order.
                    260:            //
                    261:            rgdispid[iName] = iTry-1;
                    262:            break;
                    263:          }
                    264:         }
                    265:       }
                    266:     }
                    267: 
                    268:     return hresult;
                    269: 
                    270: LMemberNotFound:;
                    271:     // If the member name is unknown, everything is unknown.
                    272:     for(iName = 0; iName < cNames; ++iName)
                    273:       rgdispid[iName] = -1;
                    274:     return ResultFromScode(DISP_E_UNKNOWNNAME);
                    275: }
                    276: 

unix.superglobalmegacorp.com

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