Example #1
0
ResourceString::ResourceString ( HMODULE Module, ULONG Id )
{
  SavedModule = Module ;
  SavedId = Id ;

  APIRET Status = DosGetResource ( Module, RT_STRING, Id/16+1, &BlockPointer ) ;
  if ( Status )
  {
    #ifdef DEBUG
    Log (
      "ERROR: Unable to get string resource."
      "  Module %lu, id %lu, code %08lX.\r\n", SavedModule, SavedId, Status ) ;
    #endif
    return ;
  }

  StringPointer = PBYTE(BlockPointer) + sizeof(USHORT) ;

  USHORT Index = (USHORT) ( Id % 16 ) ;
  while ( Index-- )
  {
    StringPointer += *StringPointer ;
    StringPointer ++ ;
  }

  StringPointer ++ ;
}
Example #2
0
ULONG APIENTRY GetNLSData(PULONG pulCodePage, PULONG pulLanguage)
{
   PVOID   pResourceData;
   CHAR    *pTemp;

   if (DosGetResource(moduleHandle, RT_RCDATA, NLS_CHARSET_INFO, &pResourceData ))
     return (MMIO_ERROR);

   /*
    * The resource table is of the form :
    *   usCodePage     Low
    *   usCountryCode  High
    *   usLanguage     Low
    *   usDialect      High
    */

   pTemp = (CHAR *)pResourceData;

   while (pTemp)
      {
      memmove(pulCodePage, pTemp, sizeof(ULONG));
      pTemp += sizeof(ULONG);

      if (pTemp == NULL)
        break;

      memmove(pulLanguage, pTemp, sizeof(ULONG));

      break;
      }

   DosFreeResource(pResourceData);

   return (MMIO_SUCCESS);
}
Example #3
0
//  RETURN THE WIDTH AND HEIGHT OF A DIALOG BOX.
BOOL GetDialogDimensions(ULONG idDlg, PLONG plCx, PLONG plCy, PULONG pidFocus)
{
	APIRET rc;
	PDLGTEMPLATE pDlgTemplate = NULL;

	rc = DosGetResource(0, RT_DIALOG, idDlg, (PPVOID) &pDlgTemplate);

	if (!rc) {
		PDLGTITEM pDlgItem;

		// Get offset to the item table
		pDlgItem = (PDLGTITEM)((PBYTE) pDlgTemplate + pDlgTemplate->offadlgti);

		*plCx = (LONG)pDlgItem->cx;
		*plCy = (LONG)pDlgItem->cy;

		// Currently the focus item doesn't seem to be set properly so it will
		// be hard-coded in the constant array.
		//*pidFocus = (ULONG) (pDlgItem + pDlgTemplate->iItemFocus)->id;
		*pidFocus = *pidFocus;
		return TRUE;
	}

	return FALSE;
}
Example #4
0
BOOL DLL_GetDataResource (HMODULE DLLHandle, ULONG ResourceID, PPVOID ResourcePtrPtr, PULONG ResourceSizePtr) {
   if (DosGetResource(DLLHandle, RT_RCDATA, ResourceID, ResourcePtrPtr))
      return FALSE;
   if (DosQueryResourceSize(DLLHandle, RT_RCDATA, ResourceID, ResourceSizePtr))
      return FALSE;
   return TRUE;
 }
