/***************************************************************************\ * DdeFreeStringHandle (DDEML API) * * Description: * Decrement the use count of an HSZ. * * History: * 11-1-91 sanfords Created. \***************************************************************************/ BOOL DdeFreeStringHandle( DWORD idInst, HSZ hsz) { PCL_INSTANCE_INFO pcii; BOOL fRet = FALSE; EnterDDECrit; pcii = ValidateInstance((HANDLE)LongToHandle( idInst )); if (pcii == NULL) { BestSetLastDDEMLError(DMLERR_INVALIDPARAMETER); goto Exit; } if (ValidateHSZ(hsz) == HSZT_INVALID) { SetLastDDEMLError(pcii, DMLERR_INVALIDPARAMETER); goto Exit; } MONHSZ(pcii, hsz, MH_DELETE); fRet = TRUE; if (LATOM_FROM_HSZ(hsz) != 0) { if (DeleteAtom(LATOM_FROM_HSZ(hsz))) { SetLastDDEMLError(pcii, DMLERR_INVALIDPARAMETER); fRet = FALSE; } } Exit: LeaveDDECrit; return (fRet); }
/*********************************************************************** * UXTHEME_SetWindowProperty * * I'm using atoms as there may be large numbers of duplicated strings * and they do the work of keeping memory down as a cause of that quite nicely */ static HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue) { ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp)); if(oldValue) DeleteAtom(oldValue); if(pszValue) { ATOM atValue = AddAtomW(pszValue); if(!atValue || !SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp), (LPWSTR)MAKEINTATOM(atValue))) { HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); if(atValue) DeleteAtom(atValue); return hr; } } return S_OK; }
void FreeModuleInstance(HMODULE hModule) { LPMODULEINFO lpModuleInfo, lpModuleTemp; if (!(lpModuleInfo = GETMODULEINFO(hModule))) { return; } DeleteAtom(lpModuleInfo->atmModuleName); WinFree(lpModuleInfo->lpModuleName); if (bModIndex == lpModuleInfo->bModIndex) bModIndex--; lpModuleTable[lpModuleInfo->bModIndex] = (LPMODULEINFO)0; if (lpModuleInfo == (LPMODULEINFO)lpModuleHead) lpModuleHead = (LPOBJHEAD)lpModuleInfo->ObjHead.lpObjNext; else { for (lpModuleTemp = (LPMODULEINFO)lpModuleHead; lpModuleTemp && (LPMODULEINFO)lpModuleTemp->ObjHead.lpObjNext != lpModuleInfo; lpModuleTemp = (LPMODULEINFO)lpModuleTemp->ObjHead.lpObjNext); if (lpModuleTemp) lpModuleTemp->ObjHead.lpObjNext = lpModuleInfo->ObjHead.lpObjNext; } RELEASEMODULEINFO(lpModuleInfo); FREEHMODULE(hModule); }
GlobalKey::~GlobalKey() { QWidget *main = ShortcutsPlugin::getMainWindow(); if (m_key && main){ UnregisterHotKey(main->winId(), m_key); DeleteAtom((unsigned short)m_key); } }
VOID CloseKeys() { for (; keyscached--;) { #ifdef DEBUG if (!ahkey[keyscached]) { DPF0(("Closing a null key\n")); } #endif RegCloseKey(ahkey[keyscached]); DeleteAtom(akeyatoms[keyscached]); } }
void CALLBACK ConnectionTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD) { if (uMsg == WM_TIMER) { KillTimer(hwnd, idEvent); //We've received a timer message: enable the popups for a specified protocol. char szProto[256]; if (GetAtomNameA((ATOM)idEvent, szProto, sizeof(szProto)) > 0) { db_set_b(0, MODULE, szProto, 1); DeleteAtom((ATOM)idEvent); } } }
VOID CloseKeys() { for (; keyscached--;) { #ifdef DEBUG if (!ahkey[keyscached]) { //Assertion! DPF0(("Closing a null key\n")); //DebugBreak(); } #endif RegCloseKey(ahkey[keyscached]); DeleteAtom(akeyatoms[keyscached]); } }
BOOL CWordPadApp::IsDocOpen(LPCTSTR lpszFileName) { if (lpszFileName[0] == NULL) return FALSE; TCHAR szPath[_MAX_PATH]; AfxFullPath(szPath, lpszFileName); ATOM atom = GlobalAddAtom(szPath); ASSERT(atom != NULL); if (atom == NULL) return FALSE; EnumWindows(StaticEnumProc, (LPARAM)&atom); if (atom == NULL) return TRUE; DeleteAtom(atom); return FALSE; }
BOOL CALLBACK CWordPadApp::StaticEnumProc(HWND hWnd, LPARAM lParam) { TCHAR szClassName[30]; GetClassName(hWnd, szClassName, 30); if (lstrcmp(szClassName, szWordPadClass) != 0) return TRUE; ATOM* pAtom = (ATOM*)lParam; ASSERT(pAtom != NULL); DWORD_PTR dw = NULL; ::SendMessageTimeout(hWnd, m_nOpenMsg, NULL, (LPARAM)*pAtom, SMTO_ABORTIFHUNG, 500, &dw); if (dw) { ::SetForegroundWindow(hWnd); DeleteAtom(*pAtom); *pAtom = NULL; return FALSE; } return TRUE; }
/***************************************************************************\ * DdeNameService (DDEML API) * * Description: * Registers, and Unregisters service names and sets the Initiate filter * state for an instance. * * History: * 11-1-91 sanfords Created. \***************************************************************************/ HDDEDATA DdeNameService( DWORD idInst, HSZ hsz1, // service name HSZ hsz2, // reserved for future enhancements UINT afCmd) // DNS_ flags. { BOOL fRet = TRUE; LATOM *plaNameService; PCL_INSTANCE_INFO pcii; EnterDDECrit; pcii = ValidateInstance((HANDLE)LongToHandle( idInst )); if (pcii == NULL) { BestSetLastDDEMLError(DMLERR_INVALIDPARAMETER); fRet = FALSE; goto Exit; } if ((hsz1 && ValidateHSZ(hsz1) == HSZT_INVALID) || hsz2 != 0) { SetLastDDEMLError(pcii, DMLERR_INVALIDPARAMETER); fRet = FALSE; goto Exit; } if (afCmd & DNS_FILTERON && !(pcii->afCmd & APPCMD_FILTERINITS)) { pcii->afCmd |= APPCMD_FILTERINITS; NtUserUpdateInstance(pcii->hInstServer, &pcii->MonitorFlags, pcii->afCmd); } if (afCmd & DNS_FILTEROFF && (pcii->afCmd & APPCMD_FILTERINITS)) { pcii->afCmd &= ~APPCMD_FILTERINITS; NtUserUpdateInstance(pcii->hInstServer, &pcii->MonitorFlags, pcii->afCmd); } if (afCmd & (DNS_REGISTER | DNS_UNREGISTER)) { GATOM ga; if (pcii->afCmd & APPCMD_CLIENTONLY) { SetLastDDEMLError(pcii, DMLERR_DLL_USAGE); fRet = FALSE; goto Exit; } if (hsz1 == 0) { if (afCmd & DNS_REGISTER) { /* * registering NULL is not allowed! */ SetLastDDEMLError(pcii, DMLERR_INVALIDPARAMETER); fRet = FALSE; goto Exit; } /* * unregistering NULL is just like unregistering each * registered name. * * 10/19/90 - made this a synchronous event so that hsz * can be freed by calling app after this call completes * without us having to keep a copy around forever. */ plaNameService = pcii->plaNameService; while (*plaNameService != 0) { ga = LocalToGlobalAtom(*plaNameService); DeleteAtom(*plaNameService); LeaveDDECrit; RegisterService(FALSE, ga, pcii->hwndMother); EnterDDECrit; GlobalDeleteAtom(ga); plaNameService++; } pcii->cNameServiceAlloc = 1; *pcii->plaNameService = 0; goto Exit; } if (afCmd & DNS_REGISTER) { plaNameService = (LATOM *)DDEMLReAlloc(pcii->plaNameService, sizeof(LATOM) * ++pcii->cNameServiceAlloc); if (plaNameService == NULL) { SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR); pcii->cNameServiceAlloc--; fRet = FALSE; goto Exit; } else { pcii->plaNameService = plaNameService; } IncLocalAtomCount(LATOM_FROM_HSZ(hsz1)); // NameService copy plaNameService[pcii->cNameServiceAlloc - 2] = LATOM_FROM_HSZ(hsz1); plaNameService[pcii->cNameServiceAlloc - 1] = 0; } else { // DNS_UNREGISTER plaNameService = pcii->plaNameService; while (*plaNameService != 0 && *plaNameService != LATOM_FROM_HSZ(hsz1)) { plaNameService++; } if (*plaNameService == 0) { goto Exit; // not found just exit } // // fill empty slot with last entry and fill last entry with 0 // pcii->cNameServiceAlloc--; *plaNameService = pcii->plaNameService[pcii->cNameServiceAlloc - 1]; pcii->plaNameService[pcii->cNameServiceAlloc - 1] = 0; } ga = LocalToGlobalAtom(LATOM_FROM_HSZ(hsz1)); LeaveDDECrit; RegisterService((afCmd & DNS_REGISTER) ? TRUE : FALSE, ga, pcii->hwndMother); EnterDDECrit; GlobalDeleteAtom(ga); } Exit: LeaveDDECrit; return ((HDDEDATA)IntToPtr( fRet )); }
BOOL _DestroyCursor( PCURSOR pcur, DWORD cmdDestroy) { PPROCESSINFO ppi; PPROCESSINFO ppiCursor; int i; extern BOOL DestroyAniIcon(PACON pacon); if (pcur == NULL) { UserAssert(FALSE); return(TRUE); } ppi = PpiCurrent(); ppiCursor = GETPPI(pcur); /* * Remove this icon from the caption icon cache. */ for (i = 0; i < CCACHEDCAPTIONS; i++) { if (cachedCaptions[i].spcursor == pcur) { Unlock( &(cachedCaptions[i].spcursor) ); } } /* * First step in destroying an cursor */ switch (cmdDestroy) { case CURSOR_ALWAYSDESTROY: /* * Always destroy? then don't do any checking... */ break; case CURSOR_CALLFROMCLIENT: /* * Can't destroy public cursors/icons. */ if (ppiCursor == NULL) /* * Fake success if its a resource loaded icon because * this is how win95 responded. */ return !!(pcur->CURSORF_flags & CURSORF_FROMRESOURCE); /* * If this cursor was loaded from a resource, don't free it till the * process exits. This is the way we stay compatible with win3.0's * cursors which were actually resources. Resources under win3 have * reference counting and other "features" like handle values that * never change. Read more in the comment in * ServerLoadCreateCursorIcon(). */ if (pcur->CURSORF_flags & (CURSORF_LRSHARED | CURSORF_SECRET)) { return TRUE; } /* * One thread can't destroy the objects created by another. */ if (ppiCursor != ppi) { RIPERR0(ERROR_DESTROY_OBJECT_OF_OTHER_THREAD, RIP_VERBOSE, ""); return FALSE; } /* * fall through. */ case CURSOR_THREADCLEANUP: /* * Don't destroy public objects either (pretend it worked though). */ if (ppiCursor == NULL) return TRUE; break; } /* * First mark the object for destruction. This tells the locking code that * we want to destroy this object when the lock count goes to 0. If this * returns FALSE, we can't destroy the object yet. */ if (!HMMarkObjectDestroy((PHEAD)pcur)) return FALSE; if (pcur->strName.Length != 0) { UserFreePool((LPSTR)pcur->strName.Buffer); } if (pcur->atomModName != 0) { DeleteAtom(pcur->atomModName); } /* * If this is an ACON call its special routine to destroy it. */ if (pcur->CURSORF_flags & CURSORF_ACON) { DestroyAniIcon((PACON)pcur); } else { if (pcur->hbmMask != NULL) { GreDeleteObject(pcur->hbmMask); } if (pcur->hbmColor != NULL) { GreDeleteObject(pcur->hbmColor); } } /* * Ok to destroy... Free the handle (which will free the object and the * handle). */ DestroyEmptyCursorObject(pcur); return TRUE; }
/***************************************************************************\ * _ClientEventCallback * * Description: * Called from the server side to perform event callbacks. * * History: * 11-12-91 sanfords Created. \***************************************************************************/ DWORD _ClientEventCallback( PCL_INSTANCE_INFO pcii, PEVENT_PACKET pep) { HDDEDATA hData; EnterDDECrit; switch (pep->EventType) { case 0: // MonitorFlags change event - everybody gets it pcii->MonitorFlags = pep->Data; break; case MF_CALLBACKS: { MONCBSTRUCT mcb; mcb = *((MONCBSTRUCT *)&pep->Data); mcb.hsz1 = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)mcb.hsz1)); mcb.hsz2 = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)mcb.hsz2)); if ( mcb.wType == XTYP_REGISTER || mcb.wType == XTYP_UNREGISTER) { mcb.hsz2 = INST_SPECIFIC_HSZ_FROM_LATOM((LATOM)mcb.hsz2); } hData = InternalCreateDataHandle(pcii, (LPSTR)&mcb, pep->cbEventData, 0, HDATA_NOAPPFREE | HDATA_READONLY | HDATA_EXECUTE, 0, 0); if (hData) { DoCallback(pcii, (WORD)XTYP_MONITOR, 0, 0, 0, 0, hData, 0L, pep->EventType); InternalFreeDataHandle((HDDEDATA)hData, TRUE); DeleteAtom(LATOM_FROM_HSZ(mcb.hsz1)); DeleteAtom(LATOM_FROM_HSZ(mcb.hsz2)); } } break; case MF_LINKS: { MONLINKSTRUCT ml; ml = *((MONLINKSTRUCT *)&pep->Data); ml.hszSvc = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)ml.hszSvc)); ml.hszTopic = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)ml.hszTopic)); ml.hszItem = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)ml.hszItem)); hData = InternalCreateDataHandle(pcii, (LPSTR)&ml, pep->cbEventData, 0, HDATA_NOAPPFREE | HDATA_READONLY | HDATA_EXECUTE, 0, 0); if (hData) { DoCallback(pcii, (WORD)XTYP_MONITOR, 0, 0, 0, 0, hData, 0L, pep->EventType); InternalFreeDataHandle((HDDEDATA)hData, TRUE); DeleteAtom(LATOM_FROM_HSZ(ml.hszSvc)); DeleteAtom(LATOM_FROM_HSZ(ml.hszTopic)); DeleteAtom(LATOM_FROM_HSZ(ml.hszItem)); } } break; case MF_CONV: { MONCONVSTRUCT mc; mc = *((MONCONVSTRUCT *)&pep->Data); mc.hszSvc = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)mc.hszSvc)); mc.hszTopic = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)mc.hszTopic)); hData = InternalCreateDataHandle(pcii, (LPSTR)&mc, pep->cbEventData, 0, HDATA_NOAPPFREE | HDATA_READONLY | HDATA_EXECUTE, 0, 0); if (hData) { DoCallback(pcii, (WORD)XTYP_MONITOR, 0, 0, 0, 0, hData, 0L, pep->EventType); InternalFreeDataHandle((HDDEDATA)hData, TRUE); DeleteAtom(LATOM_FROM_HSZ(mc.hszSvc)); DeleteAtom(LATOM_FROM_HSZ(mc.hszTopic)); } } break; case MF_HSZ_INFO: if (!(pcii->flags & IIF_UNICODE)) { LPSTR pszAnsi; /* * Translate HSZ string back into ANSI */ if (WCSToMB(((PMONHSZSTRUCT)&pep->Data)->str, ((int)pep->cbEventData - (int)((PMONHSZSTRUCT)&pep->Data)->cb) / sizeof(WCHAR), &pszAnsi, (int)pep->cbEventData - (int)((PMONHSZSTRUCT)&pep->Data)->cb, TRUE)) { strcpy(((PMONHSZSTRUCTA)&pep->Data)->str, pszAnsi); UserLocalFree(pszAnsi); } ((PMONHSZSTRUCT)&pep->Data)->cb = sizeof(MONHSZSTRUCTA); } // fall through case MF_SENDMSGS: case MF_POSTMSGS: if (pep->EventType == MF_POSTMSGS) { PMONMSGSTRUCT pmms = (PMONMSGSTRUCT)&pep->Data; BYTE buf[32]; /* * We may need to translate the Execute string to/from * UNICODE depending on what type of monitor this is * going to. */ if (pmms->wMsg == WM_DDE_EXECUTE) { BOOL fUnicodeText; int flags; flags = (IS_TEXT_UNICODE_UNICODE_MASK | IS_TEXT_UNICODE_REVERSE_MASK | (IS_TEXT_UNICODE_NOT_UNICODE_MASK & (~IS_TEXT_UNICODE_ILLEGAL_CHARS)) | IS_TEXT_UNICODE_NOT_ASCII_MASK); #ifdef ISTEXTUNICODE_WORKS fUnicodeText = RtlIsTextUnicode(pmms->dmhd.Data, min(32, pmms->dmhd.cbData), &flags); #else fUnicodeText = (*(LPSTR)pmms->dmhd.Data == '\0'); #endif if (pcii->flags & IIF_UNICODE && !fUnicodeText) { /* Ascii->UNICODE */ RtlMultiByteToUnicodeN((LPWSTR)buf, 32, NULL, (LPSTR)&pmms->dmhd.Data, min(32, pmms->dmhd.cbData)); RtlCopyMemory(&pmms->dmhd.Data, buf, 32); } else if (!(pcii->flags & IIF_UNICODE) && fUnicodeText) { /* UNICODE->Ascii */ RtlUnicodeToMultiByteN((LPSTR)buf, 32, NULL, (LPWSTR)&pmms->dmhd.Data, min(32, pmms->dmhd.cbData)); RtlCopyMemory(&pmms->dmhd.Data, buf, 32); } } } case MF_ERRORS: hData = InternalCreateDataHandle(pcii, (LPSTR)&pep->Data, pep->cbEventData, 0, HDATA_NOAPPFREE | HDATA_READONLY | HDATA_EXECUTE, 0, 0); if (hData) { DoCallback(pcii, (WORD)XTYP_MONITOR, 0, 0, 0, 0, hData, 0L, pep->EventType); InternalFreeDataHandle((HDDEDATA)hData, TRUE); } break; } LeaveDDECrit; return (0); }
/********************************************************************* ** ** Adds a new menu item to a menu. ** ** Position is the position of the new menu item. If position is -1, ** the menu item is inserted as the last item. ** **********************************************************************/ BOOL __far __pascal MyInsertMenu ( HWND hDataWnd, LPSTR lpMenuID, LPSTR lpItemID, LPSTR lpItemText, LPSTR lpMacro, short int Position ) { HMENUSYS hMenuSys; FPMENUSYS MenuSysPtr; /* Menu info. to store in menu info. list. */ MENUINFO MenuInfo, MenuItemInfo; BOOL bReturn; /* Pointer to macro string. */ char __far * MacroStringPtr; /* Get the menu sys. data */ hMenuSys = (HMENUSYS) WndData( hDataWnd, WDM_GETMENUSYS, 0, NULL ); /* Lock menu sys. data. */ MenuSysPtr = ( FPMENUSYS ) GlobalLock( hMenuSys ); /* Menubar does not even exist. */ if( MenuSysPtr->hMenuBar == NULL ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, MENUDOESNOTEXIST, MB_ICONHAND | MB_OK ); /* Success. */ return( FALSE ); } /* Find the menu that the item will be added to. */ if( GetMenuInfo( MenuSysPtr->hMenuList, lpMenuID, &MenuInfo ) ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, MENUDOESNOTEXIST, MB_ICONHAND | MB_OK ); /* Success. */ return( FALSE ); } /* Verify that the new menu's ID string is unique. */ if( GetMenuInfo( MenuSysPtr->hMenuList, lpItemID, &MenuItemInfo ) ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, MENUALREADYEXISTS, MB_ICONHAND | MB_OK ); /* Success. */ return( FALSE ); } /* Allocate memory for storage of macro string. */ if( !GlobalAllocMem( hDataWnd, &(MenuItemInfo).hMacroString, _fstrlen( lpMacro ) + sizeof(char) ) ) { /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, CANTCREATEMENU, MB_ICONHAND | MB_OK ); /* Failure. */ return( FALSE ); } /* Copy macro string storage area. */ MacroStringPtr = (char __far *) GlobalLock( MenuItemInfo.hMacroString ); _fstrcpy( MacroStringPtr, lpMacro ); GlobalUnlock( MenuItemInfo.hMacroString ); /* Init. the other menu item info. */ MenuItemInfo.MenuID = AddAtom( lpItemID ); MenuItemInfo.hMenu = NULL; MenuItemInfo.hParentMenu = MenuInfo->hMenu; MenuItemInfo.hMacroString = NULL; /* Add the menu item to the menu. */ if( ! InsertMenu( MenuInfo->hMenu, Position, MF_BYPOSITION | MF_ENABLED | MF_STRING, MenuItemInfo.MenuID, lpItemText) ) { /* Delete allocated info. */ DeleteAtom( MenuItemInfo.ButtonID ); GlobalFree( MenuItemInfo.hMacroString ); /* Error. */ MsgBox( GetLibInst(), hDataWnd, IDS_ERRORTITLE, CANTCREATEMENU, MB_ICONHAND | MB_OK ); /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Success. */ return( FALSE ); } /* Save the menu info. */ bReturn = SaveMenuInfo( hDataWnd, &(MenuSysPtr)->hMenuList, (FPMENUINFO) &MenuInfo ); if( bReturn == FALSE ) { /* Delete allocated info. */ DeleteAtom( MenuItemInfo.ButtonID ); GlobalFree( MenuItemInfo.hMacroString ); /* Remove the new menu item. */ RemoveMenu( MenuInfo->hMenu, Position, MF_BYPOSITION ); /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Failure. */ return FALSE; } /* Show changes. */ DrawMenuBar( MenuSysPtr->hMenuBar ); /* Unlock menu sys. data. */ GlobalUnlock( hMenuSys ); /* Success. */ return( TRUE ); }
/***************************************************************************\ * DdeConnectList (DDEML API) * * Description: * Initiates DDE conversations with multiple servers or adds unique servers * to an existing conversation list. * * History: * 11-12-91 sanfords Created. \***************************************************************************/ HCONVLIST DdeConnectList( DWORD idInst, HSZ hszService, HSZ hszTopic, HCONVLIST hConvList, PCONVCONTEXT pCC) { PCL_INSTANCE_INFO pcii; PCONV_INFO pcoi, pcoiNew, pcoiExisting, pcoiNext; HCONVLIST hConvListRet = 0; HWND hwndTarget = 0; LATOM aNormalSvcName = 0; PCONVLIST pcl = NULL; HCONVLIST hConvListOld; int i; CheckDDECritOut; EnterDDECrit; if (!ValidateConnectParameters((HANDLE)idInst, &pcii, &hszService, hszTopic, &aNormalSvcName, &pCC, &hwndTarget, hConvList)) { goto Exit; } ValidateConvList(hConvList); hConvListOld = hConvList; pcoi = (PCONV_INFO)ConnectConv(pcii, LATOM_FROM_HSZ(hszService), LATOM_FROM_HSZ(hszTopic), hwndTarget, (pcii->afCmd & (CBF_FAIL_SELFCONNECTIONS | CBF_FAIL_CONNECTIONS)) ? pcii->hwndMother : 0, pCC, hConvListOld, CLST_MULT_INITIALIZING); if (pcoi == NULL) { /* * no new connections made */ SetLastDDEMLError(pcii, DMLERR_NO_CONV_ESTABLISHED); hConvListRet = hConvListOld; goto Exit; } /* * allocate or reallocate the hConvList hwnd list for later addition * If we already have a valid list, reuse the handle so we don't have * to alter the preexisting pcoi->hConvList values. */ if (hConvListOld == 0) { pcl = (PCONVLIST)DDEMLAlloc(sizeof(CONVLIST)); if (pcl == NULL) { SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR); DisconnectConv(pcoi); goto Exit; } // pcl->chwnd = 0; LPTR zero inits. hConvList = (HCONVLIST)CreateHandle((DWORD)pcl, HTYPE_CONVERSATION_LIST, InstFromHandle(pcii->hInstClient)); if (hConvList == 0) { DDEMLFree(pcl); SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR); DisconnectConv(pcoi); goto Exit; } } else { pcl = (PCONVLIST)GetHandleData((HANDLE)hConvList); pcl = DDEMLReAlloc(pcl, sizeof(CONVLIST) + sizeof(HWND) * pcl->chwnd); if (pcl == NULL) { SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR); hConvListRet = hConvListOld; DisconnectConv(pcoi); goto Exit; } SetHandleData((HANDLE)hConvList, (DWORD)pcl); } ValidateConvList(hConvListOld); if (hConvListOld) { /* * remove duplicates from new conversations * * Although we tried to prevent duplicates from happening * within the initiate enumeration code, wild initiates or * servers responding with different service names than * requested could cause duplicates. */ /* For each client window... */ for (i = 0; i < pcl->chwnd; i++) { /* For each existing conversation in that window... */ for (pcoiExisting = (PCONV_INFO) GetWindowLong(pcl->ahwnd[i], GWL_PCI); pcoi != NULL && pcoiExisting != NULL; pcoiExisting = pcoiExisting->next) { if (!(pcoiExisting->state & ST_CONNECTED)) continue; /* For each new conversation... */ for (pcoiNew = pcoi; pcoiNew != NULL; pcoiNew = pcoiNext) { pcoiNext = pcoiNew->next; /* see if the new conversation duplicates the existing one */ if (!(pcoiNew->state & ST_CONNECTED)) continue; UserAssert(((PCL_CONV_INFO)pcoiExisting)->hwndReconnect); UserAssert(((PCL_CONV_INFO)pcoiNew)->hwndReconnect); if (((PCL_CONV_INFO)pcoiExisting)->hwndReconnect == ((PCL_CONV_INFO)pcoiNew)->hwndReconnect && pcoiExisting->laTopic == pcoiNew->laTopic && pcoiExisting->laService == pcoiNew->laService) { /* * duplicate conversation - disconnection causes an unlink */ if (pcoiNew == pcoi) { /* * We are freeing up the head of the list, * Reset the head to the next guy. */ pcoi = pcoiNext; } ValidateConvList(hConvList); ShutdownConversation(pcoiNew, FALSE); ValidateConvList(hConvList); break; } } } } for (pcoiExisting = pcoi; pcoiExisting != NULL; pcoiExisting = pcoiExisting->next) { /* * if these are all zombies - we DONT want to link it in! * This is possible because ShutdownConversation() leaves the critical section * and could allow responding terminates to come through. */ if (pcoiExisting->state & ST_CONNECTED) { goto FoundOne; } } pcoi = NULL; // abandon this guy - he will clean up in time. FoundOne: /* * add new pcoi (if any are left) hwnd to ConvList hwnd list. */ if (pcoi != NULL) { UserAssert(pcoi->hwndConv); pcl->ahwnd[pcl->chwnd] = pcoi->hwndConv; pcl->chwnd++; hConvListRet = hConvList; } else { hConvListRet = hConvListOld; if (!hConvListOld) { DestroyHandle((HANDLE)hConvList); } } } else { // no hConvListOld UserAssert(pcoi->hwndConv); pcl->ahwnd[0] = pcoi->hwndConv; pcl->chwnd = 1; hConvListRet = hConvList; } if (pcoi != NULL) { /* * set hConvList field for all remaining new conversations. */ UserAssert(hConvListRet); for (pcoiNew = pcoi; pcoiNew != NULL; pcoiNew = pcoiNew->next) { if (pcoiNew->state & ST_CONNECTED) { ((PCL_CONV_INFO)pcoiNew)->hConvList = hConvListRet; } } } Exit: if (aNormalSvcName) { DeleteAtom(aNormalSvcName); } ValidateConvList(hConvListRet); LeaveDDECrit; return (hConvListRet); }
/***************************************************************************\ * FreeConversationResources * * Description: * Used when: Client window is disconnected by app, Server window is * disconnected by either side, or when a conversation is disconnected * at Uninitialize time. * * This function releases all resources held by the pcoi and unlinks it * from its host window pcoi chian. pcoi is freed once this return s. * * History: * 12-21-91 sanfords Created. \***************************************************************************/ VOID FreeConversationResources( PCONV_INFO pcoi) { PADVISE_LINK paLink; PDDE_MESSAGE_QUEUE pdmq; PXACT_INFO pxi; CheckDDECritIn; /* * Don't free resources on locked conversations. */ if (pcoi->cLocks > 0) { pcoi->state |= ST_FREE_CONV_RES_NOW; return; } /* * Don't free resources if a synchronous transaction is in effect! */ pxi = pcoi->pxiOut; while (pxi != NULL) { if (pxi->flags & XIF_SYNCHRONOUS) { /* * This conversation is in a synchronous transaction. * Shutdown the modal loop FIRST, then call this when * the loop exits. */ PostMessage(pcoi->hwndConv, WM_TIMER, TID_TIMEOUT, 0); pcoi->state |= ST_FREE_CONV_RES_NOW; return; } pxi = pxi->next; } /* * If this is an Intra-Process conversation that hasn't yet received * a terminate message, make it a zombie. We will call this routine * again once the terminate arrives or when WaitForZombieTerminate() has * timed out waiting. */ if (pcoi->state & ST_INTRA_PROCESS && !(pcoi->state & ST_TERMINATE_RECEIVED)) { DestroyHandle((HANDLE)pcoi->hConv); pcoi->hConv = (HCONV)CreateHandle((DWORD)pcoi, HTYPE_ZOMBIE_CONVERSATION, InstFromHandle(pcoi->hConv)); UnlinkConvFromOthers(pcoi, TRUE); return; } /* * remove any transactions left in progress */ while (pcoi->pxiOut != NULL) { (pcoi->pxiOut->pfnResponse)(pcoi->pxiOut, 0, 0); } /* * Throw away any incomming queued DDE messages. */ while (pcoi->dmqOut != NULL) { pdmq = pcoi->dmqOut; DumpDDEMessage(!(pcoi->state & ST_INTRA_PROCESS), pdmq->msg, pdmq->lParam); pcoi->dmqOut = pcoi->dmqOut->next; if (pcoi->dmqOut == NULL) { pcoi->dmqIn = NULL; } DDEMLFree(pdmq); } // // Remove all link info // paLink = pcoi->aLinks; while (pcoi->cLinks) { if (pcoi->state & ST_CLIENT) { MONLINK(pcoi->pcii, FALSE, paLink->wType & XTYPF_NODATA, pcoi->laService, pcoi->laTopic, LocalToGlobalAtom(paLink->laItem), paLink->wFmt, FALSE, (HCONV)pcoi->hwndPartner, (HCONV)pcoi->hwndConv); } else { MONLINK(pcoi->pcii, FALSE, paLink->wType & XTYPF_NODATA, pcoi->laService, pcoi->laTopic, LocalToGlobalAtom(paLink->laItem), paLink->wFmt, TRUE, (HCONV)pcoi->hwndConv, (HCONV)pcoi->hwndPartner); } if (!(pcoi->state & ST_CLIENT)) { DeleteLinkCount(pcoi->pcii, paLink->pLinkCount); } DeleteAtom(paLink->laItem); // link structure copy paLink++; pcoi->cLinks--; } if (pcoi->aLinks) { DDEMLFree(pcoi->aLinks); } // // free atoms associated with this conv // DeleteAtom(pcoi->laService); DeleteAtom(pcoi->laTopic); if (pcoi->laServiceRequested) { DeleteAtom(pcoi->laServiceRequested); } UnlinkConvFromOthers(pcoi, FALSE); /* * invalidate app's conversation handle */ DestroyHandle((HANDLE)pcoi->hConv); DDEMLFree(pcoi); }
ServiceRegistrar::~ServiceRegistrar() { DeleteAtom(m_serviceAtom); }
~CGlobalAtom(void) { DeleteAtom(atom); }
DWORD main( int argc, char *argv[], char *envp[] ) { ATOM Atom1, Atom2, Atom3; BOOL Atom1Found, Atom2Found, Atom3Found; DWORD Atom1Length, Atom2Length, Atom3Length; TCHAR NameBuffer[ 128 ]; printf( "TATOM: Entering Test Program\n" ); Atom1 = AddAtom( TEXT("Atom1") ); Atom2 = AddAtom( TEXT("#4095") ); Atom3 = AddAtom( (LPTSTR)0x1234 ); printf( "AddAtom( ""Atom1"" ) == %X\n", Atom1 ); printf( "AddAtom( ""#4095"" ) == %X\n", Atom2 ); printf( "AddAtom( 0x1234 ) == %X\n", Atom3 ); Atom1 = AddAtom( TEXT("Atom1") ); Atom2 = AddAtom( TEXT("#4095") ); Atom3 = AddAtom( (LPTSTR)0x1234 ); printf( "AddAtom( ""Atom1"" ) == %X\n", Atom1 ); printf( "AddAtom( ""#4095"" ) == %X\n", Atom2 ); printf( "AddAtom( 0x1234 ) == %X\n", Atom3 ); assert( Atom1Found = (Atom1 == FindAtom( TEXT("Atom1") )) ); assert( Atom2Found = (Atom2 == FindAtom( TEXT("#4095") )) ); assert( Atom3Found = (Atom3 == FindAtom( (LPTSTR)0x1234 )) ); printf( "FindAtom( ""Atom1"" ) == %X\n", Atom1 ); printf( "FindAtom( ""#4095"" ) == %X\n", Atom2 ); printf( "FindAtom( 0x1234 ) == %X\n", Atom3 ); Atom1Length = GetAtomName( Atom1, NameBuffer, sizeof( NameBuffer )); #ifdef UNICODE printf( "GetAtomName( %X ) == %ws\n", Atom1, NameBuffer ); #else printf( "GetAtomName( %X ) == %s\n", Atom1, NameBuffer ); #endif Atom2Length = GetAtomName( Atom2, NameBuffer, sizeof( NameBuffer )); #ifdef UNICODE printf( "GetAtomName( %X ) == %ws\n", Atom2, NameBuffer ); #else printf( "GetAtomName( %X ) == %s\n", Atom2, NameBuffer ); #endif Atom3Length = GetAtomName( Atom3, NameBuffer, sizeof( NameBuffer )); #ifdef UNICODE printf( "GetAtomName( %X ) == %ws\n", Atom3, NameBuffer ); #else printf( "GetAtomName( %X ) == %s\n", Atom3, NameBuffer ); #endif printf( "DeleteAtom( %X ) == %X\n", Atom1, DeleteAtom( Atom1 ) ); printf( "DeleteAtom( %X ) == %X\n", Atom1, DeleteAtom( Atom1 ) ); printf( "DeleteAtom( %X ) == %X\n", Atom1, DeleteAtom( Atom1 ) ); printf( "DeleteAtom( %X ) == %X\n", Atom1, DeleteAtom( Atom1 ) ); printf( "DeleteAtom( %X ) == %X\n", Atom2, DeleteAtom( Atom2 ) ); printf( "DeleteAtom( %X ) == %X\n", Atom3, DeleteAtom( Atom3 ) ); Atom1 = GlobalAddAtom( TEXT("Atom1") ); Atom2 = GlobalAddAtom( TEXT("#4095") ); Atom3 = GlobalAddAtom( (LPTSTR)0x1234 ); printf( "GlobalAddAtom( ""Atom1"" ) == %X\n", Atom1 ); printf( "GlobalAddAtom( ""#4095"" ) == %X\n", Atom2 ); printf( "GlobalAddAtom( 0x1234 ) == %X\n", Atom3 ); Atom1 = GlobalAddAtom( TEXT("Atom1") ); Atom2 = GlobalAddAtom( TEXT("#4095") ); Atom3 = GlobalAddAtom( (LPTSTR)0x1234 ); printf( "GlobalAddAtom( ""Atom1"" ) == %X\n", Atom1 ); printf( "GlobalAddAtom( ""#4095"" ) == %X\n", Atom2 ); printf( "GlobalAddAtom( 0x1234 ) == %X\n", Atom3 ); assert( Atom1Found = (Atom1 == GlobalFindAtom( TEXT("Atom1") )) ); assert( Atom2Found = (Atom2 == GlobalFindAtom( TEXT("#4095") )) ); assert( Atom3Found = (Atom3 == GlobalFindAtom( (LPTSTR)0x1234 )) ); printf( "GlobalFindAtom( ""Atom1"" ) == %X\n", Atom1 ); printf( "GlobalFindAtom( ""#4095"" ) == %X\n", Atom2 ); printf( "GlobalFindAtom( 0x1234 ) == %X\n", Atom3 ); Atom1Length = GlobalGetAtomName( Atom1, NameBuffer, sizeof( NameBuffer )); #ifdef UNICODE printf( "GlobalGetAtomName( %X ) == %ws\n", Atom1, NameBuffer ); #else printf( "GlobalGetAtomName( %X ) == %s\n", Atom1, NameBuffer ); #endif Atom2Length = GlobalGetAtomName( Atom2, NameBuffer, sizeof( NameBuffer )); #ifdef UNICODE printf( "GlobalGetAtomName( %X ) == %ws\n", Atom2, NameBuffer ); #else printf( "GlobalGetAtomName( %X ) == %s\n", Atom2, NameBuffer ); #endif Atom3Length = GlobalGetAtomName( Atom3, NameBuffer, sizeof( NameBuffer )); #ifdef UNICODE printf( "GlobalGetAtomName( %X ) == %ws\n", Atom3, NameBuffer ); #else printf( "GlobalGetAtomName( %X ) == %s\n", Atom3, NameBuffer ); #endif printf( "GlobalDeleteAtom( %X ) == %X\n", Atom1, GlobalDeleteAtom( Atom1 ) ); printf( "GlobalDeleteAtom( %X ) == %X\n", Atom1, GlobalDeleteAtom( Atom1 ) ); printf( "GlobalDeleteAtom( %X ) == %X\n", Atom1, GlobalDeleteAtom( Atom1 ) ); printf( "GlobalDeleteAtom( %X ) == %X\n", Atom1, GlobalDeleteAtom( Atom1 ) ); printf( "GlobalDeleteAtom( %X ) == %X\n", Atom2, GlobalDeleteAtom( Atom2 ) ); printf( "GlobalDeleteAtom( %X ) == %X\n", Atom3, GlobalDeleteAtom( Atom3 ) ); printf( "TATOM: Exiting Test Program\n" ); return 0; }