home *** CD-ROM | disk | FTP | other *** search
- //-----------------------------------------------------------------------------
- // sysvars.CPP
- // Copyright (C) 1998 by Visio Corporation
- //
- // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
- // WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
- // PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
- //
-
- // Description: Displays sysvars in a scrollable listbox as part of
- // a fully MFC/AppWizard/ClassWizard project.
- //
- //
- // Revision History:
- // Original started 3/3/98 Author Mark Barrow
- //-----------------------------------------------------------------------------
- #include "stdafx.h"
- #include <windows.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <io.h>
- #include <sds.h>
- #include "resource.h"
- #include "MfcAppDlg.h"
-
- extern "C" HWND adsw_hwndAcad;
- #define ARRAYELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
-
- // Define the structure of the table: a string giving the IntelliCAD name
- // of the function, and a pointer to a function returning type int.
- struct func_def { char *func_name; int (*func) (struct sds_resbuf *); };
-
- int sysvars(struct sds_resbuf *rb);
-
- // Define the array of function names and handlers.
- // To add more functions to this table, just put them in the list, after
- // declaring the function names.
- static struct func_def func_table[] = {
- {"c:sysvars" , sysvars}
- };
- // Globals
- char adsw_AppName[512];
- char ads_appname[512];
- HWND adsw_hwndAcad;
- HINSTANCE adsw_hInstance;
- HWND adsw_hWnd;
- int adsw_wait;
- sds_matrix ads_identmat;
-
- extern "C" int SDS_GetGlobals(char *appname,HWND *hwnd,HINSTANCE *hInstance);
-
- // Required entry point for SDS programs.
- void __declspec(dllexport) SDS_EntryPoint(HWND hWnd);
-
- void __declspec(dllexport) SDS_EntryPoint(HWND hWnd) {
-
- int i,j;
- char* tmp = NULL;
- // This DLL is dynamically linked against the MFC DLLs.
- // Therefore any functions exported from this DLL which
- // call into MFC must have the AFX_MANAGE_STATE macro
- // added at the very beginning of the function.
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- for(i=0; i<=3; i++) for(j=0; j<=3; j++) ads_identmat[i][j]=0.0;
- for(i=0; i<=3; i++) ads_identmat[i][i]=1.0;
-
- SDS_GetGlobals(adsw_AppName,&adsw_hwndAcad,&adsw_hInstance);
- strncpy(ads_appname,adsw_AppName,sizeof(ads_appname)-1);
- tmp = adsw_AppName;
- SDS_main(1,&tmp);
- return;
- }
-
- // The code from here to the end of invokefun() is UNCHANGED when you add or delete
- // functions.
-
- // Declarations of other local support functions
- int main (int, char **);
- int invokefun (void);
- int funcload (void);
-
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- /* MAIN - the main routine */
-
- int main(int argc, char** argv)
- {
- short scode = RSRSLT; // Normal result code (default)
- int stat;
- char errmsg[80];
-
- sds_init(argc, argv); // Open communication with lisp
-
- for ( ;; ) { // Request/Result loop
- if ((stat = sds_link(scode)) < 0) {
- sprintf(errmsg, "Sysvars: bad status from sds_link() = %d\n", stat);
- sds_printf(errmsg);
- sds_exit(-1);
- }
- scode = RSRSLT; // Reset result code
-
- switch (stat) {
- case RQXLOAD: // Load & define functions
- scode = funcload() == RTNORM ? RSRSLT : RSERR;
- break;
- case SDS_RQXUNLD:
- break;
- case RQSUBR: // Handle external function requests
- scode = invokefun() == RTNORM ? RSRSLT : RSERR;
- break;
- case SDS_RQSAVE:
- break;
- case SDS_RQEND:
- break;
- case SDS_RQQUIT:
- break;
- case SDS_RQCFG:
- break;
- case SDS_RQHUP:
- break;
- case SDS_RQXHELP:
- break;
- default:
- break;
- }
- }
- return(1);
- }
-
- //-----------------------------------------------------------------------------
- // FUNCLOAD -- Define this application's external functions. Return
- // RTERROR on error, else RTNORM.
-
- static int funcload()
- {
- short i;
-
- for (i = 0; i < ARRAYELEMENTS(func_table); i++) {
- if (!sds_defun(func_table[i].func_name, i))
- return RTERROR;
- }
- return RTNORM;
- }
-
- //-----------------------------------------------------------------------------
- // invokefun -- Execute external function (called upon an RQSUBR request).
- // Return value from the function executed, RTNORM or RTERROR.
-
- static int invokefun()
- {
- struct sds_resbuf *rb;
- int val;
-
- // Get the function code and check that it's within range.
- // (It can't fail to be, but paranoia doesn't hurt.)
- if ((val = sds_getfuncode()) < 0 || val >= ARRAYELEMENTS(func_table)) {
- sds_fail("Received nonexistent function code.");
- return RTERROR;
- }
-
- // Fetch the arguments, if any.
- rb = sds_getargs();
-
- // Call the handler and return its success-failure status.
- val = (*func_table[val].func)(rb);
- sds_relrb(rb);
- return val;
-
- }
-
- //-----------------------------------------------------------------------------
- // The code from the beginning of main() to here is UNCHANGED when you add or
- // delete functions.
- //-----------------------------------------------------------------------------
-
- static int sysvars(struct sds_resbuf *rb)
- {
- CMfcAppDlg dlg(CWnd::FromHandle(adsw_hwndAcad));
- dlg.DoModal();
- return RTNORM;
- }
-