Example #5
0
/* Returned string needs to be PR_Free'd by caller */
static char *LoadRCDATAVersion(HMODULE hMod, ULONG resid)
{
   APIRET rc;
   ULONG  ulSize = 0;
   char  *string = 0;

   rc = DosQueryResourceSize(hMod, RT_RCDATA, resid, &ulSize);

   // version info is should be 8 chars
   if (rc == NO_ERROR && ulSize == 8)
   {
      char *version = NULL;
      rc = DosGetResource(hMod, RT_RCDATA, resid, (void**) &version);

      if (rc == NO_ERROR)
      {
         string = PR_smprintf("%d.%d.%d.%d\n",
                              version[0], version[2], version[4], version[6]);

         DosFreeResource(version);
      }
   }

   return string;
}
Example #6
0
/* Returned string needs to be PR_Free'd by caller */
static char *LoadRCDATAString( HMODULE hMod, ULONG resid)
{
   APIRET rc;
   ULONG  ulSize = 0;
   char  *string = 0;

   rc = DosQueryResourceSize( hMod, RT_RCDATA, resid, &ulSize);

   if( rc == NO_ERROR)
   {
      char *readOnlyString = 0;
      rc = DosGetResource( hMod, RT_RCDATA, resid, (void**) &readOnlyString);

      /* allow for 0-termination if user hasn't got it right */
      if( readOnlyString[ ulSize - 1] != '\0')
         ulSize++;

      if( rc == NO_ERROR)
      {
         /* copy string & zero-terminate */
         string = (char*) PR_Malloc( ulSize);
         memcpy( string, readOnlyString, ulSize - 1);
         string[ ulSize - 1] = '\0';

         DosFreeResource( readOnlyString);
      }
   }

   return string;
}
BOOL GetDialogDimensions( ULONG idDlg, PLONG pCx, PLONG pCy )
{
    BOOL         fSuccess = TRUE;
    APIRET       rc;
    PDLGTEMPLATE pDlgTemplate = NULL;

    rc = DosGetResource( 0, RT_DIALOG, idDlg, (PPVOID) &pDlgTemplate );

    if( !rc )
    {
        PDLGTITEM pDlgItem;

        // Get offset to the item table

        pDlgItem = (PDLGTITEM) ((PBYTE) pDlgTemplate + pDlgTemplate->offadlgti);

        *pCx = (LONG) pDlgItem->cx;
        *pCy = (LONG) pDlgItem->cy;
    }
    else
    {
        fSuccess = FALSE;
        Msg( "DosGetResource for id %u RC(%X)", idDlg, HWNDERR( hwndBook ) );
    }

    return fSuccess;
}
Example #8
0
File: gvpmisc.c Project: 131/gsview
void
profile_create_section(PROFILE *prf, const char *section, int id)
{
char *rcdata, *entry, *value;
char name[MAXSTR];
    if (!DosGetResource(0, RT_RCDATA, id, (PPVOID)&rcdata)) {
	if (rcdata == (char *)NULL) {
	    profile_close(prf);
	    return;
	}
	entry = rcdata;
	while (strlen(entry)!=0) {
	    for ( value = entry; 
		  (*value!='\0') && (*value!=',') && (*value!='='); 
		  value++)
		/* nothing */;
	    strncpy(name, entry, value-entry);
	    name[value-entry] = '\0';
	    value++;
	    profile_write_string(prf, section, name, value);
	    entry = value + strlen(value) + 1;
	}
   }
   DosFreeResource(rcdata);
}
Example #9
0
ResourceString :: ResourceString (ULONG Id) : psz ("(string load error)")
{
    SavedId = Id;

    if (DosGetResource (Module(), RT_STRING, Id/16+1, &BlockPointer))
        return;

    psz = PSZ (BlockPointer) + sizeof(USHORT);

    USHORT Index = USHORT (Id % 16);
    while (Index--)
    {
        psz += * PUCHAR (psz);
        psz ++;
    }

    psz ++;
}
OString::OString(ULONG res, HMODULE mod)
{
 PVOID  resPtr  = NULL;
 STRRES *str    = NULL;

 if (DosGetResource(mod, RT_STRING, res / 16 + 1, &resPtr))
   *this << "ERROR";
 else
   {
    str = (STRRES*) resPtr + sizeof(USHORT);

    for(ULONG i = 0; i < 15; i++)
      {
       str +=  atoi((PCSZ)&str->len);
      }

    DosFreeResource(resPtr);
   }    
}
Example #11
0
USHORT Settings :: GetLanguages (HWND hwnd)
{
    // find all dlls and add the names to the language list
    HDIR          hdir;
    ULONG         c, fl, ul;
    FILEFINDBUF3  findbuf;
    APIRET        rc;
    PSZ           psz;
    HMODULE       hmod;

    fl   = FILE_NORMAL;
    hdir = HDIR_CREATE;
    c    = 1;
    rc   = DosFindFirst ("*.dll", &hdir, fl, &findbuf,
                         sizeof (findbuf), &c, FIL_STANDARD);
    while (!rc)
    {
        // we don't want the extension
        if ((psz = _getext (findbuf.achName)))
            *psz = '\0';
        // try opening the dll and read the version etc. data
        if ((rc = DosLoadModule(PSZ(NULL), 0, findbuf.achName, &hmod)) == NO_ERROR) {
            PVOID pv;
            if (DosGetResource(hmod, RT_RCDATA, DLL_ID, &pv) == NO_ERROR) {
                if (strcmp(PSZ(pv), "Gotcha!") == 0) {
                    psz = PSZ(pv)+strlen(PSZ(pv))+3;
                    ul = WinInsertLboxItem (hwnd, LIT_END, psz);
                    WinSendMsg(hwnd, LM_SETITEMHANDLE, MPFROMLONG(ul),
                               MPFROMP (strdup(findbuf.achName)));
                }
                DosFreeResource(pv);
            }
            DosFreeModule(hmod);
        }
        c = 1;
        rc = DosFindNext (hdir, &findbuf, sizeof (findbuf), &c);
    }
    DosFindClose (hdir);

    return 1;
}
Example #12
0
File: gvpmisc.c Project: 131/gsview
int
send_prolog(int resource)
{  
char *prolog, *p;
APIRET rc;
int code = -1;
	rc = DosGetResource(0, RT_RCDATA, resource, (PPVOID)&prolog);
	if (!rc && (prolog != (char *)NULL) ) {
	    code = 0;
	    p = prolog;
	    while (*p) {
		if (debug & DEBUG_GENERAL)
		    gs_addmess(p);
		if (!code)
	            code = gs_execute(p, strlen(p));
		p += strlen(p)+1;
	    }
	    DosFreeResource(prolog);
	}
	return code;
}
Example #13
0
File: gvpmisc.c Project: 131/gsview
int
load_resource(int resource, char *str, int len)
{  
char *prolog, *p;
int plen;
APIRET rc;
	rc = DosGetResource(hlanguage, RT_RCDATA, resource, (PPVOID)&prolog);
	if (!rc && (prolog != (char *)NULL) ) {
	    p = prolog;
	    while (*p) {
		plen = strlen(p);
		if (plen + 1 < len) {
		    strncpy(str, p, len);
		    str+=plen;
		    len-=plen;
		}
		p += plen + 1;
	    }
	    DosFreeResource(prolog);
	}
	return rc;
}
Example #14
0
int
send_prolog(FILE *f, int resource)
{  
char *prolog, *p;
APIRET rc;
int code = -1;
	rc = DosGetResource(pstotextModule, RT_RCDATA, resource, (PPVOID)&prolog);
	if (!rc && (prolog != (char *)NULL) ) {
	    code = 0;
	    p = prolog;
	    while (*p) {
		if (!code)
		    fputs(p, f);
		p += strlen(p)+1;
	    }
	    DosFreeResource(prolog);
	}
	else {
	    fprintf(stderr, "Failed to load pstotext resource %d\n", resource);
	}
	return code;
}
Example #15
0
VOID PDSGetTemplate(HWND hWnd, ULONG idDlg)

