home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / qahook.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.1 KB  |  93 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. //
  19. // Necessary hooks for QA partner to access custom objects within
  20. // Communicator
  21. //
  22. #include <windows.h>
  23. #include <windowsx.h>
  24. #include "qahook.h"
  25.  
  26. static HANDLE        hSharedMemory = NULL;
  27. static CSharedData    *pData = NULL;
  28.  
  29. // 
  30. // *open existing* shared memory chunk 
  31. // once you have the pointer to the new segment 
  32. // use this pointer to access data, e.g.: 
  33. // 
  34. //  if(pData->m_dwBytesUsed > 0) 
  35. //  { 
  36. //    // use pData->m_buf here 
  37. //  } 
  38. //
  39. CSharedData *
  40. OpenExistingSharedMemory(void)
  41. {
  42. #ifdef WIN32
  43.  
  44.   DWORD dwSize;
  45.   LPCTSTR szObjectName = SHARED_MEMORY_CHUNK_NAME; 
  46.  
  47.   if (pData != NULL)
  48.       return pData;
  49.  
  50.   hSharedMemory = OpenFileMapping( 
  51.     FILE_MAP_WRITE /*PAGE_READWRITE*/,FALSE,szObjectName); 
  52.   if(hSharedMemory == 0) 
  53.   { 
  54.     return NULL; 
  55.   } 
  56.  
  57.   pData = (CSharedData *)MapViewOfFile( 
  58.     hSharedMemory,FILE_MAP_ALL_ACCESS,0,0,0); 
  59.   if(pData == NULL) 
  60.   { 
  61.     return NULL; 
  62.   } 
  63.   
  64.   dwSize = pData->m_dwSize; 
  65.   return pData;
  66. #else
  67.   return NULL;
  68. #endif  // WIN32
  69. }  
  70.  
  71. // 
  72. // to close shared memory segment
  73. // 
  74. void
  75. CloseSharedMemory(void)
  76. {
  77. #ifdef WIN32
  78.   if (pData != 0) 
  79.   { 
  80.     UnmapViewOfFile(pData); 
  81.     pData = 0; 
  82.   } 
  83.  
  84.   if(hSharedMemory != 0) 
  85.   { 
  86.     CloseHandle(hSharedMemory); 
  87.     hSharedMemory = 0; 
  88.   } 
  89. #else
  90.   return;
  91. #endif    // WIN32
  92. }
  93.