merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / svdde / ddeml2.cxx
blob5398d680d859214974e823d93b6be37564849fb9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ddeml2.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define INCL_DOS
35 #include <stdlib.h>
37 #include "ddemlimp.hxx"
38 #define LOGFILE
39 #define STATUSFILE
40 #define DDEDATAFILE
41 #include "ddemldeb.hxx"
43 #if defined (OS2) && defined (__BORLANDC__)
44 #pragma option -w-par
45 #endif
48 // ************************************************************************
49 // Hilfsfunktionen Speicherverwaltung
50 // ************************************************************************
53 // AllocAtomName
56 PSZ ImpDdeMgr::AllocAtomName( ATOM hString, ULONG& rBufLen )
58 HATOMTBL hAtomTable = WinQuerySystemAtomTable();
59 ULONG nLen = WinQueryAtomLength( hAtomTable, hString );
60 nLen++;
61 PSZ pBuf = 0;
62 if ( !MyDosAllocMem( (PPVOID)&pBuf, nLen, PAG_READ|PAG_WRITE|PAG_COMMIT | OBJ_ANY,"Atom" ) )
64 WinQueryAtomName( hAtomTable, hString, pBuf, nLen );
65 rBufLen = nLen;
67 return pBuf;
72 // MakeDDEObject
75 PDDESTRUCT ImpDdeMgr::MakeDDEObject( HWND hwnd, ATOM hItemName,
76 USHORT fsStatus, USHORT usFormat, PVOID pabData, ULONG usDataLen )
78 PDDESTRUCT pddes = 0;
79 ULONG usItemLen;
80 PULONG pulSharedObj;
81 //WRITELOG("MakeDDEObject: Start")
83 PSZ pItemName = 0;
84 if( hItemName != NULL )
85 pItemName = AllocAtomName( hItemName, usItemLen );
86 else
87 usItemLen = 1;
89 ULONG nTotalSize = sizeof(DDESTRUCT) + usItemLen + usDataLen;
91 if( !(MyDosAllocSharedMem((PPVOID)&pulSharedObj, NULL,
92 nTotalSize,
93 PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GETTABLE | OBJ_GIVEABLE | OBJ_ANY,
94 "MakeDDEObject")))
96 pddes = (PDDESTRUCT) pulSharedObj;
97 // siehe "Glenn Puchtel, DDE for OS/2" p.60
98 pddes->cbData = (ULONG)usDataLen;
99 pddes->fsStatus = fsStatus;
100 pddes->usFormat = usFormat;
101 pddes->offszItemName = sizeof( DDESTRUCT );
102 if( (usDataLen) && (pabData != NULL ) )
103 pddes->offabData = sizeof(DDESTRUCT) + usItemLen;
104 else
105 pddes->offabData = 0;
107 if( pItemName != NULL )
108 memcpy(DDES_PSZITEMNAME(pddes), pItemName, usItemLen );
109 else
110 *(DDES_PSZITEMNAME(pddes)) = '\0';
112 if( pabData != NULL )
113 memcpy( DDES_PABDATA(pddes), pabData, usDataLen );
116 if ( pItemName )
118 MyDosFreeMem( pItemName,"MakeDDEObject" );
120 return pddes;
124 // AllocNamedSharedMem
127 APIRET ImpDdeMgr::AllocNamedSharedMem( PPVOID ppBaseAddress, PSZ pName,
128 ULONG nElementSize, ULONG nElementCount )
130 ULONG nObjSize = (ULONG)(nElementSize * nElementCount );
131 nObjSize += sizeof( ULONG ); // fuer ElementCount am Anfang des Blocks
133 *ppBaseAddress = 0;
134 APIRET nRet = MyDosAllocSharedMem( ppBaseAddress, pName, nObjSize,
135 PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_ANY,
136 "AllocNamedSharedMem" );
137 if ( !nRet )
139 memset( *ppBaseAddress, 0, nObjSize );
140 ULONG* pULONG = (ULONG*)*ppBaseAddress;
141 *pULONG = nObjSize;
143 return nRet;
146 void ImpDdeMgr::CreateServerWnd()
148 hWndServer = WinCreateWindow( HWND_DESKTOP, WC_FRAME, "DDEServer", 0,
149 0,0,0,0, HWND_DESKTOP, HWND_BOTTOM, 0, 0, 0 );
150 WinSetWindowULong( hWndServer, 0, (ULONG)this );
151 WinSubclassWindow( hWndServer, ::ServerWndProc );
152 TID tidDummy;
153 WinQueryWindowProcess( hWndServer, &pidThis, &tidDummy );
156 void ImpDdeMgr::DestroyServerWnd()
158 WinDestroyWindow( hWndServer );
159 hWndServer = NULLHANDLE;
162 HWND ImpDdeMgr::CreateConversationWnd()
164 HWND hWnd = WinCreateWindow( HWND_OBJECT, WC_FRAME, "DDEConvWnd", 0,
165 0,0,0,0, HWND_DESKTOP, HWND_BOTTOM, 0, 0, 0 );
166 if ( hWnd )
168 ImpConvWndData* pWndData = new ImpConvWndData;
169 pWndData->pThis = this;
170 pWndData->nRefCount = 0;
171 WinSetWindowULong( hWnd, 0, (ULONG)pWndData );
172 WinSubclassWindow( hWnd, ::ConvWndProc );
173 #if 0 && defined( OV_DEBUG )
174 String aStr("ConvWnd created:");
175 aStr += (ULONG)hWnd;
176 WRITELOG((char*)aStr.GetStr())
177 #endif
179 else
180 nLastErrInstance = DMLERR_SYS_ERROR;
182 return hWnd;
185 // static
186 void ImpDdeMgr::DestroyConversationWnd( HWND hWnd )
188 ImpConvWndData* pObj = (ImpConvWndData*)WinQueryWindowULong( hWnd, 0 );
189 if( pObj )
191 pObj->nRefCount--;
192 if( pObj->nRefCount == 0
193 // auch Windows mit Refcount vonm loeschen, da dieser in initial
194 // auf 0 gesetzt wird
195 || pObj->nRefCount == (USHORT)-1 )
197 delete pObj;
198 WinDestroyWindow( hWnd );
199 #if 0 && defined( OV_DEBUG )
200 String aStr("ConvWnd destroyed:");
201 aStr += (ULONG)hWnd;
202 WRITELOG((char*)aStr.GetStr())
203 #endif
205 else
207 #if 0 && defined( OV_DEBUG )
208 String aStr("ConvWnd not destroyed (Refcount=");
209 aStr += pObj->nRefCount;
210 aStr += ") "; aStr += (ULONG)hWnd;
211 WRITELOG((char*)aStr.GetStr())
212 #endif
215 #if defined( OV_DEBUG )
216 else
218 WRITELOG("DestroyCnvWnd:Already destroyed/No win data/Partner died")
220 #endif
223 // static
224 USHORT ImpDdeMgr::GetConversationWndRefCount( HWND hWnd )
226 ImpConvWndData* pObj = (ImpConvWndData*)WinQueryWindowULong( hWnd, 0 );
227 DBG_ASSERT(pObj,"Dde:ConvWnd has no data");
228 if( pObj )
229 return pObj->nRefCount;
230 return 0;
233 // static
234 USHORT ImpDdeMgr::IncConversationWndRefCount( HWND hWnd )
236 #if 0 && defined( OV_DEBUG )
237 String aStr("IncConversationWndRefCount ");
238 aStr += (ULONG)hWnd;
239 WRITELOG((char*)aStr.GetStr())
240 #endif
241 ImpConvWndData* pObj = (ImpConvWndData*)WinQueryWindowULong( hWnd, 0 );
242 DBG_ASSERT(pObj,"Dde:ConvWnd has no data");
243 if( pObj )
245 pObj->nRefCount++;
246 return pObj->nRefCount;
248 return 0;
251 ImpDdeMgrData* ImpDdeMgr::InitAll()
253 ImpDdeMgrData* pBase = 0;
254 // nur dann neu anlegen, wenn die Tabelle nicht existiert
255 APIRET nRet=DosGetNamedSharedMem((PPVOID)&pBase,DDEMLDATA,PAG_READ| PAG_WRITE);
256 if ( nRet )
258 if ( nRet == 2 ) // ERROR_FILE_NOT_FOUND )
260 // DDECONVERSATIONCOUNT=4096
261 USHORT nConvTransCount = 128;
262 PSZ pResult;
263 nRet = DosScanEnv( "SOMAXDDECONN", (const char**)&pResult );
264 if( !nRet )
266 int nTemp = 0;
267 nTemp = atoi( pResult );
268 nTemp++; // der nullte Eintrag wird nicht benutzt
269 if( nTemp > 128 )
270 nConvTransCount = (USHORT)nTemp;
272 ULONG nSize = sizeof(ImpDdeMgrData);
273 nSize += sizeof(ImpHCONV) * nConvTransCount;
274 nSize += sizeof(Transaction) * nConvTransCount;
275 nSize += sizeof(HWND) * DDEMLAPPCOUNT;
277 nRet = ImpDdeMgr::AllocNamedSharedMem( (PPVOID)&pBase,
278 DDEMLDATA, nSize, 1 );
279 if ( !nRet )
281 pBase->nTotalSize = nSize;
282 ULONG nAppTable = (ULONG)&(pBase->aAppTable);
283 ULONG nCharBase = (ULONG)pBase;
284 pBase->nOffsAppTable = nAppTable - nCharBase;
285 pBase->nOffsConvTable = pBase->nOffsAppTable;
286 pBase->nOffsConvTable += sizeof(HWND) * DDEMLAPPCOUNT;
287 pBase->nOffsTransTable = pBase->nOffsConvTable;
288 pBase->nOffsTransTable += sizeof(ImpHCONV) * nConvTransCount;
290 pBase->nMaxAppCount = DDEMLAPPCOUNT;
291 pBase->nMaxConvCount = nConvTransCount;
292 pBase->nMaxTransCount = nConvTransCount;
297 if( pBase )
299 pConvTable = ImpDdeMgr::GetConvTable( pBase );
300 pTransTable = ImpDdeMgr::GetTransTable( pBase );
301 pAppTable = ImpDdeMgr::GetAppTable( pBase );
304 memset( &aDefaultContext, 0, sizeof(CONVCONTEXT) );
305 aDefaultContext.cb = sizeof(CONVCONTEXT);
306 aDefaultContext.idCountry = 49; // ??
307 aDefaultContext.usCodepage = 850; // ??
309 return pBase;
312 // static
313 HCONV ImpDdeMgr::CreateConvHandle( ImpDdeMgrData* pData,
314 PID pidOwner,
315 HWND hWndMe, HWND hWndPartner,
316 HSZ hszPartner, HSZ hszServiceReq, HSZ hszTopic,
317 HCONV hPrevHCONV )
319 DBG_ASSERT(pData,"DDE:Invalid data");
320 if( !pData )
321 return (HCONV)0;
323 ImpHCONV* pPtr = ImpDdeMgr::GetConvTable( pData );
324 USHORT nCount = pData->nMaxConvCount;
325 pPtr++;
326 nCount--; // ersten Handle (NULLHANDLE) ueberspringen
327 USHORT nIdx = 1;
328 DBG_ASSERT(pPtr,"No ConvTable");
329 if( !pPtr )
330 return (HCONV)0;
332 while( nCount && pPtr->hWndThis != (HWND)NULL )
334 nCount--;
335 pPtr++;
336 nIdx++;
338 if( !nCount )
339 return (HCONV)0;
341 DdeKeepStringHandle( hszPartner );
342 DdeKeepStringHandle( hszServiceReq );
343 DdeKeepStringHandle( hszTopic );
344 pPtr->hszPartner = hszPartner;
345 pPtr->hszServiceReq = hszServiceReq;
346 pPtr->hszTopic = hszTopic;
348 pPtr->hWndThis = hWndMe;
349 pPtr->hWndPartner = hWndPartner;
350 pPtr->pidOwner = pidOwner;
351 pPtr->hConvPartner = (HCONV)0;
352 pPtr->nPrevHCONV = (USHORT)hPrevHCONV;
353 pPtr->nNextHCONV = 0;
354 pPtr->nStatus = ST_CONNECTED;
356 pData->nCurConvCount++;
358 return (HCONV)nIdx;
361 // static
362 void ImpDdeMgr::FreeConvHandle( ImpDdeMgrData* pBase, HCONV hConv,
363 BOOL bDestroyHWndThis )
365 DBG_ASSERT(pBase,"DDE:No data");
366 #if 0 && defined( OV_DEBUG )
367 String aStr("FreeConvHandle: Start ");
368 aStr += (ULONG)hConv;
369 aStr += " Destroy: "; aStr += (USHORT)bDestroyHWndThis;
370 WRITELOG((char*)aStr.GetStr());
371 WRITESTATUS("FreeConvHandle: Start");
372 #endif
373 if( !pBase )
375 WRITELOG("FreeConvHandle: FAIL");
376 return;
378 DBG_ASSERT(hConv&&hConv<pBase->nMaxConvCount,"DDE:Invalid Conv-Handle");
379 if( hConv && hConv < pBase->nMaxConvCount )
381 ImpHCONV* pTable = ImpDdeMgr::GetConvTable( pBase );
382 ImpHCONV* pPtr = pTable + (USHORT)hConv;
383 if( pPtr->nStatus & ST_INLIST )
385 // Verkettung umsetzen
386 USHORT nPrev = pPtr->nPrevHCONV;
387 USHORT nNext = pPtr->nNextHCONV;
388 if( nPrev )
390 pPtr = pTable + nPrev;
391 pPtr->nNextHCONV = nNext;
393 if( nNext )
395 pPtr = pTable + nNext;
396 pPtr->nPrevHCONV = nPrev;
398 pPtr = pTable + (USHORT)hConv;
401 DdeFreeStringHandle( pPtr->hszPartner );
402 DdeFreeStringHandle( pPtr->hszServiceReq );
403 DdeFreeStringHandle( pPtr->hszTopic );
404 if( bDestroyHWndThis )
405 DestroyConversationWnd( pPtr->hWndThis );
406 memset( pPtr, 0, sizeof(ImpHCONV) );
407 DBG_ASSERT(pBase->nCurConvCount,"Dde:Invalid Trans. count");
408 pBase->nCurConvCount--;
410 #if defined(OV_DEBUG)
411 else
413 WRITELOG("FreeConvHandle: FAIL");
415 #endif
416 //WRITELOG("FreeConvHandle: END");
417 //WRITESTATUS("FreeConvHandle: End");
420 // static
421 HCONV ImpDdeMgr::IsConvHandleAvailable( ImpDdeMgrData* pBase )
423 DBG_ASSERT(pBase,"DDE:No data");
424 if( !pBase )
425 return 0;
427 ImpHCONV* pPtr = ImpDdeMgr::GetConvTable( pBase );
428 USHORT nCurPos = pBase->nMaxConvCount - 1;
429 pPtr += nCurPos; // von hinten aufrollen
430 while( nCurPos >= 1 )
432 if( pPtr->hWndThis == 0 )
433 return TRUE;
434 pPtr--;
435 nCurPos--;
437 return FALSE;
440 // static
441 HCONV ImpDdeMgr::GetConvHandle( ImpDdeMgrData* pBase, HWND hWndThis,
442 HWND hWndPartner )
444 DBG_ASSERT(pBase,"DDE:No data");
445 if( !pBase )
446 return 0;
447 ImpHCONV* pPtr = ImpDdeMgr::GetConvTable( pBase );
448 USHORT nCurPos = 1;
449 pPtr++; // ersten Handle ueberspringen
450 USHORT nCurConvCount = pBase->nCurConvCount;
451 while( nCurConvCount && nCurPos < pBase->nMaxConvCount )
453 if( pPtr->hWndThis )
455 if(pPtr->hWndThis == hWndThis && pPtr->hWndPartner == hWndPartner)
456 return (HCONV)nCurPos;
457 nCurConvCount--;
458 if( !nCurConvCount )
459 return (HCONV)0;
461 nCurPos++;
462 pPtr++;
464 return (HCONV)0;
469 // static
470 ULONG ImpDdeMgr::CreateTransaction( ImpDdeMgrData* pBase, HCONV hOwner,
471 HSZ hszItem, USHORT nFormat, USHORT nTransactionType )
473 DBG_ASSERT(pBase,"DDE:No Data");
474 DBG_ASSERT(hOwner!=0,"DDE:No Owner");
476 if( pBase && hOwner )
478 Transaction* pPtr = ImpDdeMgr::GetTransTable( pBase );
479 DBG_ASSERT(pPtr->hConvOwner==0,"DDE:Data corrupted");
480 USHORT nId = 1;
481 pPtr++;
482 while( nId < pBase->nMaxTransCount )
484 if( pPtr->hConvOwner == (HCONV)0 )
486 pPtr->hConvOwner = hOwner;
487 DdeKeepStringHandle( hszItem );
488 pPtr->hszItem = hszItem;
489 pPtr->nType = nTransactionType;
490 pPtr->nConvst = XST_CONNECTED;
491 pPtr->nFormat = nFormat;
492 pBase->nCurTransCount++;
493 return (ULONG)nId;
495 nId++;
496 pPtr++;
499 return 0;
502 // static
503 void ImpDdeMgr::FreeTransaction( ImpDdeMgrData* pBase, ULONG nTransId )
505 DBG_ASSERT(pBase,"DDE:No Data");
506 if( !pBase )
507 return;
509 DBG_ASSERT(nTransId<pBase->nMaxTransCount,"DDE:Invalid TransactionId");
510 if( nTransId >= pBase->nMaxTransCount )
511 return;
513 Transaction* pPtr = ImpDdeMgr::GetTransTable( pBase );
514 pPtr += nTransId;
515 DBG_ASSERT(pPtr->hConvOwner!=0,"DDE:TransId has no owner");
516 if( pPtr->hConvOwner )
518 //WRITELOG("Freeing transaction");
519 DdeFreeStringHandle( pPtr->hszItem );
520 memset( pPtr, 0, sizeof(Transaction) );
521 DBG_ASSERT(pBase->nCurTransCount,"Dde:Invalid Trans. count");
522 pBase->nCurTransCount--;
526 // static
527 ULONG ImpDdeMgr::GetTransaction( ImpDdeMgrData* pBase,
528 HCONV hOwner, HSZ hszItem, USHORT nFormat )
530 DBG_ASSERT(pBase,"DDE:No Data");
531 if( !pBase || !hOwner )
532 return 0;
534 Transaction* pTrans = ImpDdeMgr::GetTransTable( pBase );
535 DBG_ASSERT(pTrans,"DDE:No TransactionTable");
536 if( !pTrans )
537 return 0;
538 pTrans++; // NULLHANDLE ueberspringen
540 ImpHCONV* pConv = ImpDdeMgr::GetConvTable( pBase );
541 pConv += (USHORT)hOwner;
542 HCONV hConvPartner = pConv->hConvPartner;
544 USHORT nCurTransCount = pBase->nCurTransCount;
545 for( USHORT nTrans=1; nTrans< pBase->nMaxTransCount; nTrans++, pTrans++ )
547 if( pTrans->hConvOwner )
549 if(( pTrans->hConvOwner == hOwner ||
550 pTrans->hConvOwner == hConvPartner) &&
551 pTrans->nFormat == nFormat &&
552 pTrans->hszItem == hszItem )
554 // gefunden!
555 return (ULONG)nTrans;
557 nCurTransCount--;
558 if( !nCurTransCount )
559 return 0;
562 return 0; // narda
565 // static
566 HSZ ImpDdeMgr::DdeCreateStringHandle( PSZ pszString, int iCodePage)
568 if( !pszString || *pszString == '\0' )
569 return (HSZ)0;
570 // Atom-Table beachtet Gross/Kleinschreibung, DDEML aber nicht
572 // OV 12.4.96: Services,Topics,Items case-sensitiv!!!
573 // (Grosskundenanforderung (Reuter-DDE))
574 //strlwr( pszString );
575 //*pszString = (char)toupper(*pszString);
577 HATOMTBL hAtomTable = WinQuerySystemAtomTable();
578 ATOM aAtom = WinAddAtom( hAtomTable, pszString );
579 return (HSZ)aAtom;
582 // static
583 ULONG ImpDdeMgr::DdeQueryString( HSZ hszStr, PSZ pszStr, ULONG cchMax, int iCodePage)
585 HATOMTBL hAtomTable = WinQuerySystemAtomTable();
586 if ( !pszStr )
587 return WinQueryAtomLength( hAtomTable, (ATOM)hszStr);
588 else
590 *pszStr = 0;
591 return WinQueryAtomName( hAtomTable, (ATOM)hszStr, pszStr, cchMax );
595 // static
596 BOOL ImpDdeMgr::DdeFreeStringHandle( HSZ hsz )
598 if( !hsz )
599 return FALSE;
600 ATOM aResult = WinDeleteAtom( WinQuerySystemAtomTable(),(ATOM)hsz );
601 return (BOOL)(aResult==0);
604 // static
605 BOOL ImpDdeMgr::DdeKeepStringHandle( HSZ hsz )
607 if( !hsz )
608 return TRUE;
609 HATOMTBL hAtomTable = WinQuerySystemAtomTable();
610 #ifdef DBG_UTIL
611 ULONG nUsageCount=WinQueryAtomUsage(hAtomTable,(ATOM)hsz);
612 #endif
613 ULONG nAtom = 0xFFFF0000;
614 ULONG nPar = (ULONG)hsz;
615 nAtom |= nPar;
616 ATOM aAtom = WinAddAtom( hAtomTable, (PSZ)nAtom );
617 #ifdef DBG_UTIL
618 if ( aAtom )
619 DBG_ASSERT(WinQueryAtomUsage(hAtomTable,(ATOM)hsz)==nUsageCount+1,"Keep failed");
620 #endif
621 return (BOOL)(aAtom!=0);
625 // static
626 int ImpDdeMgr::DdeCmpStringHandles(HSZ hsz1, HSZ hsz2)
628 if ( hsz1 == hsz2 )
629 return 0;
630 if ( hsz1 < hsz2 )
631 return -1;
632 return 1;
635 HDDEDATA ImpDdeMgr::DdeCreateDataHandle( void* pSrc, ULONG cb,
636 ULONG cbOff, HSZ hszItem, USHORT wFmt, USHORT afCmd)
638 char* pData = (char*)pSrc;
639 pData += cbOff;
640 USHORT nStatus;
641 if( afCmd & HDATA_APPOWNED )
642 nStatus = IMP_HDATAAPPOWNED;
643 else
644 nStatus = 0;
645 PDDESTRUCT hData=MakeDDEObject(0,(ATOM)hszItem,nStatus,wFmt,pData,cb);
646 // WRITEDATA(hData)
647 if ( !hData )
648 ImpDdeMgr::nLastErrInstance = DMLERR_INVALIDPARAMETER;
649 return (HDDEDATA)hData;
652 // static
653 BYTE* ImpDdeMgr::DdeAccessData(HDDEDATA hData, ULONG* pcbDataSize)
655 BYTE* pRet = 0;
656 *pcbDataSize = 0;
657 if ( hData )
659 pRet = (BYTE*)hData;
660 pRet += hData->offabData;
661 ULONG nLen = hData->cbData;
662 // nLen -= hData->offabData;
663 *pcbDataSize = nLen;
665 else
666 ImpDdeMgr::nLastErrInstance = DMLERR_INVALIDPARAMETER;
667 return pRet;
670 // static
671 BOOL ImpDdeMgr::DdeUnaccessData(HDDEDATA hData)
673 return TRUE; // nothing to do for us
676 // static
677 BOOL ImpDdeMgr::DdeFreeDataHandle(HDDEDATA hData)
679 DdeUnaccessData( hData );
680 MyDosFreeMem( (PSZ)hData, "DdeFreeDataHandle" );
681 return TRUE;
684 // static
685 HDDEDATA ImpDdeMgr::DdeAddData(HDDEDATA hData,void* pSrc,ULONG cb,ULONG cbOff)
687 return (HDDEDATA)0;
690 // static
691 ULONG ImpDdeMgr::DdeGetData(HDDEDATA hData,void* pDst,ULONG cbMax,ULONG cbOff)
693 return 0;
696 BOOL ImpDdeMgr::DisconnectAll()
698 //WRITESTATUS("Before DisconnectAll()")
699 USHORT nCurConvCount = pData->nCurConvCount;
700 if( !nCurConvCount )
701 return TRUE;
703 BOOL bRet = TRUE;
704 ImpHCONV* pPtr = pConvTable;
705 pPtr++;
707 for( USHORT nPos=1; nPos < pData->nMaxConvCount; nPos++, pPtr++ )
709 if( pPtr->hWndThis )
711 if( !DdeDisconnect( (HCONV)nPos ) )
712 bRet = FALSE;
713 nCurConvCount--;
714 if( !nCurConvCount )
715 break;
718 //WRITESTATUS("After DisconnectAll()")
719 return bRet;
722 // static
723 void ImpDdeMgr::FreeTransactions( ImpDdeMgrData* pData,HWND hWndThis,
724 HWND hWndPartner )
726 USHORT nCurTransCount = pData->nCurTransCount;
727 if( !nCurTransCount )
728 return;
730 Transaction* pTrans = GetTransTable( pData );
731 ImpHCONV* pConvTable = GetConvTable( pData );
732 pTrans++;
733 for( USHORT nPos=1; nPos < pData->nMaxTransCount; nPos++, pTrans++ )
735 if( pTrans->hConvOwner )
737 ImpHCONV* pConv = pConvTable + (USHORT)(pTrans->hConvOwner);
738 if((pConv->hWndThis==hWndThis&& pConv->hWndPartner==hWndPartner)||
739 (pConv->hWndThis==hWndPartner && pConv->hWndPartner==hWndThis))
741 FreeTransaction( pData, (ULONG)nPos );
743 nCurTransCount--;
744 if( !nCurTransCount )
745 return;
750 // static
751 void ImpDdeMgr::FreeTransactions( ImpDdeMgrData* pData, HCONV hConvOwner )
753 USHORT nCurTransCount = pData->nCurTransCount;
754 if( !nCurTransCount )
755 return;
757 Transaction* pTrans = GetTransTable( pData );
758 // ImpHCONV* pConvTable = GetConvTable( pData );
759 pTrans++;
760 for( USHORT nPos=1; nPos < pData->nMaxTransCount; nPos++, pTrans++ )
762 if( pTrans->hConvOwner == hConvOwner )
764 FreeTransaction( pData, (ULONG)nPos );
765 nCurTransCount--;
766 if( !nCurTransCount )
767 return;
772 // static
773 void ImpDdeMgr::FreeConversations( ImpDdeMgrData* pData, HWND hWndThis,
774 HWND hWndPartner )
776 USHORT nCurCount = pData->nCurConvCount;
777 if( !nCurCount )
778 return;
780 ImpHCONV* pPtr = GetConvTable( pData );
781 pPtr++;
782 for( USHORT nPos=1; nPos < pData->nMaxConvCount; nPos++, pPtr++ )
784 if( pPtr->hWndThis )
786 if( hWndThis && pPtr->hWndPartner==hWndPartner )
787 FreeConvHandle( pData, (HCONV)nPos );
788 nCurCount--;
789 if( !nCurCount )
790 return;
796 BOOL ImpDdeMgr::OwnsConversationHandles()
798 //WRITESTATUS("OwnsConversationHandles()");
799 #if 0 && defined( OV_DEBUG )
800 String aStr("OwnsConversationHandles Server:");
801 aStr += (ULONG)hWndServer;
802 WRITELOG((char*)aStr.GetStr())
803 #endif
804 ImpHCONV* pPtr = GetConvTable( pData );
805 for( USHORT nCur = 1; nCur < pData->nMaxConvCount; nCur++, pPtr++ )
807 if( pPtr->hWndThis && pPtr->pidOwner == pidThis )
809 //WRITELOG("OwnsConversationHandles: TRUE");
810 return TRUE;
813 // WRITELOG("OwnsConversationHandles: FALSE");
814 return FALSE;
819 // *********************************************************************
820 // *********************************************************************
821 // *********************************************************************
823 USHORT DdeInitialize(ULONG* pidInst, PFNCALLBACK pfnCallback,
824 ULONG afCmd, ULONG ulRes)
826 if( (*pidInst)!=0 )
828 // Reinitialize wird noch nicht unterstuetzt
829 DBG_ASSERT(0,"DDEML:Reinitialize not supported");
830 return DMLERR_INVALIDPARAMETER;
833 ImpDdeMgr* pMgr = new ImpDdeMgr;
834 *pidInst = (ULONG)pMgr;
835 return pMgr->DdeInitialize( pfnCallback, afCmd );
838 BOOL DdeUninitialize(ULONG idInst)
840 if( !idInst )
841 return FALSE;
842 ImpDdeMgr* pMgr = (ImpDdeMgr*)idInst;
843 // nur loeschen, wenn wir nicht mehr benutzt werden!
844 if( !pMgr->OwnsConversationHandles() )
846 WRITELOG("DdeUninitialize: TRUE");
847 delete pMgr;
848 return TRUE;
850 WRITELOG("DdeUninitialize: FALSE");
851 return FALSE;
855 HCONVLIST DdeConnectList(ULONG idInst, HSZ hszService, HSZ hszTopic,
856 HCONVLIST hConvList, CONVCONTEXT* pCC)
858 if( !idInst )
859 return 0;
860 return ((ImpDdeMgr*)idInst)->DdeConnectList(hszService,hszTopic,
861 hConvList, pCC );
864 HCONV DdeQueryNextServer(HCONVLIST hConvList, HCONV hConvPrev)
866 return ImpDdeMgr::DdeQueryNextServer( hConvList, hConvPrev );
869 BOOL DdeDisconnectList(HCONVLIST hConvList)
871 return ImpDdeMgr::DdeDisconnectList( hConvList );
874 HCONV DdeConnect(ULONG idInst, HSZ hszService, HSZ hszTopic,
875 CONVCONTEXT* pCC)
877 if( !idInst )
878 return 0;
879 return ((ImpDdeMgr*)idInst)->DdeConnect( hszService, hszTopic, pCC );
882 BOOL DdeDisconnect(HCONV hConv)
884 return ImpDdeMgr::DdeDisconnect( hConv );
887 HCONV DdeReconnect(HCONV hConv)
889 return ImpDdeMgr::DdeReconnect( hConv );
893 USHORT DdeQueryConvInfo(HCONV hConv, ULONG idTransact, CONVINFO* pCI )
895 return ImpDdeMgr::DdeQueryConvInfo( hConv, idTransact, pCI );
898 BOOL DdeSetUserHandle(HCONV hConv, ULONG id, ULONG hUser)
900 return ImpDdeMgr::DdeSetUserHandle( hConv, id, hUser );
903 BOOL DdeAbandonTransaction(ULONG idInst, HCONV hConv, ULONG idTransaction)
905 if( !idInst )
906 return FALSE;
907 return ((ImpDdeMgr*)idInst)->DdeAbandonTransaction(hConv,idTransaction);
910 BOOL DdePostAdvise(ULONG idInst, HSZ hszTopic, HSZ hszItem)
912 if( !idInst )
913 return FALSE;
914 return ((ImpDdeMgr*)idInst)->DdePostAdvise( hszTopic, hszItem );
917 BOOL DdeEnableCallback(ULONG idInst, HCONV hConv, USHORT wCmd)
919 if( !idInst )
920 return FALSE;
921 return ((ImpDdeMgr*)idInst)->DdeEnableCallback( hConv, wCmd );
924 HDDEDATA DdeClientTransaction(void* pData, ULONG cbData,
925 HCONV hConv, HSZ hszItem, USHORT wFmt, USHORT wType,
926 ULONG dwTimeout, ULONG* pdwResult)
928 return ImpDdeMgr::DdeClientTransaction( pData, cbData,
929 hConv, hszItem, wFmt, wType, dwTimeout, pdwResult );
932 HDDEDATA DdeCreateDataHandle(ULONG idInst, void* pSrc, ULONG cb,
933 ULONG cbOff, HSZ hszItem, USHORT wFmt, USHORT afCmd)
935 if( !idInst )
936 return 0;
937 return ((ImpDdeMgr*)idInst)->DdeCreateDataHandle( pSrc, cb,
938 cbOff, hszItem, wFmt, afCmd );
941 HDDEDATA DdeAddData(HDDEDATA hData, void* pSrc, ULONG cb, ULONG cbOff)
943 return ImpDdeMgr::DdeAddData( hData, pSrc, cb, cbOff );
946 ULONG DdeGetData(HDDEDATA hData, void* pDst, ULONG cbMax, ULONG cbOff)
948 return ImpDdeMgr::DdeGetData( hData, pDst, cbMax, cbOff );
951 BYTE* DdeAccessData(HDDEDATA hData, ULONG* pcbDataSize)
953 return ImpDdeMgr::DdeAccessData( hData, pcbDataSize );
956 BOOL DdeUnaccessData(HDDEDATA hData)
958 return ImpDdeMgr::DdeUnaccessData( hData );
961 BOOL DdeFreeDataHandle(HDDEDATA hData)
963 return ImpDdeMgr::DdeFreeDataHandle( hData );
966 USHORT DdeGetLastError(ULONG idInst)
968 if( !idInst )
969 return DMLERR_DLL_NOT_INITIALIZED;
970 return ((ImpDdeMgr*)idInst)->DdeGetLastError();
973 HSZ DdeCreateStringHandle(ULONG idInst, PSZ pszString,int iCodePage )
975 if( !idInst )
976 return 0;
977 return ((ImpDdeMgr*)idInst)->DdeCreateStringHandle(pszString,iCodePage);
980 ULONG DdeQueryString( ULONG idInst, HSZ hsz, PSZ pBuf,
981 ULONG cchMax, int iCodePage )
983 if( !idInst )
984 return 0;
985 return ((ImpDdeMgr*)idInst)->DdeQueryString( hsz,pBuf,cchMax,iCodePage);
988 BOOL DdeFreeStringHandle( ULONG idInst, HSZ hsz)
990 if( !idInst )
991 return FALSE;
992 return ((ImpDdeMgr*)idInst)->DdeFreeStringHandle( hsz );
995 BOOL DdeKeepStringHandle( ULONG idInst, HSZ hsz )
997 if( !idInst )
998 return FALSE;
999 return ((ImpDdeMgr*)idInst)->DdeKeepStringHandle( hsz );
1002 int DdeCmpStringHandles(HSZ hsz1, HSZ hsz2)
1004 return ImpDdeMgr::DdeCmpStringHandles( hsz1, hsz2 );
1007 HDDEDATA DdeNameService( ULONG idInst, HSZ hsz1, HSZ hszRes, USHORT afCmd )
1009 if( !idInst )
1010 return 0;
1011 return ((ImpDdeMgr*)idInst)->DdeNameService( hsz1, afCmd );