{
PDLGTEMPLATE pdlgt;		   /* Dialog Template Pointer		*/
POINTL	     aptl[2];		   /* Dialog Points Array		*/
PVOID	     pvClassName;	   /* Control Data Pointer		*/
PVOID	     pvCtlData;		   /* Control Data Pointer		*/
PVOID	     pvPresParams;	   /* Presentation Parameters Pointer	*/
PVOID	     pvStart;		   /* Dialog Template Item Pointer	*/
PVOID	     pvText;		   /* Control Data Pointer		*/
INT	     cbparam;		   /* Presentation Parameter Size	*/
PPARAM	     pparam;		   /* Presentation Parameters Pointer	*/
PPRESPARAMS  ppres;		   /* Presentation Parameters Pointer	*/
register INT cItems;		   /* Dialog Items Counter		*/
register INT i;			   /* Loop Counter			*/

		       /* Try reading in the dialog template for the	*/
		       /* dialog ID given				*/

if ( DosGetResource((HMODULE)NULL, RT_DIALOG, idDlg, (PPVOID)(PVOID)&pdlgt) )

		       /* Dialog template not found, exit without	*/
		       /* creating any controls				*/
   return;
		       /* Convert the memory selector returned into an	*/
		       /* addressable pointer to allow the controls to	*/
		       /* be decoded					*/

pvStart	= (PVOID)pdlgt;
		       /* Check	to see if any presentation parameters	*/
		       /* associated with the control.	A -1 indicates	*/
		       /* that no presentation parameters are		*/
		       /* associated.					*/

if ( pdlgt->adlgti[0].offPresParams != 0xffff )
   {
   ppres = (PPRESPARAMS)((PBYTE)pvStart	+ pdlgt->adlgti[0].offPresParams);
   cbparam = (INT)ppres->cb;

   i = 0;
   pparam = ppres->aparam;
   while ( cbparam )
       {
       pparam =	(PPARAM)((BYTE *)pparam	+ i);
       WinSetPresParam(hWnd, pparam->id, pparam->cb, pparam->ab);
       cbparam -= (i = (INT)pparam->cb + (INT)sizeof(ULONG) * 2);
       }
   }
		       /* Save the number of controls found within the	*/
		       /* dialog template				*/

cItems = pdlgt->adlgti[0].cChildren + 1;

		       /* Read in and translate	each of	the controls	*/

for ( i	= 1; i < cItems; i++ )
   {
		       /* Get the position and size of the control and	*/
		       /* convert from dialog units to actual window	*/
		       /* co-ordinates					*/

   aptl[0].x = (LONG)pdlgt->adlgti[i].x;
   aptl[0].y = (LONG)pdlgt->adlgti[i].y;
   aptl[1].x = (LONG)pdlgt->adlgti[i].cx;
   aptl[1].y = (LONG)pdlgt->adlgti[i].cy;

   WinMapDlgPoints(hWnd, aptl, 2UL, TRUE);

		       /* Check	to see if a custom class is specified	*/
		       /* or if	a standard PM control class is being	*/
		       /* used						*/

   if (	pdlgt->adlgti[i].cchClassName )

		       /* Since	a length for the class name present,	*/
		       /* a custom class name is being used for	the	*/
		       /* control.  Point to the memory	location where	*/
		       /* the class name is found within the dialog	*/
		       /* template information.				*/

       pvClassName = (PVOID)((PBYTE)pvStart + pdlgt->adlgti[i].offClassName);
   else
		       /* No class name	length given indicating	that a	*/
		       /* standard PM class is being used.  The	class	*/
		       /* name is stored as an index value.  For	*/
		       /* example, the class for static's is defined as */
		       /*						*/
		       /* #define WC_STATIC ((PSZ)0xffff0005L)		*/
		       /*						*/
		       /* The values within the	dialog template	for	*/
		       /* the static class would be			*/
		       /*						*/
		       /* adlgti[i].cchClassName = 0			*/
		       /* adlgti[i].offClassName = 5			*/
		       /*						*/
		       /* Therefore, the value of offClassName field	*/
		       /* must be used as an index that	is used	to	*/
		       /* actually select the class name.		*/

       switch (	pdlgt->adlgti[i].offClassName )
	   {
		       /* Control Type:	 Button				*/

	   case	WINCLASS_BUTTON	:
	       pvClassName = WC_BUTTON;	
	       break;
		       /* Control Type:	 Frame				*/

	   case	WINCLASS_FRAME :
	       pvClassName = WC_FRAME;
	       break;
		       /* Control Type:	 Scroll	Bar			*/

	   case	WINCLASS_SCROLLBAR :
	       pvClassName = WC_SCROLLBAR;
	       break;
		       /* Control Type:	 List Box			*/

	   case	WINCLASS_LISTBOX :
	       pvClassName = WC_LISTBOX;
	       break;
		       /* Control Type:	 Edit				*/

	   case	WINCLASS_ENTRYFIELD :
	       pvClassName = WC_ENTRYFIELD;
	       break;
		       /* Control Type:	 Static				*/

	   case	WINCLASS_STATIC	:
	       pvClassName = WC_STATIC;	
	       break;
		       /* Control Type:	 Combo Box			*/

	   case	WINCLASS_COMBOBOX :
	       pvClassName = WC_COMBOBOX;
	       break;
		       /* Control Type:	 Multi-Line Edit		*/

	   case	WINCLASS_MLE :
	       pvClassName = WC_MLE;
	       break;
		       /* Control Type:	 Spin Button		  [1.3]	*/

	   case	WINCLASS_SPINBUTTON :
	       pvClassName = WC_SPINBUTTON;
	       break;
		       /* Control Type:	 Container		  [2.0]	*/

	   case	WINCLASS_CONTAINER :
	       pvClassName = WC_CONTAINER;
	       break;
		       /* Control Type:	 Slider			  [2.0]	*/

	   case	WINCLASS_SLIDER	:
	       pvClassName = WC_SLIDER;
	       break;
		       /* Control Type:	 Value Set		  [2.0]	*/

	   case	WINCLASS_VALUESET :
	       pvClassName = WC_VALUESET;
	       break;
		       /* Control Type:	 Notebook		  [2.0]	*/

	   case	WINCLASS_NOTEBOOK :
	       pvClassName = WC_NOTEBOOK;
	       break;
		       /* Control Type:	 Handwriting	 [Pen for OS/2]	*/

	   case	WINCLASS_HWXENTRY :
	       pvClassName = WC_HWXENTRY;
	       break;
		       /* Control Type:	 Sketch		 [Pen for OS/2]	*/

	   case	WINCLASS_SKETCH	:
	       pvClassName = WC_SKETCH;
	       break;
		       /* Control Type:	 Graphic Button	       [MMPM/2]	*/

	   case	WINCLASS_GRAPHICBUTTON :
	       pvClassName = WC_GRAPHICBUTTON;
	       break;
		       /* Control Type:	 Circular Slider       [MMPM/2]	*/

	   case	WINCLASS_CIRCULARSLIDER	:
	       pvClassName = WC_CIRCULARSLIDER;
	       break;
	   }
		       /* Check	to see if any control data associated	*/
		       /* with the control.  A -1 indicates that no	*/
		       /* control data is associated.			*/

   if (	pdlgt->adlgti[i].offCtlData != 0xffff )
       pvCtlData = (PVOID)((PBYTE)pvStart + pdlgt->adlgti[i].offCtlData);
   else
       pvCtlData = NULL;
		       /* Check	to see if any presentation parameters	*/
		       /* associated with the control.	A -1 indicates	*/
		       /* that no presentation parameters are		*/
		       /* associated.					*/

   if (	pdlgt->adlgti[i].offPresParams != 0xffff )
       pvPresParams = (PVOID)((PBYTE)pvStart + pdlgt->adlgti[i].offPresParams);
   else
       pvPresParams = NULL;

		       /* Check	to see if any text specified for the	*/
		       /* control					*/

   if (	pdlgt->adlgti[i].cchText )
       pvText =	(PVOID)((PBYTE)pvStart + pdlgt->adlgti[i].offText);
   else
       pvText =	NULL;
		       /* Create the control				*/

   WinCreateWindow(hWnd, pvClassName, pvText,
		   pdlgt->adlgti[i].flStyle,
		   aptl[0].x, aptl[0].y,
		   aptl[1].x, aptl[1].y,
		   hWnd, HWND_BOTTOM, (ULONG)(pdlgt->adlgti[i].id & 0xffff),
		   pvCtlData, pvPresParams);
   }
		       /* Release the memory allocated for the dialog	*/
		       /* template before returning			*/
DosFreeResource(pvStart);
}
Example #16
0
/**********************************************************************
 * Function: LoadNoteBookPages
 * Info    : Load notebook pages
 * Result  :
 **********************************************************************/
