home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 November / Dppcpro1198.iso / Nov / Intelcad / Extras / mfcapp / sysvars.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-19  |  5.7 KB  |  184 lines

  1. //-----------------------------------------------------------------------------
  2. //  sysvars.CPP
  3. //  Copyright (C) 1998 by Visio Corporation
  4. //
  5. //  THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
  6. //  WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
  7. //  PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
  8. //
  9.  
  10. //  Description: Displays sysvars in a scrollable listbox as part of
  11. //               a fully MFC/AppWizard/ClassWizard project.
  12. //  
  13. //
  14. //  Revision History:
  15. //  Original started 3/3/98  Author Mark Barrow   
  16. //-----------------------------------------------------------------------------
  17. #include "stdafx.h"
  18. #include <windows.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <errno.h>
  22. #include <io.h>
  23. #include <sds.h>
  24. #include "resource.h"
  25. #include "MfcAppDlg.h"
  26.  
  27. extern "C" HWND adsw_hwndAcad;
  28. #define ARRAYELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
  29.  
  30. // Define the structure of the table: a string giving the IntelliCAD name
  31. // of the function, and a pointer to a function returning type int.
  32. struct func_def { char *func_name; int (*func) (struct sds_resbuf *); };
  33.  
  34. int sysvars(struct sds_resbuf *rb);
  35.  
  36. // Define the array of function names and handlers.
  37. // To add more functions to this table, just put them in the list, after
  38. // declaring the function names.
  39. static struct func_def func_table[] =        {
  40.     {"c:sysvars"    , sysvars}
  41.                                              };
  42. // Globals 
  43. char      adsw_AppName[512];
  44. char      ads_appname[512];
  45. HWND      adsw_hwndAcad;
  46. HINSTANCE adsw_hInstance;
  47. HWND      adsw_hWnd;
  48. int       adsw_wait;
  49. sds_matrix ads_identmat;
  50.  
  51. extern "C" int SDS_GetGlobals(char *appname,HWND *hwnd,HINSTANCE *hInstance);
  52.  
  53. // Required entry point for SDS programs.
  54. void __declspec(dllexport) SDS_EntryPoint(HWND hWnd);
  55.  
  56. void __declspec(dllexport) SDS_EntryPoint(HWND hWnd) {
  57.     
  58.     int i,j;
  59.     char* tmp = NULL;
  60.     // This DLL is dynamically linked against the MFC DLLs. 
  61.     // Therefore any functions exported from this DLL which
  62.     // call into MFC must have the AFX_MANAGE_STATE macro
  63.     // added at the very beginning of the function.
  64.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  65.  
  66.     for(i=0; i<=3; i++) for(j=0; j<=3; j++)    ads_identmat[i][j]=0.0;
  67.     for(i=0; i<=3; i++) ads_identmat[i][i]=1.0;
  68.  
  69.     SDS_GetGlobals(adsw_AppName,&adsw_hwndAcad,&adsw_hInstance);
  70.     strncpy(ads_appname,adsw_AppName,sizeof(ads_appname)-1);
  71.     tmp = adsw_AppName;
  72.     SDS_main(1,&tmp);
  73.     return;
  74. }
  75.  
  76. // The code from here to the end of invokefun() is UNCHANGED when you add or delete
  77. // functions.
  78.  
  79. //  Declarations of other local support functions
  80. int    main       (int, char **);
  81. int    invokefun  (void);
  82. int    funcload   (void);
  83.  
  84. //-----------------------------------------------------------------------------
  85. //-----------------------------------------------------------------------------
  86. /* MAIN - the main routine */
  87.  
  88. int main(int argc, char** argv)
  89. {
  90.    short scode = RSRSLT;             // Normal result code (default)
  91.    int stat;
  92.    char errmsg[80];
  93.  
  94.    sds_init(argc, argv);             // Open communication with lisp
  95.  
  96.    for ( ;; ) {                      // Request/Result loop
  97.        if ((stat = sds_link(scode)) < 0) {
  98.            sprintf(errmsg, "Sysvars: bad status from sds_link() = %d\n", stat);
  99.            sds_printf(errmsg);
  100.            sds_exit(-1);
  101.        }
  102.        scode = RSRSLT;               // Reset result code
  103.  
  104.        switch (stat) {
  105.        case RQXLOAD:                 // Load & define functions
  106.            scode = funcload() == RTNORM ? RSRSLT : RSERR;
  107.            break;
  108.        case SDS_RQXUNLD:
  109.            break;
  110.        case RQSUBR:                  // Handle external function requests
  111.            scode = invokefun() == RTNORM ? RSRSLT : RSERR;
  112.            break;
  113.        case SDS_RQSAVE:
  114.            break;
  115.        case SDS_RQEND:
  116.            break;
  117.        case SDS_RQQUIT:
  118.            break;
  119.        case SDS_RQCFG:
  120.            break;
  121.        case SDS_RQHUP:
  122.            break;
  123.        case SDS_RQXHELP:
  124.            break;
  125.        default:
  126.            break;
  127.        }
  128.    }
  129.    return(1);
  130. }
  131.  
  132. //-----------------------------------------------------------------------------
  133. // FUNCLOAD  --  Define this application's external functions.  Return
  134. //               RTERROR on error, else RTNORM.
  135.  
  136. static int funcload()
  137. {
  138.     short i;
  139.  
  140.     for (i = 0; i < ARRAYELEMENTS(func_table); i++) {
  141.         if (!sds_defun(func_table[i].func_name, i))
  142.             return RTERROR;
  143.     }
  144.     return RTNORM;
  145. }
  146.  
  147. //-----------------------------------------------------------------------------
  148. // invokefun -- Execute external function (called upon an RQSUBR request).
  149. //              Return value from the function executed, RTNORM or RTERROR.
  150.  
  151. static int invokefun()
  152. {
  153.     struct sds_resbuf *rb;
  154.     int val;
  155.  
  156.     // Get the function code and check that it's within range.
  157.     // (It can't fail to be, but paranoia doesn't hurt.)
  158.     if ((val = sds_getfuncode()) < 0 || val >= ARRAYELEMENTS(func_table)) {
  159.         sds_fail("Received nonexistent function code.");
  160.         return RTERROR;
  161.     }
  162.  
  163.     // Fetch the arguments, if any.
  164.     rb = sds_getargs();
  165.  
  166.     // Call the handler and return its success-failure status.
  167.     val = (*func_table[val].func)(rb);
  168.     sds_relrb(rb);
  169.     return val;
  170.  
  171. }
  172.  
  173. //-----------------------------------------------------------------------------
  174. // The code from the beginning of main() to here is UNCHANGED when you add or
  175. // delete functions.
  176. //-----------------------------------------------------------------------------
  177.  
  178. static int sysvars(struct sds_resbuf *rb)
  179. {
  180.     CMfcAppDlg dlg(CWnd::FromHandle(adsw_hwndAcad));
  181.     dlg.DoModal();
  182.     return RTNORM;
  183. }
  184.