CVS: seamlessrdp/ServerExe/HookDll hookdll.cpp,1.29,1.30

Pierre Ossman <[email protected]>
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/seamlessrdp/ServerExe/HookDll
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27587

Modified Files:
	hookdll.cpp 
Log Message:
Add a named mutex so that all hooks will write atomically into the virtual
channel.


Index: hookdll.cpp
===================================================================
RCS file: /cvsroot/rdesktop/seamlessrdp/ServerExe/HookDll/hookdll.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** hookdll.cpp	8 Mar 2006 16:12:49 -0000	1.29
--- hookdll.cpp	8 Mar 2006 16:55:02 -0000	1.30
***************
*** 32,36 ****
  HINSTANCE hInst = 0;
  HANDLE m_vcHandle = 0;
! 
  
  void SendDebug( char *format, ... )
--- 32,36 ----
  HINSTANCE hInst = 0;
  HANDLE m_vcHandle = 0;
! HANDLE hMutex = 0;
  
  void SendDebug( char *format, ... )
***************
*** 53,72 ****
  {
      switch ( ul_reason_for_call ) {
!     case DLL_PROCESS_ATTACH: {
!             // remember our instance handle
!             hInst = hinstDLL;
!             ++iInstanceCount;
!             OpenVirtualChannel();
!             break;
!         }
  
      case DLL_THREAD_ATTACH:
          break;
      case DLL_THREAD_DETACH:
          break;
!     case DLL_PROCESS_DETACH: {
!             --iInstanceCount;
!             CloseVirtualChannel();
!         }
          break;
      }
--- 53,87 ----
  {
      switch ( ul_reason_for_call ) {
!     case DLL_PROCESS_ATTACH:
!         // remember our instance handle
!         hInst = hinstDLL;
! 
!         hMutex = CreateMutex( NULL, FALSE, "Local\\Seamless" );
!         if (!hMutex)
!             return FALSE;
! 
!         WaitForSingleObject( hMutex, INFINITE );
!         ++iInstanceCount;
!         ReleaseMutex( hMutex );
! 
!         OpenVirtualChannel();
! 
!         break;
  
      case DLL_THREAD_ATTACH:
          break;
+ 
      case DLL_THREAD_DETACH:
          break;
! 
!     case DLL_PROCESS_DETACH:
!         WaitForSingleObject( hMutex, INFINITE );
!         --iInstanceCount;
!         ReleaseMutex( hMutex );
! 
!         CloseVirtualChannel();
! 
!         CloseHandle( hMutex );
! 
          break;
      }
***************
*** 442,445 ****
--- 457,461 ----
  int WriteToChannel( PCHAR buffer )
  {
+     BOOL result;
      PULONG bytesRead = 0;
      PULONG pBytesWritten = 0;
***************
*** 448,452 ****
          return 1;
  
!     BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten );
  
      if ( result ) {
--- 464,470 ----
          return 1;
  
!     WaitForSingleObject( hMutex, INFINITE );
!     result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten );
!     ReleaseMutex( hMutex );
  
      if ( result ) {



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.