static BOOL LoadNoteBookPages(HWND hwndNoteBook)
{

  /* Insert "General" page */
  if (NO_ERROR != DosGetResource(hRessourceModule,
                                 RT_DIALOG,
                                 DID_GENERAL_DLG,
                                 &pPointerDialog1))
  {
   pPointerDialog1 = NULL;
   return FALSE;
  }

  ulGeneralPageId = (LONG)WinSendDlgItemMsg(hwndNoteBook, DID_PREF_NOTEBOOK,
       BKM_INSERTPAGE, NULL,
       MPFROM2SHORT((BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | BKA_MAJOR),
       BKA_LAST));

  if ( !ulGeneralPageId)
  {
    DosFreeResource(&pPointerDialog1);
    pPointerDialog1 = NULL;
    return FALSE;
  }

#if 0
  if ( !WinSendDlgItemMsg(hwndNoteBook, DID_PREF_NOTEBOOK,
       BKM_SETSTATUSLINETEXT, MPFROMLONG(ulGeneralPageId),
       MPFROMP("Page 1 of 2")))
    return FALSE;
#endif

  Len = WinLoadString(Hab, hRessourceModule, IDS_GENERAL_TAB,
                      TITLESTRN_MAXLEN, Title);

  if (!WinSendDlgItemMsg(hwndNoteBook, DID_PREF_NOTEBOOK,
      BKM_SETTABTEXT, MPFROMLONG(ulGeneralPageId), Title))
  {
    DosFreeResource(&pPointerDialog1);
    pPointerDialog1 = NULL;
    return FALSE;
  }

  hwndGeneralWindow = WinCreateDlg(hwndNoteBook,
                                   hwndNoteBook,
                                   PrefGeneralDlgProc,
                                   pPointerDialog1,
                                   NULL);
 if (NULLHANDLE != hwndGeneralWindow)
  WinSendDlgItemMsg(hwndNoteBook, DID_PREF_NOTEBOOK,
                    BKM_SETPAGEWINDOWHWND,
                    MPFROMLONG(ulGeneralPageId),
                    MPFROMHWND(hwndGeneralWindow));
 else
 {
    DosFreeResource(&pPointerDialog1);
    pPointerDialog1 = NULL;
    return FALSE;
 }

  /* Insert "Files" page */
 if (NO_ERROR != DosGetResource(hRessourceModule,
                                RT_DIALOG,
                                DID_FILES_DLG,
                                &pPointerDialog2))
 {
    DosFreeResource(&pPointerDialog1);
    pPointerDialog1 = NULL;
    pPointerDialog2 = NULL;
    return FALSE;
 }

  ulFilesPageId = (LONG)WinSendDlgItemMsg(hwndNoteBook, DID_PREF_NOTEBOOK,
       BKM_INSERTPAGE, NULL,
       MPFROM2SHORT((BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | BKA_MAJOR),
       BKA_LAST));

  if (!ulFilesPageId)
  {
    DosFreeResource(&pPointerDialog1);
    DosFreeResource(&pPointerDialog2);
    pPointerDialog1 = NULL;
    pPointerDialog2 = NULL;
    return FALSE;
  }

  Len = WinLoadString(Hab, hRessourceModule, IDS_FILES_TAB,
                      TITLESTRN_MAXLEN, Title);

  if (!WinSendDlgItemMsg(hwndNoteBook, DID_PREF_NOTEBOOK,
      BKM_SETTABTEXT, MPFROMLONG(ulFilesPageId), Title))
  {
    DosFreeResource(&pPointerDialog1);
    DosFreeResource(&pPointerDialog2);
    pPointerDialog1 = NULL;
    pPointerDialog2 = NULL;
    return FALSE;
  }

  hwndFilesWindow = WinCreateDlg(hwndNoteBook,
                                 hwndNoteBook,
                                 PrefFilesDlgProc,
                                 pPointerDialog2,
                                 NULL);
 if (NULLHANDLE != hwndFilesWindow)
  WinSendDlgItemMsg(hwndNoteBook, DID_PREF_NOTEBOOK,
                    BKM_SETPAGEWINDOWHWND,
                    MPFROMLONG(ulFilesPageId),
                    MPFROMHWND(hwndFilesWindow));
 else
 {
   DosFreeResource(&pPointerDialog1);
   DosFreeResource(&pPointerDialog2);
   pPointerDialog1 = NULL;
   pPointerDialog2 = NULL;
   return FALSE;
 }

 return TRUE;
}
BOOL LoadStringTable(HMODULE hmodRes,
                     ULONG   ulTableItems,
                     PSZ     pszTable[] )

