home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / ADS / CPP / DDE / DDEGLOB.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  4.3 KB  |  128 lines

  1. /* 
  2.     DDEGLOB.CPP -
  3.     
  4.     This file:
  5.  
  6.         Defines global objects DDE_GLOBAL, this object is 
  7.         created once and only once to set up some essential
  8.         information in a ADS DDE application, such as connection
  9.         to ACAD and the global DDE instance ID.
  10.  
  11.  
  12.     (C) Copyright 1988-1994 by Autodesk, Inc.
  13.  
  14.     This program is copyrighted by Autodesk, Inc. and is  licensed
  15.     to you under the following conditions.  You may not distribute
  16.     or  publish the source code of this program in any form.   You
  17.     may  incorporate this code in object form in derivative  works
  18.     provided  such  derivative  works  are  (i.) are  designed and
  19.     intended  to  work  solely  with  Autodesk, Inc. products, and
  20.     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright
  21.     1988-1994 by Autodesk, Inc."
  22.  
  23.     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  24.     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  25.     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  26.     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  27.     UNINTERRUPTED OR ERROR FREE.
  28.  
  29. */
  30. #include "ddeinc.h"
  31.  
  32. #ifdef DDEADS_DBG
  33. static char     dbg_string[256];
  34. #endif
  35.  
  36. //-----------------------------------------------------------------------------
  37. // 
  38. // This variable should be the only DDE variable in a program
  39. //
  40. //-----------------------------------------------------------------------------
  41. DWORD                   DDE_GLOBAL::InstId = 0;
  42. SERVER_INFO*            DDE_GLOBAL::acad_info = NULL;
  43. DDE_CLIENT_CONNECTION*  DDE_GLOBAL::acad_connection = NULL;
  44. SS_SERVER_INFO*         DDE_GLOBAL::excel_server_info = NULL;
  45.  
  46. DDE_GLOBAL              dde_global;
  47.  
  48. //-----------------------------------------------------------------------------
  49. DDE_GLOBAL::DDE_GLOBAL()
  50. {
  51.     //
  52.     // First step: initialize the instance id
  53.     //
  54.     if ( DdeInitialize( &InstId
  55.                         , ( PFNCALLBACK ) ( FARPROC )DDE_CLIENT_CONNECTION::ClientCallBack
  56.                         , APPCMD_CLIENTONLY
  57.                         , 0 )
  58.                         != DMLERR_NO_ERROR )
  59.     {
  60.         ::MessageBox( 0
  61.                     , "Initialization failed."
  62.                     , "DDEML client connection"
  63.                     , MB_ICONSTOP|MB_TASKMODAL);
  64.         exit( 0 );
  65.     }
  66. #ifdef DDEADS_DBG
  67.     wsprintf( dbg_string
  68.             , " DdeInitialized: this = %lx InstId = %lx"
  69.             , this
  70.             , InstId );
  71.     OutputDebugString( dbg_string );
  72. #endif
  73.  
  74.     //
  75.     // Initialize acad connection
  76.     //
  77.     acad_info = new SERVER_INFO( ACAD_REG_KEY, R13ACAD );
  78.     acad_connection = new DDE_CLIENT_CONNECTION( *acad_info );
  79.     acad_connection->Init( ADS_STRING( "AutoCAD.r13.DDE" )
  80.                             , ADS_STRING( "System" )
  81.                             , ADS_STRING( "" ) );
  82.     ( DDE_GLOBAL::acad_connection )->SetupConnection();
  83.     
  84.     //
  85.     // Initialize excel connection
  86.     //
  87.     excel_server_info = new SS_SERVER_INFO( EXCEL_REG_KEY
  88.                                             , EXCEL_MAX_ROW
  89.                                             , EXCEL_MAX_COL
  90.                                             , 1
  91.                                             , 1
  92.                                             , EXCEL_ROW
  93.                                             , EXCEL_COL
  94.                                             , EXCEL_DELIM
  95.                                             , EXCEL_ROW_SEPERATOR
  96.                                             , EXCEL_COL_SEPERATOR 
  97.                                             , MSEXCEL );
  98.     //
  99.     // Initialize other server connections here
  100.     //
  101. }
  102.  
  103. //-----------------------------------------------------------------------------
  104. DDE_GLOBAL::~DDE_GLOBAL()
  105. {
  106.     delete excel_server_info; excel_server_info = NULL;
  107.     delete acad_connection; acad_connection = NULL;
  108.     delete acad_info; acad_info = NULL;
  109.  
  110.     //
  111.     // Last step: deinitialize the instance ID
  112.     //
  113.     if ( DdeUninitialize( InstId ) == TRUE )
  114.     {
  115.         InstId = 0;
  116.     }
  117.     else
  118.     {
  119.         DWORD err = GetLastError();
  120.         
  121.         ::MessageBox( 0
  122.                     , "UnInitialization failed."
  123.                     , "DDEML client connection"
  124.                     , MB_ICONSTOP|MB_TASKMODAL);
  125.     }
  126. }
  127.  
  128.