Ignore:
Timestamp:
Sep 30, 2023, 11:06:42 PM (23 months ago)
Author:
erdmann
Message:

Created branch v2.9_Lars.

Location:
branches/v2.9_Lars
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/v2.9_Lars/common_functions/helper.c

    r4 r74  
    1919/*
    2020 * If you need another license for your prject/product contact me at
    21  * 
     21 *
    2222 * http://www.os2world.com/cdwriting
    2323 * http://www.geocities.com/SiliconValley/Sector/5785/
     
    4040//#define INSTALLDIR 1
    4141
    42 #define INI_BGCLR_KEY       "bg"
    43 #define INI_FGCLR_KEY       "fg"
    44 #define INI_BTNBGCLR_KEY       "btnbg"
    45 #define INI_BTNFGCLR_KEY       "btnfg"
    46 #define INI_ACTIVETBBGCLR_KEY       "activetbbg"
    47 #define INI_INACTIVETBBGCLR_KEY       "inactivetbbg"
    48 #define INI_ACTIVETBFGCLR_KEY       "activetbfg"
    49 #define INI_INACTIVETBFGCLR_KEY       "inactivetbfg"
     42#define INI_BGCLR_KEY            (PSZ)"bg"
     43#define INI_FGCLR_KEY            (PSZ)"fg"
     44#define INI_BTNBGCLR_KEY         (PSZ)"btnbg"
     45#define INI_BTNFGCLR_KEY         (PSZ)"btnfg"
     46#define INI_ACTIVETBBGCLR_KEY    (PSZ)"activetbbg"
     47#define INI_INACTIVETBBGCLR_KEY  (PSZ)"inactivetbbg"
     48#define INI_ACTIVETBFGCLR_KEY    (PSZ)"activetbfg"
     49#define INI_INACTIVETBFGCLR_KEY  (PSZ)"inactivetbfg"
    5050
    5151/* The subdirectory in the installation directory where to put the log files */
     
    5656#define DEFRESDLLNAME "\\mmres_en.dll"
    5757
    58 extern char* params[];
     58extern PSZ params[];
    5959extern HMODULE RESSOURCEHANDLE;
    6060extern char logName[];
     
    6565
    6666HMODULE _queryResModuleHandle2(char *installDir);
    67 BOOL IniSaveData(char * iniFile, char* chrApp, char *chrKey, void* theData, ULONG ulSize);
    68 BOOL IniRestoreData(char * iniFile, char* chrApp, char *chrKey, void * theData, ULONG* ulMaxSize);
    69 void writeLog(char* logText);
     67BOOL IniSaveData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, ULONG ulSize);
     68BOOL IniRestoreData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, PULONG ulMaxSize);
     69void writeLog(PSZ logText);
    7070void HlpWriteToTrapLog(const char* chrFormat, ...);
    7171
     
    7474{
    7575  char logNameLocal[CCHMAXPATH];
    76  
     76
    7777  sprintf(logNameLocal,"%s\\%s\\%s",params[1],LOGFILE_SUBDIR,logName);
    7878
     
    8888}
    8989
    90 void writeLog(char* logText)
     90void writeLog(PSZ logText)
    9191{
    9292  char logNameLocal[CCHMAXPATH];
     
    117117{
    118118  STARTDATA startData={0};
    119   APIRET rc;
    120119  PID pid;
    121120  ULONG ulSessionID=0;
    122   char chrLoadError[CCHMAXPATH];
    123   char startParams[CCHMAXPATH*4];
    124   char exename[CCHMAXPATH]={0};
    125   char chrFolderPath[CCHMAXPATH+10];
    126  
     121  UCHAR chrLoadError[CCHMAXPATH];
     122  UCHAR startParams[CCHMAXPATH*4];
     123  UCHAR exename[CCHMAXPATH]={0};
     124  UCHAR chrFolderPath[CCHMAXPATH+10];
     125
    127126  memset(&startData,0,sizeof(startData));
    128127  startData.Length=sizeof(startData);
     
    131130  startData.TraceOpt=SSF_TRACEOPT_NONE;
    132131  startData.PgmTitle=pszTitle;
    133    
     132
    134133  /*  sprintf(exename,"%s",buildWrapName(wrapperExe));*/
    135   sprintf(exename,"%s\\bin\\%s",params[1],wrapperExe);
     134  sprintf((PCHAR)exename,"%s\\bin\\%s",params[1],wrapperExe);
    136135  /*
    137136    if(!checkHelper(exename))
     
    151150
    152151  /* Put the exe-path between " " to make sure, spaces are handled correctly */
    153   strcpy(chrFolderPath,folderPath);
    154   sprintf(startParams,"\"%s\" \"%s\" %s",
    155           chrInstallDir,chrFolderPath, parameter);
     152  strcpy((PCHAR)chrFolderPath,(PCHAR)folderPath);
     153  sprintf((PCHAR)startParams,"\"%s\" \"%s\" %s",
     154          (PCHAR)chrInstallDir,(PCHAR)chrFolderPath, (PCHAR)parameter);
    156155  startData.PgmInputs=startParams;
    157156
    158   rc=DosStartSession(&startData,&ulSessionID,&pid);   
    159   return 0;   
    160 }
    161 
    162 
    163 BOOL IniRestoreWindowPos(char * iniFile, char* chrApp, char *chrKey, HWND hwnd)
     157  DosStartSession(&startData,&ulSessionID,&pid);
     158  return 0;
     159}
     160
     161
     162BOOL IniRestoreWindowPos(char * iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd)
    164163{
    165164  HINI hini=0;
     
    183182    }/* end of if(!hini) */
    184183
    185     ulSize=sizeof(swp); 
     184    ulSize=sizeof(swp);
    186185    if(!PrfQueryProfileData(hini, chrApp, chrKey, &swp, &ulSize))
    187186      bError=TRUE;
     
    189188    if(hini)
    190189      PrfCloseProfile(hini);
    191    
     190
    192191    if(bError)
    193192      break;
     
    199198}
    200199
    201 BOOL IniSaveWindowPos(char * iniFile, char* chrApp, char *chrKey, HWND hwnd)
     200BOOL IniSaveWindowPos(PSZ iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd)
    202201{
    203202  HINI hini=0;
     
    206205
    207206  /* Open ini-file */
    208   hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile);
     207  hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
    209208  do{
    210209
     
    227226    if(hini)
    228227      PrfCloseProfile(hini);
    229    
     228
    230229    if(bError)
    231230      break;
     
    235234}
    236235
    237 BOOL IniSaveWindowClrs(char * chrIniFile, char* chrApp , HWND hwnd)
     236BOOL IniSaveWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd)
    238237{
    239238  RGB rgb;
     
    283282}
    284283
    285 BOOL IniRestoreWindowClrs(char * chrIniFile, char* chrApp , HWND hwnd)
     284BOOL IniRestoreWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd)
    286285{
    287286  RGB rgb;
    288287  ULONG ulSize;
    289  
     288
    290289  ulSize=sizeof(RGB);
    291290  if(IniRestoreData(chrIniFile, chrApp, INI_BGCLR_KEY, &rgb, &ulSize))
     
    295294                      PP_BACKGROUNDCOLOR,(ULONG)sizeof(rgb), &rgb);
    296295    }
    297   ulSize=sizeof(RGB);       
     296  ulSize=sizeof(RGB);
    298297  if(IniRestoreData(chrIniFile, chrApp, INI_FGCLR_KEY, &rgb, &ulSize))
    299298    {
     
    306305  if(IniRestoreData(chrIniFile, chrApp, INI_ACTIVETBBGCLR_KEY, &rgb, &ulSize))
    307306    {
    308            
     307
    309308      WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
    310309                      PP_ACTIVECOLOR,(ULONG)sizeof(rgb), &rgb);
     
    324323  if(IniRestoreData(chrIniFile, chrApp, INI_ACTIVETBFGCLR_KEY, &rgb, &ulSize))
    325324    {
    326            
     325
    327326      //            WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR),
    328327      //              PP_ACTIVECOLOR,(ULONG)sizeof(rgb), &rgb);
     
    341340}
    342341
    343 BOOL IniSaveInt(char * iniFile, char* chrApp, char *chrKey, int theInt)
     342BOOL IniSaveInt(PSZ iniFile, PSZ chrApp, PSZ chrKey, int theInt)
    344343{
    345344  HINI hini=0;
    346345  BOOL bError=FALSE;
    347   char chrIntString[50];
     346  UCHAR chrIntString[50];
    348347
    349348  /* Open ini-file */
     
    363362    }/* end of if(!hini) */
    364363
    365     sprintf(chrIntString, "%d", theInt);
     364    sprintf((PCHAR)chrIntString, "%d", theInt);
    366365    if(!PrfWriteProfileString(hini, chrApp, chrKey, chrIntString))
    367366      bError=TRUE;
     
    369368    if(hini)
    370369      PrfCloseProfile(hini);
    371    
     370
    372371    if(bError)
    373372      break;
     
    377376}
    378377
    379 BOOL IniSaveData(char * iniFile, char* chrApp, char *chrKey, void* theData, ULONG ulSize)
     378BOOL IniSaveData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, ULONG ulSize)
    380379{
    381380  HINI hini=0;
     
    383382
    384383  /* Open ini-file */
    385   hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile);
     384  hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
    386385  do{
    387386
     
    403402    if(hini)
    404403      PrfCloseProfile(hini);
    405    
     404
    406405    if(bError)
    407406      break;
     
    411410}
    412411
    413 BOOL IniRestoreData(char * iniFile, char* chrApp, char *chrKey, void * theData, ULONG* ulMaxSize)
     412BOOL IniRestoreData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, PULONG ulMaxSize)
    414413{
    415414  HINI hini=0;
     
    417416
    418417  /* Open ini-file */
    419   hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile);
     418  hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
    420419  do{
    421420
     
    433432
    434433    bError=PrfQueryProfileData(hini, chrApp, chrKey, theData, ulMaxSize);
    435    
     434
    436435    if(hini)
    437436      PrfCloseProfile(hini);
    438    
     437
    439438    return bError;
    440439  } while(TRUE);
     
    443442
    444443
    445 int IniRestoreInt(char * iniFile, char* chrApp, char *chrKey, int defaultInt)
     444int IniRestoreInt(PSZ iniFile, PSZ chrApp, PSZ chrKey, int defaultInt)
    446445{
    447446  HINI hini=0;
     
    449448
    450449  /* Open ini-file */
    451   hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)iniFile);
     450  hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile);
    452451  do{
    453452
     
    465464
    466465    theInt=PrfQueryProfileInt(hini, chrApp, chrKey, defaultInt);
    467    
     466
    468467    if(hini)
    469468      PrfCloseProfile(hini);
    470    
     469
    471470    return theInt;
    472471  } while(TRUE);
     
    475474
    476475
    477 BOOL readIni2(char * installDir)
    478 {
    479   HWND hwnd;
    480 
    481   hwnd=HWND_DESKTOP;
     476BOOL readIni2(PSZ installDir)
     477{
    482478#if 0
    483479  strncpy(chrInstallDir, installDir,sizeof(chrInstallDir));
    484480  /* Build full path for cdrecord.ini file */
    485   sprintf(profileName,"%s\\cdrecord.ini", installDir);       
     481  sprintf(profileName,"%s\\cdrecord.ini", installDir);
    486482  /* Insert message in Logfile */
    487483  writeLog("Reading values from ");
     
    490486
    491487  /* Open ini-file */
    492   hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)profileName);
     488  hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
    493489  do{
    494490    if(!hini) {
     
    522518{
    523519  /* Build full path for cdrecord.ini file */
    524   snprintf(chrBuffer, iBufferSize, "%s\\cdrecord.ini", chrInstallDir);       
     520  snprintf(chrBuffer, iBufferSize, "%s\\cdrecord.ini", chrInstallDir);
    525521  chrBuffer[iBufferSize-1]=0; /* Always terminate with zero */
    526522}
     
    529525HINI HlpOpenIni()
    530526{
    531   char profileName[CCHMAXPATH];
     527  UCHAR profileName[CCHMAXPATH];
    532528
    533529  /* Build full path for cdrecord.ini file */
     
    535531
    536532  /* Open ini-file */
    537   return PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),(unsigned char *)profileName);
     533  return PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName);
    538534}
    539535
     
    568564BOOL HlpBuildMMProgIniFileName(char* chrProgname, char * chrBuffer, ULONG ulBufferSize)
    569565{
    570   char * chrPtr; 
     566  char * chrPtr;
    571567
    572568  /* Default is INI file in users home dir */
     
    591587#if 0
    592588/* This function returns the module handle of our ressource dll */
    593 HMODULE queryResModuleHandle(char *chrExePath)
     589HMODULE queryResModuleHandle(PSZ chrExePath)
    594590{
    595591  COUNTRYCODE country= {0};
    596592  COUNTRYINFO countryInfo= {0};
    597   char path[CCHMAXPATH]; 
    598   char buf[CCHMAXPATH];
    599   char* found;
     593  UCHAR path[CCHMAXPATH];
     594  UCHAR buf[CCHMAXPATH];
     595  PUCHAR found;
    600596  APIRET rc;
    601597  ULONG ulInfoLen;
    602    
     598
    603599  if(!RESSOURCEHANDLE) {
    604600
    605601    //writeLog("Trying to load ressource DLL.\n");
    606602
    607     /* Get the country code of our system and load the 
     603    /* Get the country code of our system and load the
    608604       resource DLL with the right language */
    609605    do {
     
    632628      /* Insert message in Logfile */
    633629      //      writeLog("Ressource-DLL for the current countrycode not found. Trying to load default one (CDFLD001.DLL).\n");
    634      
     630
    635631      /* NLS DLL not found. Try to load default */
    636632      found=strrchr(path,'\\');
     
    644640      //HlpWriteToTrapLog(path);
    645641      //HlpWriteToTrapLog("\n");
    646      
     642
    647643
    648644      rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE);
     
    662658
    663659/* This function returns the module handle of our ressource dll */
    664 HMODULE queryResModuleHandle(char *chrExePath)
    665 {
    666   char path[CCHMAXPATH]; 
    667   char buf[CCHMAXPATH];
    668   char* found;
     660HMODULE queryResModuleHandle(PSZ chrExePath)
     661{
     662  UCHAR path[CCHMAXPATH];
     663  UCHAR buf[CCHMAXPATH];
     664  PCHAR found;
    669665  APIRET rc;
    670    
     666
    671667  if(!RESSOURCEHANDLE) {
    672    
     668
    673669    //writeLog("Trying to load ressource DLL.\n");
    674    
    675     /* Get the language code of our system and load the 
     670
     671    /* Get the language code of our system and load the
    676672       resource DLL with the right language */
    677     do 
     673    do
    678674      {
    679         static char chrLang[]="en_EN";
    680         PSZ pszLang="";
    681         char *chrPtr;
    682        
     675        static UCHAR chrLang[]="en_EN";
     676        PSZ pszLang=NULL;
     677        PUCHAR chrPtr;
     678
    683679        /* Get Language var */
    684         if(NO_ERROR!=DosScanEnv("LANG", &pszLang)) {
     680        if(NO_ERROR!=DosScanEnv((PSZ)"LANG", &pszLang)) {
    685681         pszLang=chrLang;
    686         }       
     682        }
    687683        /* Skip leading spaces */
    688684        chrPtr=pszLang;
    689685        while(*chrPtr==' ')
    690686          chrPtr++;
    691        
     687
    692688        /* Check if value seems to be valid. The var must be something like xx_XX thus length is 5 */
    693         if(strlen(chrPtr)<5)
     689        if(strlen((PCHAR)chrPtr)<5)
    694690          break;
    695        
    696         sprintf(path,"%s", chrExePath);
     691
     692        sprintf((PCHAR)path,"%s", chrExePath);
    697693        //    SysWriteToTrapLog(path);
    698         if((found=strrchr(path, '\\'))!=NULLHANDLE)
     694        if((found=strrchr((PCHAR)path, '\\'))!=NULLHANDLE)
    699695          *found=0;
    700696
    701         /* Extract the first two chars */               
    702         sprintf(buf, RESDLLNAME, chrPtr[0], chrPtr[1]);
    703         strcat(path,buf);
     697        /* Extract the first two chars */
     698        sprintf((PCHAR)buf, RESDLLNAME, chrPtr[0], chrPtr[1]);
     699        strcat((PCHAR)path,(const PCHAR)buf);
    704700        /* Insert message in Logfile */
    705701        // SysWriteToTrapLog("Using the following DLL path: %s\n", path);
    706        
     702
    707703        rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE);
    708704        if(rc==NO_ERROR)
    709705          break;
    710        
     706
    711707        /* Insert message in Logfile */
    712708        SysWriteToTrapLog("Ressource-DLL for the current country not found. Trying to load default one.\n");
    713        
     709
    714710        /* NLS DLL not found. Try to load default */
    715         found=strrchr(path,'\\');
     711        found=strrchr((PCHAR)path,(int)'\\');
    716712        if(!found)
    717713          break;
    718        
     714
    719715        *found=0;
    720         sprintf(buf, DEFRESDLLNAME);
    721         strcat(path,buf);
     716        sprintf((PCHAR)buf, DEFRESDLLNAME);
     717        strcat((PCHAR)path,(const PCHAR)buf);
    722718        //HlpWriteToTrapLog("Using the following DLL path: ");
    723719        //HlpWriteToTrapLog(path);
    724720        //HlpWriteToTrapLog("\n");
    725        
    726        
     721
     722
    727723        rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE);
    728724        if(rc!=NO_ERROR) {
     
    745741}
    746742
    747 void HlpSendCommandToObject(char* chrObject, char* command)
     743void HlpSendCommandToObject(PSZ chrObject, PSZ command)
    748744{
    749745  HOBJECT hObject;
    750   char chrCommand[CCHMAXPATH];
     746  UCHAR chrCommand[CCHMAXPATH];
    751747
    752748  hObject=WinQueryObject(chrObject);
    753   sprintf(chrCommand,"Querying object pointer for: %s\n", chrObject);
     749  sprintf((PCHAR)chrCommand,"Querying object pointer for: %s\n", chrObject);
    754750  writeLog(chrCommand);
    755751  if(hObject!=NULLHANDLE) {
    756     strcpy(chrCommand,command);
     752    strcpy((PCHAR)chrCommand,(const PCHAR)command);
    757753    WinSetObjectData(hObject,chrCommand);
    758     writeLog("Sending command to object: ");
     754    writeLog((PSZ)"Sending command to object: ");
    759755    writeLog(command);
    760     writeLog("\n");
     756    writeLog((PSZ)"\n");
    761757  }
    762758  else {
    763     sprintf(chrCommand,"Can't query object pointer for: %s\n", chrObject);
     759    sprintf((PCHAR)chrCommand,"Can't query object pointer for: %s\n", chrObject);
    764760    writeLog(chrCommand);
    765761  }
    766762}
    767763
    768 
Note: See TracChangeset for help on using the changeset viewer.