{
  /*������������������������������������������������������������������������Ŀ*/
  /*� Local structure definitions                                            �*/
  /*�                                                                        �*/
  /*� - these items define templates for overlaying the RESOURCE segment     �*/
  /*�   read by DosGetResource/DosGetResource2                               �*/
  /*��������������������������������������������������������������������������*/
  typedef struct                           /* single string in RESOURCE       */
  {
     UCHAR  ucLength;
     CHAR   cString[1];

  }    PMST_STRING,
    * PPMST_STRING;

  typedef struct                           /* first part of RESOURCE SEGMENT  */
  {
     USHORT       usCodePage;
     PMST_STRING  pmstString;

  }    PMST_RES,
    * PPMST_RES;

  typedef union                            /* easy pointer movement           */
  {
     PPMST_RES    pR;
     PPMST_STRING pS;
     PCHAR        pC;
     PVOID        pV;

  }  PMST_UPTR;

  /*������������������������������������������������������������������������Ŀ*/
  /*� Local variables                                                        �*/
  /*��������������������������������������������������������������������������*/
  BOOL   bOK = BOOL_TRUE;               /* well, start as an OPTIMIST... */

  ULONG  ulI;                           /* current string table value */

  PMST_UPTR   P;                        /* multi-function POINTER */

  /*������������������������������������������������������������������������Ŀ*/
  /*� Set all STRING table pointers to NULL before starting...               �*/
  /*� (since we can't make any assumptions about state of passed table!)     �*/
  /*��������������������������������������������������������������������������*/
  memset(pszTable, 0, ulTableItems * sizeof(pszTable[0]) );

  /*������������������������������������������������������������������������Ŀ*/
  /*� Process all of the string items (as defined by caller)                 �*/
  /*��������������������������������������������������������������������������*/
  for( ulI = 0;                      /* Initialize: start at first string   */
       ulI < ulTableItems;           /* While:      more strings to process */
       ulI++)                        /* Iterate:    to the next string      */
  {
    /*����������������������������������������������������������������������Ŀ*/
    /*� Need to load a new RESOURCE segment?                                 �*/
    /*�                                                                      �*/
    /*� this happens if: (1) this is the first STRING being processed        �*/
    /*�                  (2) all STRINGs from this SEGMENT have been         �*/
    /*�                                                            processed �*/
    /*������������������������������������������������������������������������*/
    if ( (ulI % ulStringsPerRes) == 0)         /* all last segment processed? */
    {
      if (DosGetResource (hmodRes,                    /* from where */
                          RT_STRING,                  /* Res Type = STRINGTABLE */
                          (ulI / ulStringsPerRes) + 1, /* Res ID */
                          &P.pV) )                    /* put PTR here */
      {
        bOK = BOOL_FALSE;                             /* error detected... */
        break;
      }

      /*��������������������������������������������������������������������Ŀ*/
      /*� Locate first string in this new RESOURCE segment                   �*/
      /*����������������������������������������������������������������������*/
      P.pS = &P.pR->pmstString;
    }

    /*����������������������������������������������������������������������Ŀ*/
    /*� Set address of this STRING in caller's table                         �*/
    /*������������������������������������������������������������������������*/
    pszTable[ulI] = &P.pS->cString[0];

    /*����������������������������������������������������������������������Ŀ*/
    /*� Move to the next STRING in this segment                              �*/
    /*������������������������������������������������������������������������*/
    P.pC += P.pS->ucLength + 1;
  }

  return( bOK );
}
Example #18
0
/**
 * Bind a bind packet found in a resource item.
 * No bind options is specified. Hence packet and DB defaults are used.
 * @returns NO_ERROR (0) on success.
 *          Appropirate error code on error.
 * @param   hmod    Handle of the resource module. Use NULLHANDLE
 *                  for the executable of the process.
 * @param   idType  Resource type identifier. Usually 805.
 * @param   idName  Name identifier of the resource.
 * @status  Completely implemented.
 * @author  knut st. osmundsen ([email protected])
 */
