lpr.c

Go to the documentation of this file.
00001 /***********************************************************************/
00002 /* Copyright (C) 2005 INRIA Allan CORNET */
00003 /***********************************************************************/
00004 #include <Windows.h>
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 /***********************************************************************/
00008 typedef int (*MYPROC) (HINSTANCE , HWND , char *, char *); 
00009 typedef BOOL (*MYPROC2) (void);
00010 #define MAXSTR 256
00011 /***********************************************************************/
00012 char *GetScilabDirectory(BOOL UnixStyle);
00013 char *GetScilabDllDirectory(BOOL UnixStyle);
00014 void AddToScilabDllPathEnv();
00015 /***********************************************************************/
00016 int main (int argc, char *argv[])
00017 {
00018         HINSTANCE hinstLib; 
00019         
00020     MYPROC gp_printfile; 
00021         MYPROC2 ConfigurePrinterDialogBox; 
00022     BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
00023 
00024         AddToScilabDllPathEnv();
00025         
00026         hinstLib = LoadLibrary(TEXT("LibScilab"));      
00027  
00028     if (hinstLib != NULL) 
00029     { 
00030         gp_printfile = (MYPROC) GetProcAddress(hinstLib, TEXT("gp_printfile")); 
00031                 ConfigurePrinterDialogBox = (MYPROC2) GetProcAddress(hinstLib, TEXT("ConfigurePrinterDialogBox")); 
00032  
00033         if ( (NULL != gp_printfile) && (NULL != ConfigurePrinterDialogBox) )
00034         {
00035                 HWND parent;
00036                 HANDLE x = GetModuleHandleA (0);
00037                                                 
00038                 fRunTimeLinkSuccess = TRUE;
00039                 parent = GetActiveWindow ();
00040                                                 
00041                 ConfigurePrinterDialogBox();
00042                 
00043                 if (argc == 2)
00044                         (gp_printfile) (x, parent, argv[1], (char *) 0);
00045                 else
00046                         (gp_printfile) (x, parent, (char *) 0, (char *) 0);
00047 
00048         }
00049                 else
00050                 {
00051                         MessageBox(NULL,"Lpr : Libscilab.dll Incorret Version !","Warning",MB_ICONERROR); 
00052                 }
00053 
00054         fFreeResult = FreeLibrary(hinstLib); 
00055     } 
00056  
00057     if (! fRunTimeLinkSuccess) MessageBox(NULL,"Lpr : Libscilab.dll not found !","Warning",MB_ICONERROR); 
00058         
00059     return (0);
00060 }
00061 /***********************************************************************/
00062 char *GetScilabDirectory(BOOL UnixStyle)
00063 {
00064         LPSTR ScilabModuleName=NULL;
00065         char drive[_MAX_DRIVE];
00066         char dir[_MAX_DIR];
00067         char fname[_MAX_FNAME];
00068         char ext[_MAX_EXT];
00069 
00070         char *SciPathName=NULL;
00071         char *DirTmp=NULL;
00072 
00073         int index = 0;
00074 
00075         ScilabModuleName = (LPSTR) malloc (MAXSTR + 1);
00076 
00077         if (!GetModuleFileName ((HINSTANCE)GetModuleHandle(NULL), (LPSTR) ScilabModuleName, MAXSTR))
00078         {
00079                 if (ScilabModuleName) {free(ScilabModuleName);ScilabModuleName=NULL;}
00080                 return NULL;
00081         }
00082 
00083         _splitpath(ScilabModuleName,drive,dir,fname,ext);
00084         if (ScilabModuleName) {free(ScilabModuleName);ScilabModuleName=NULL;}
00085         if (dir[strlen(dir)-1] == '\\') dir[strlen(dir)-1] = '\0';
00086 
00087         for (index=0;index<3;index++)
00088         {
00089                 DirTmp=strrchr (dir, '\\');
00090                 if (DirTmp)
00091                 {
00092                         if (strlen(dir)-strlen(DirTmp)>0)
00093                         {
00094                                 dir[strlen(dir)-strlen(DirTmp)] = '\0';
00095                         }
00096                         else return NULL;
00097                 }
00098         }
00099         
00100 
00101 
00102         SciPathName=(char*)malloc((int)(strlen(drive)+strlen(dir)+5)*sizeof(char));
00103 
00104         _makepath(SciPathName,drive,dir,NULL,NULL);
00105 
00106         if ( UnixStyle )
00107         {       
00108                 int i=0;
00109                 for (i=0;i<(int)strlen(SciPathName);i++)
00110                 {
00111                         if (SciPathName[i]=='\\') SciPathName[i]='/';
00112                 }
00113         }
00114         SciPathName[strlen(SciPathName)-1]='\0';
00115         return SciPathName;
00116 }
00117 /***********************************************************************/
00118 char *GetScilabDllDirectory(BOOL UnixStyle)
00119 {
00120         char *LibScilabPath=NULL;
00121         char *PathTmp=NULL;
00122         PathTmp=GetScilabDirectory(UnixStyle);
00123 
00124         LibScilabPath=(char*)malloc(sizeof(char)*(strlen(PathTmp)+strlen("%s\\bin")+1));
00125         wsprintf(LibScilabPath,"%s\\bin",PathTmp);
00126         if (PathTmp) {free(PathTmp);PathTmp=NULL;}
00127         return LibScilabPath;
00128 }
00129 /***********************************************************************/
00130 void AddToScilabDllPathEnv(void)
00131 {
00132         char *LibScilabDirectory=NULL;
00133         char *env=NULL;
00134 
00135         LibScilabDirectory=GetScilabDllDirectory(FALSE);
00136         env=(char*)malloc(sizeof(char)*(strlen(LibScilabDirectory)+strlen("PATH=%s;%PATH%")+1));
00137         sprintf(env,"PATH=%s;%PATH%",LibScilabDirectory);
00138         if (LibScilabDirectory) {free(LibScilabDirectory);LibScilabDirectory=NULL;}
00139         _putenv(env);
00140         if (env) {free(env);env=NULL;}
00141 }
00142 /***********************************************************************/

Generated on Sun Mar 4 15:04:01 2007 for Scilab [trunk] by  doxygen 1.5.1