int     BindResource(unsigned long hmod, unsigned long idType, unsigned long idName)
{
    struct sqlca    sqlca = {0};
    BOOL            fRc;
    APIRET          rc;
    ULONG           cbBnd;
    PVOID           pvBnd;
    FILE *          phBnd;
    char            szBindFile[CCHMAXPATH];
    CHAR            achsqlopt[sizeof(struct sqlopt) + sizeof(struct sqloptions) * 3] = {0};
    struct sqlopt * psqlopt = (struct sqlopt *)&achsqlopt[0];

    /*
     * Load resource and get its size.
     */
    rc = DosQueryResourceSize((HMODULE)hmod, idType, idName, &cbBnd);
    if (rc != NO_ERROR)
        return rc;
    rc = DosGetResource((HMODULE)hmod, idType, idName, &pvBnd);
    if (rc != NO_ERROR)
        return rc;

    /*
     * Open temporary file.
     */
    phBnd = fopen(BindTmpFile(szBindFile, "bnd"), "wb");
    if (!phBnd)
    {
        DosFreeResource(pvBnd);
        return ERROR_OPEN_FAILED;
    }

    /*
     * Write the bind file data to the temporary file and close it.
     */
    if (fwrite(pvBnd, 1, cbBnd, phBnd) != cbBnd)
    {
        DosFreeResource(pvBnd);
        fclose(phBnd);
        return ERROR_WRITE_FAULT;
    }
    DosFreeResource(pvBnd);
    fclose(phBnd);

    /*
     * Execute bind, delete tempfile and return.
     */
    psqlopt->option[0].type   = SQL_BLOCK_OPT;
    psqlopt->option[0].val    = SQL_BL_ALL;
    psqlopt->option[1].type   = SQL_ISO_OPT;
    psqlopt->option[1].val    = SQL_UNCOM_READ;
    psqlopt->header.allocated = 0;
    psqlopt->header.used      = 0;
    rc = sqlabndx((_SQLOLDCHAR *)szBindFile,
                  "\\dev\\nul",
                  psqlopt,
                  &sqlca);
    if (rc == NO_ERROR && sqlca.sqlcode != SQL_RC_OK)
        rc = sqlca.sqlcode;
    if (rc)
    {
        /*
         * Error occured. Rerun the bind and collect bind messages.
         */
        char            szBuffer[256];
        FILE *          phTmpFile;
        CHAR            szTmpFile[CCHMAXPATH];

        sqlabndx((_SQLOLDCHAR *)szBindFile,
                 BindTmpFile(szTmpFile, NULL),
                 psqlopt,
                 &sqlca);
        phTmpFile = fopen(szTmpFile, "r");
        if (phTmpFile)
        {
            while (fgets(szBuffer, sizeof(szBuffer), phTmpFile))
                BindError("%s", szBuffer);
            fclose(phTmpFile);
        }
        DosDelete(szTmpFile);
        BindError("package=%s sqlcode=%ld sqlstate=%.5s\n",
                  szBindFile, sqlca.sqlcode, sqlca.sqlstate);
        return rc;
    }

    DosDelete(szBindFile);
    return NO_ERROR;
}
void vncHTTPConnectThread::DoHTTP(VSocket *socket)
{
    char filename[1024];
    char *line;

    // Read in the HTTP header
    if ((line = ReadLine(socket, '\n', 1024)) == NULL)
        return;

    // Scan the header for the filename and free the storage
    int result = sscanf(line, "GET %s ", (char*)&filename);
    delete [] line;
    if ((result == 0) || (result == EOF))
        return;

    vnclog.Print(LL_CLIENTS, VNCLOG("file %s requested\n"), filename);

    // Read in the rest of the browser's request data and discard...
    BOOL emptyline=TRUE;

    for (;;)
    {
        char c;

        if (!socket->ReadExact(&c, 1))
            return;
        if (c=='\n')
        {
            if (emptyline)
                break;
            emptyline = TRUE;
        }
        else
            if (c >= ' ')
            {
                emptyline = FALSE;
            }
    }

    vnclog.Print(LL_INTINFO, VNCLOG("parameters read\n"));

    if (filename[0] != '/')
    {
        vnclog.Print(LL_CONNERR, VNCLOG("filename didn't begin with '/'\n"));
        socket->SendExact(HTTP_MSG_NOSUCHFILE, strlen(HTTP_MSG_NOSUCHFILE));
        return;
    }

    // Switch, dependent upon the filename:
    if (strcmp(filename, "/") == 0)
    {
        char indexpage[2048 + MAX_COMPUTERNAME_LENGTH + 1];

        vnclog.Print(LL_CLIENTS, VNCLOG("sending main page\n"));

        // Send the OK notification message to the client
        if (!socket->SendExact(HTTP_MSG_OK, strlen(HTTP_MSG_OK)))
            return;

        // Compose the index page
        if (m_server->SockConnected())
        {
            int width, height, depth;

            // Get the screen's dimensions
            m_server->GetScreenInfo(width, height, depth);

            // Get the name of this desktop
            char desktopname[MAX_COMPUTERNAME_LENGTH+1];
            if (GetCompName(desktopname, MAX_COMPUTERNAME_LENGTH))
            {
                // Make the name lowercase
                for (int x=0; x<strlen(desktopname); x++)
                {
                    desktopname[x] = tolower(desktopname[x]);
                }
            }
            else
            {
                strcpy(desktopname, szAppName);
            }

            // Send the java applet page
            sprintf(indexpage, HTTP_FMT_INDEX,
                desktopname, width, height+32,
                m_server->GetPort()
                );
        }
        else
        {
            // Send a "sorry, not allowed" page
            sprintf(indexpage, HTTP_MSG_NOSOCKCONN);
        }

        // Send the page
        if (socket->SendExact(indexpage, strlen(indexpage)))
            vnclog.Print(LL_INTINFO, VNCLOG("sent page\n"));

        return;
    }

    // File requested was not the index so check the mappings
    // list for a different file.

    // Now search the mappings for the desired file
    for (int x=0; x < filemappingsize; x++)
    {
        if (strcmp(filename, filemapping[x].filename) == 0)
        {
            VOID *resourceptr = NULL;

            vnclog.Print(LL_INTINFO, VNCLOG("requested file recognised\n"));

            // Load the resource
            APIRET rc = DosGetResource(NULLHANDLE, filemapping[x].type,
                                       filemapping[x].resourceID, &resourceptr);

            if ( (rc != 0) || (resourceptr==NULL) )
                return;

            vnclog.Print(LL_INTINFO, VNCLOG("sending file...\n"));

            // Send the OK message
            if (!socket->SendExact(HTTP_MSG_OK, strlen(HTTP_MSG_OK)))
            {
                DosFreeResource( resourceptr );
                return;
            }

            // Now send the entirety of the data to the client
            if (!socket->SendExact( (const char *)resourceptr, filemapping[x].rsize))
            {
                DosFreeResource( resourceptr );
                return;
            }

            vnclog.Print(LL_INTINFO, VNCLOG("file successfully sent\n"));
            DosFreeResource( resourceptr );

            return;
        }
    }

    // Send the NoSuchFile notification message to the client
    if (!socket->SendExact(HTTP_MSG_NOSUCHFILE, strlen(HTTP_MSG_NOSUCHFILE)))
        return;
}
Example #20
0
/**************************************************************************
 *   GetFormatString                                                     **
 **************************************************************************
 *
 * ARGUMENTS:
 *
 *     lSearchId         - Table search key
 *     pszFormatString   - Address where to return string.
 *                         If null, then string is not returned.
 *     lBytes            - Number of bytes to copy.
 *
 * RETURN:
 *
 *     Returns 0 if string not found, or the number of characters (bytes)
 *     copied to the callers buffer.
 *     Note, returned string is not ASCII nul terminated
 *
 * DESCRIPTION:
 *
 *     This function will retrieve the format string for the specified
 *     IOProc from the resource file that contains the strings.
 *
 ***************************************************************************/
LONG GetFormatString (LONG lSearchId,
                      PSZ  pszFormatString,   /* Null, or dest address     */
                      LONG lBytes)            /* Caller provided maximum   */
{
   PVOID   pResourceData;
   CHAR    *pTemp;
   LONG    lStringLen;      /* Length of format string  */
   LONG    lRetVal = 0;     /* Function return value    */
   LONG    lSearchTemp;

   if(DosGetResource(moduleHandle, RT_RCDATA, IOPROC_NAME_TABLE, &pResourceData))
     return (MMIO_ERROR);

   /*
    * The resource table is of the form : FOURCC String\0
    * Loop until a match is found, then return the string.
    * Copy up to the number of bytes specified.
    */

   lStringLen = 0;
   pTemp = (CHAR *)pResourceData;

   while (pTemp)
      {
      memmove(&lSearchTemp, pTemp, sizeof(LONG));

      if (lSearchTemp == 0L)
         {
         break;  /* End of table, search item not found */
         }

      if (lSearchTemp == lSearchId)   /* Search item found?               */
         {
         pTemp += sizeof(LONG);       /* Bypass numeric search id         */
         lStringLen = strlen(pTemp);  /* Determine length of found string */
         if (lStringLen >= lBytes)    /* Truncate, if necessary           */
            {
            if (lBytes > 0)
               lStringLen = lBytes;   /* Number of characters to return   */
            else
               {
               /* Callers buffer has zero size.  Cannot return any data   */
               lRetVal = 0;           /* Size of returned data            */
               break;                 /* Done searching                   */
               }
            }
         if (pszFormatString != NULL)
           memcpy(pszFormatString, pTemp, lStringLen); /* Copy string to caller */

         lRetVal = lStringLen;        /* Function return value            */
         break;                       /* We're done searching             */
         }

      pTemp += sizeof(FOURCC);
      pTemp += (strlen(pTemp) + 1);   /* Advance to next search key       */
      }

   DosFreeResource(pResourceData);

   return (lRetVal);  /* Zero or strlen */
}
/*------------------------------------------------------------------------------
| Dialog::createControlsFromTemplate                                           |
------------------------------------------------------------------------------*/
Dialog& Dialog :: createControlsFromTemplate( )
{
  PDLGTEMPLATE pdlgt;                /* Dialog Template Pointer         */
  void*        pvStart;              /* Dialog Template Item Pointer    */
  register unsigned long cItems,     /* Dialog Items Counter            */
                         ulRc,       /* Return code                     */
                         i;          /* Loop Counter                    */

                       /* Set mouse pointer to "wait" in case template  */
                       /* is large                                      */
  IPointerHandle oldPointer = mousePointer();
  ISystemPointerHandle systemPointer( ISystemPointerHandle::wait );
  setMousePointer( systemPointer );

                       /* Try reading in the dialog template for the    */
                       /* given dialog ID                               */
  ulRc = DosGetResource( 0, RT_DIALOG, this->ulId, (void **)&pdlgt );
  if ( ulRc != 0 )
  {
                       /* Dialog template not found;  reset mouse       */
                       /* pointer and throw exception                   */
    setMousePointer( oldPointer );
    ITHROWSYSTEMERROR( ulRc,
                       "DosGetResource",
                       IErrorInfo::accessError,
                       IException::recoverable );
  }
                       /* Save pointer to the start of the dlg template */
  pvStart = (void *)pdlgt;

                       /* Save the number of controls found within the  */
                       /* dialog template                               */
  cItems = pdlgt->adlgti[0].cChildren + 1;

                       /* Read in and create an Open Class Library C++  */
                       /* object for each of the controls within the    */
                       /* dialog template                               */
  for ( i = 1; i < cItems; i++ )
  {
                       /* Obtain the id of the control                  */
    unsigned long ulId = (unsigned long)(pdlgt->adlgti[i].id & 0xffff);

                       /* Skip the control if its id is -1              */
    if ( ulId != 0xffff )
    {
                       /* Check to see if a custom control is specified */
                       /* or if a standard PM control class is being    */
                       /* used                                          */
      if ( pdlgt->adlgti[i].cchClassName )
      {
                       /* Since a length for the class name present,    */
                       /* a custom control class name is being used for */
                       /* the control.  Point to the memory location    */
                       /* where the class name is found within the      */
                       /* dialog template information.                  */
        customControl( ulId,
                       ((char *)pvStart + pdlgt->adlgti[i].offClassName) );
      }
      else
      {
                       /* No class name length given indicating that a  */
                       /* standard PM class is being used.  The class   */
                       /* name is stored as an index value.  For        */
                       /* example, the class for static's is defined as */
                       /*                                               */
                       /* #define WC_STATIC ((PSZ)0xffff0005L)          */
                       /*                                               */
                       /* The values within the dialog template for     */
                       /* the static class would be                     */
                       /*                                               */
                       /* adlgti[i].cchClassName = 0                    */
                       /* adlgti[i].offClassName = 5                    */
                       /*                                               */
                       /* Therefore, the value of offClassName field    */
                       /* must be used as an index that is used to      */
                       /* actually select the class name.               */

        switch ( pdlgt->adlgti[i].offClassName )
        {
          case WINCLASS_BUTTON :
            {
              unsigned long ulStyle = pdlgt->adlgti[i].flStyle &
                                      BS_PRIMARYSTYLES;

              switch ( ulStyle )
              {
                case BS_PUSHBUTTON:
                  {
                    if ( pdlgt->adlgti[i].flStyle & (BS_BITMAP | BS_ICON) )
                    {
                      IGraphicPushButton*
                        pGraphicPushButton = new IGraphicPushButton( ulId,
                                                                     this );
                      pGraphicPushButton->setAutoDeleteObject( true );
                      graphicPushButton( pGraphicPushButton );
                    }
                    else
                    {
                      IPushButton*
                        pPushButton = new IPushButton( ulId, this );
                      pPushButton->setAutoDeleteObject( true );
                      this->pushButton( pPushButton );
                    }
                  }
                  break;

                case BS_CHECKBOX:
                case BS_AUTOCHECKBOX:
                  {
                    ICheckBox*
                      pCheckBox = new ICheckBox( ulId, this );
                    pCheckBox->setAutoDeleteObject( true );
                    checkBox( pCheckBox );
                  }
                  break;

                case BS_RADIOBUTTON:
                case BS_AUTORADIOBUTTON:
                  {
                    IRadioButton*
                      pRadioButton = new IRadioButton( ulId, this );
                    pRadioButton->setAutoDeleteObject( true );
                    radioButton( pRadioButton );
                  }
                  break;

                case BS_3STATE:
                case BS_AUTO3STATE:
                  {
                    I3StateCheckBox*
                      p3StateCheckBox = new I3StateCheckBox( ulId, this );
                    p3StateCheckBox->setAutoDeleteObject( true );
                    threeStateCheckBox( p3StateCheckBox );
                  }
                  break;

                case BS_USERBUTTON:
                  {
                    customButton( ulId );
                  }
                  break;
              } //end switch

            } //WINCLASS_BUTTON
            break;

          case WINCLASS_SCROLLBAR :
            {
              IScrollBar*
                pScrollBar = new IScrollBar( ulId, this );
              pScrollBar->setAutoDeleteObject( true );
              scrollBar( pScrollBar );
            }
            break;

          case WINCLASS_LISTBOX :
            {
              IListBox*
                pListBox = new IListBox( ulId, this );
              pListBox->setAutoDeleteObject( true );
              listBox( pListBox );
            }
            break;

          case WINCLASS_ENTRYFIELD :
            {
              IEntryField*
                pEntryField = new IEntryField( ulId, this );
              pEntryField->setAutoDeleteObject( true );
              entryField( pEntryField );
            }
            break;

          case WINCLASS_STATIC :
            {
              unsigned long ulStyle = pdlgt->adlgti[i].flStyle &
                                (SS_TEXT | SS_GROUPBOX | SS_ICON | SS_BITMAP);

              switch ( ulStyle )
              {
                case SS_TEXT:
                  {
                    IStaticText*
                      pStaticText = new IStaticText( ulId, this );
                    pStaticText->setAutoDeleteObject( true );
                    staticText( pStaticText );
                  }
                  break;

                case SS_GROUPBOX:
                  {
                    IGroupBox*
                      pGroupBox = new IGroupBox( ulId, this );
                    pGroupBox->setAutoDeleteObject( true );
                    groupBox( pGroupBox );
                  }
                  break;

                case SS_ICON:
                  {
                    IIconControl*
                      pIcon = new IIconControl( ulId, this );
                    pIcon->setAutoDeleteObject( true );
                    iconControl( pIcon );
                  }
                  break;

                case SS_BITMAP:
                  {
                    IBitmapControl*
                      pBitmap = new IBitmapControl( ulId, this );
                    pBitmap->setAutoDeleteObject( true );
                    bitmapControl( pBitmap );
                  }
                  break;
              } //end switch

            } //WINCLASS_STATIC
            break;

          case WINCLASS_COMBOBOX :
            {
              IComboBox*
                pComboBox = new IComboBox( ulId, this );
              pComboBox->setAutoDeleteObject( true );
              comboBox( pComboBox );
            }
            break;

          case WINCLASS_MLE :
            {
              IMultiLineEdit*
                pMLE = new IMultiLineEdit( ulId, this );
              pMLE->setAutoDeleteObject( true );
              mle( pMLE );
            }
            break;

          case WINCLASS_SPINBUTTON :
            {
              if ( pdlgt->adlgti[i].flStyle & SPBS_NUMERICONLY )
              {
                INumericSpinButton*
                  pNumericSpinButton = new INumericSpinButton( ulId, this );
                pNumericSpinButton->setAutoDeleteObject( true );
                numericSpinButton( pNumericSpinButton );
              }
              else
              {
                ITextSpinButton*
                  pTextSpinButton = new ITextSpinButton( ulId, this );
                pTextSpinButton->setAutoDeleteObject( true );
                textSpinButton( pTextSpinButton );
              }
            }
            break;

          case WINCLASS_CONTAINER :
            {
              IContainerControl*
                pContainer = new IContainerControl( ulId, this );
              pContainer->setAutoDeleteObject( true );
              container( pContainer );
            }
            break;

          case WINCLASS_SLIDER :
            {
              if ( pdlgt->adlgti[i].flStyle & SLS_READONLY )
              {
                IProgressIndicator*
                  pProgressIndicator = new IProgressIndicator( ulId, this );
                pProgressIndicator->setAutoDeleteObject( true );
                progressIndicator( pProgressIndicator );
              }
              else
              {
                ISlider*
                  pSlider = new ISlider( ulId, this );
                pSlider->setAutoDeleteObject( true );
                slider( pSlider );
              }
            }
            break;

          case WINCLASS_VALUESET :
            //No valueset class - see OS/2 C++ Class Library Power GUI
            //Programming with C Set++ for an implementation of a
            //valueset class.
            break;

          case WINCLASS_NOTEBOOK :
            {
              INotebook*
                pNotebook = new INotebook( ulId, this );
              pNotebook->setAutoDeleteObject( true );
              notebook( pNotebook );
            }
            break;

          case WINCLASS_CIRCULARSLIDER :
            {
              ICircularSlider*
                pCircularSlider = new ICircularSlider( ulId, this );
              pCircularSlider->setAutoDeleteObject( true );
              circularSlider( pCircularSlider );
            }
            break;
        } //end switch
      } //end if
    } //end if - id != -1

  } //end for
                       /* Release the memory allocated for the dlg      */
                       /* template before returning                     */
  DosFreeResource( pvStart );
                       /* Reset mouse pointer                           */
  setMousePointer( oldPointer );
  return( *this );
} //Dialog::createControlsFromTemplate