Changeset 74 for branches/v2.9_Lars/common_functions/helper.c
- Timestamp:
- Sep 30, 2023, 11:06:42 PM (23 months ago)
- Location:
- branches/v2.9_Lars
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/v2.9_Lars/common_functions/helper.c
r4 r74 19 19 /* 20 20 * If you need another license for your prject/product contact me at 21 * 21 * 22 22 * http://www.os2world.com/cdwriting 23 23 * http://www.geocities.com/SiliconValley/Sector/5785/ … … 40 40 //#define INSTALLDIR 1 41 41 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 47 #define INI_INACTIVETBBGCLR_KEY 48 #define INI_ACTIVETBFGCLR_KEY 49 #define INI_INACTIVETBFGCLR_KEY 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" 50 50 51 51 /* The subdirectory in the installation directory where to put the log files */ … … 56 56 #define DEFRESDLLNAME "\\mmres_en.dll" 57 57 58 extern char*params[];58 extern PSZ params[]; 59 59 extern HMODULE RESSOURCEHANDLE; 60 60 extern char logName[]; … … 65 65 66 66 HMODULE _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);67 BOOL IniSaveData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, ULONG ulSize); 68 BOOL IniRestoreData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, PULONG ulMaxSize); 69 void writeLog(PSZ logText); 70 70 void HlpWriteToTrapLog(const char* chrFormat, ...); 71 71 … … 74 74 { 75 75 char logNameLocal[CCHMAXPATH]; 76 76 77 77 sprintf(logNameLocal,"%s\\%s\\%s",params[1],LOGFILE_SUBDIR,logName); 78 78 … … 88 88 } 89 89 90 void writeLog( char*logText)90 void writeLog(PSZ logText) 91 91 { 92 92 char logNameLocal[CCHMAXPATH]; … … 117 117 { 118 118 STARTDATA startData={0}; 119 APIRET rc;120 119 PID pid; 121 120 ULONG ulSessionID=0; 122 charchrLoadError[CCHMAXPATH];123 charstartParams[CCHMAXPATH*4];124 charexename[CCHMAXPATH]={0};125 charchrFolderPath[CCHMAXPATH+10];126 121 UCHAR chrLoadError[CCHMAXPATH]; 122 UCHAR startParams[CCHMAXPATH*4]; 123 UCHAR exename[CCHMAXPATH]={0}; 124 UCHAR chrFolderPath[CCHMAXPATH+10]; 125 127 126 memset(&startData,0,sizeof(startData)); 128 127 startData.Length=sizeof(startData); … … 131 130 startData.TraceOpt=SSF_TRACEOPT_NONE; 132 131 startData.PgmTitle=pszTitle; 133 132 134 133 /* sprintf(exename,"%s",buildWrapName(wrapperExe));*/ 135 sprintf( exename,"%s\\bin\\%s",params[1],wrapperExe);134 sprintf((PCHAR)exename,"%s\\bin\\%s",params[1],wrapperExe); 136 135 /* 137 136 if(!checkHelper(exename)) … … 151 150 152 151 /* 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); 156 155 startData.PgmInputs=startParams; 157 156 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 162 BOOL IniRestoreWindowPos(char * iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd) 164 163 { 165 164 HINI hini=0; … … 183 182 }/* end of if(!hini) */ 184 183 185 ulSize=sizeof(swp); 184 ulSize=sizeof(swp); 186 185 if(!PrfQueryProfileData(hini, chrApp, chrKey, &swp, &ulSize)) 187 186 bError=TRUE; … … 189 188 if(hini) 190 189 PrfCloseProfile(hini); 191 190 192 191 if(bError) 193 192 break; … … 199 198 } 200 199 201 BOOL IniSaveWindowPos( char * iniFile, char* chrApp, char *chrKey, HWND hwnd)200 BOOL IniSaveWindowPos(PSZ iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd) 202 201 { 203 202 HINI hini=0; … … 206 205 207 206 /* Open ini-file */ 208 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP), (unsigned char *)iniFile);207 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile); 209 208 do{ 210 209 … … 227 226 if(hini) 228 227 PrfCloseProfile(hini); 229 228 230 229 if(bError) 231 230 break; … … 235 234 } 236 235 237 BOOL IniSaveWindowClrs( char * chrIniFile, char*chrApp , HWND hwnd)236 BOOL IniSaveWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd) 238 237 { 239 238 RGB rgb; … … 283 282 } 284 283 285 BOOL IniRestoreWindowClrs( char * chrIniFile, char*chrApp , HWND hwnd)284 BOOL IniRestoreWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd) 286 285 { 287 286 RGB rgb; 288 287 ULONG ulSize; 289 288 290 289 ulSize=sizeof(RGB); 291 290 if(IniRestoreData(chrIniFile, chrApp, INI_BGCLR_KEY, &rgb, &ulSize)) … … 295 294 PP_BACKGROUNDCOLOR,(ULONG)sizeof(rgb), &rgb); 296 295 } 297 ulSize=sizeof(RGB); 296 ulSize=sizeof(RGB); 298 297 if(IniRestoreData(chrIniFile, chrApp, INI_FGCLR_KEY, &rgb, &ulSize)) 299 298 { … … 306 305 if(IniRestoreData(chrIniFile, chrApp, INI_ACTIVETBBGCLR_KEY, &rgb, &ulSize)) 307 306 { 308 307 309 308 WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR), 310 309 PP_ACTIVECOLOR,(ULONG)sizeof(rgb), &rgb); … … 324 323 if(IniRestoreData(chrIniFile, chrApp, INI_ACTIVETBFGCLR_KEY, &rgb, &ulSize)) 325 324 { 326 325 327 326 // WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR), 328 327 // PP_ACTIVECOLOR,(ULONG)sizeof(rgb), &rgb); … … 341 340 } 342 341 343 BOOL IniSaveInt( char * iniFile, char* chrApp, char *chrKey, int theInt)342 BOOL IniSaveInt(PSZ iniFile, PSZ chrApp, PSZ chrKey, int theInt) 344 343 { 345 344 HINI hini=0; 346 345 BOOL bError=FALSE; 347 charchrIntString[50];346 UCHAR chrIntString[50]; 348 347 349 348 /* Open ini-file */ … … 363 362 }/* end of if(!hini) */ 364 363 365 sprintf( chrIntString, "%d", theInt);364 sprintf((PCHAR)chrIntString, "%d", theInt); 366 365 if(!PrfWriteProfileString(hini, chrApp, chrKey, chrIntString)) 367 366 bError=TRUE; … … 369 368 if(hini) 370 369 PrfCloseProfile(hini); 371 370 372 371 if(bError) 373 372 break; … … 377 376 } 378 377 379 BOOL IniSaveData( char * iniFile, char* chrApp, char *chrKey, void*theData, ULONG ulSize)378 BOOL IniSaveData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, ULONG ulSize) 380 379 { 381 380 HINI hini=0; … … 383 382 384 383 /* Open ini-file */ 385 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP), (unsigned char *)iniFile);384 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile); 386 385 do{ 387 386 … … 403 402 if(hini) 404 403 PrfCloseProfile(hini); 405 404 406 405 if(bError) 407 406 break; … … 411 410 } 412 411 413 BOOL IniRestoreData( char * iniFile, char* chrApp, char *chrKey, void * theData, ULONG*ulMaxSize)412 BOOL IniRestoreData(PSZ iniFile, PSZ chrApp, PSZ chrKey, PVOID theData, PULONG ulMaxSize) 414 413 { 415 414 HINI hini=0; … … 417 416 418 417 /* Open ini-file */ 419 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP), (unsigned char *)iniFile);418 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile); 420 419 do{ 421 420 … … 433 432 434 433 bError=PrfQueryProfileData(hini, chrApp, chrKey, theData, ulMaxSize); 435 434 436 435 if(hini) 437 436 PrfCloseProfile(hini); 438 437 439 438 return bError; 440 439 } while(TRUE); … … 443 442 444 443 445 int IniRestoreInt( char * iniFile, char* chrApp, char *chrKey, int defaultInt)444 int IniRestoreInt(PSZ iniFile, PSZ chrApp, PSZ chrKey, int defaultInt) 446 445 { 447 446 HINI hini=0; … … 449 448 450 449 /* Open ini-file */ 451 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP), (unsigned char *)iniFile);450 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),iniFile); 452 451 do{ 453 452 … … 465 464 466 465 theInt=PrfQueryProfileInt(hini, chrApp, chrKey, defaultInt); 467 466 468 467 if(hini) 469 468 PrfCloseProfile(hini); 470 469 471 470 return theInt; 472 471 } while(TRUE); … … 475 474 476 475 477 BOOL readIni2(char * installDir) 478 { 479 HWND hwnd; 480 481 hwnd=HWND_DESKTOP; 476 BOOL readIni2(PSZ installDir) 477 { 482 478 #if 0 483 479 strncpy(chrInstallDir, installDir,sizeof(chrInstallDir)); 484 480 /* Build full path for cdrecord.ini file */ 485 sprintf(profileName,"%s\\cdrecord.ini", installDir); 481 sprintf(profileName,"%s\\cdrecord.ini", installDir); 486 482 /* Insert message in Logfile */ 487 483 writeLog("Reading values from "); … … 490 486 491 487 /* Open ini-file */ 492 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP), (unsigned char *)profileName);488 hini=PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName); 493 489 do{ 494 490 if(!hini) { … … 522 518 { 523 519 /* Build full path for cdrecord.ini file */ 524 snprintf(chrBuffer, iBufferSize, "%s\\cdrecord.ini", chrInstallDir); 520 snprintf(chrBuffer, iBufferSize, "%s\\cdrecord.ini", chrInstallDir); 525 521 chrBuffer[iBufferSize-1]=0; /* Always terminate with zero */ 526 522 } … … 529 525 HINI HlpOpenIni() 530 526 { 531 charprofileName[CCHMAXPATH];527 UCHAR profileName[CCHMAXPATH]; 532 528 533 529 /* Build full path for cdrecord.ini file */ … … 535 531 536 532 /* Open ini-file */ 537 return PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP), (unsigned char *)profileName);533 return PrfOpenProfile(WinQueryAnchorBlock(HWND_DESKTOP),profileName); 538 534 } 539 535 … … 568 564 BOOL HlpBuildMMProgIniFileName(char* chrProgname, char * chrBuffer, ULONG ulBufferSize) 569 565 { 570 char * chrPtr; 566 char * chrPtr; 571 567 572 568 /* Default is INI file in users home dir */ … … 591 587 #if 0 592 588 /* This function returns the module handle of our ressource dll */ 593 HMODULE queryResModuleHandle( char *chrExePath)589 HMODULE queryResModuleHandle(PSZ chrExePath) 594 590 { 595 591 COUNTRYCODE country= {0}; 596 592 COUNTRYINFO countryInfo= {0}; 597 char path[CCHMAXPATH];598 charbuf[CCHMAXPATH];599 char*found;593 UCHAR path[CCHMAXPATH]; 594 UCHAR buf[CCHMAXPATH]; 595 PUCHAR found; 600 596 APIRET rc; 601 597 ULONG ulInfoLen; 602 598 603 599 if(!RESSOURCEHANDLE) { 604 600 605 601 //writeLog("Trying to load ressource DLL.\n"); 606 602 607 /* Get the country code of our system and load the 603 /* Get the country code of our system and load the 608 604 resource DLL with the right language */ 609 605 do { … … 632 628 /* Insert message in Logfile */ 633 629 // writeLog("Ressource-DLL for the current countrycode not found. Trying to load default one (CDFLD001.DLL).\n"); 634 630 635 631 /* NLS DLL not found. Try to load default */ 636 632 found=strrchr(path,'\\'); … … 644 640 //HlpWriteToTrapLog(path); 645 641 //HlpWriteToTrapLog("\n"); 646 642 647 643 648 644 rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE); … … 662 658 663 659 /* This function returns the module handle of our ressource dll */ 664 HMODULE queryResModuleHandle( char *chrExePath)665 { 666 char path[CCHMAXPATH];667 charbuf[CCHMAXPATH];668 char*found;660 HMODULE queryResModuleHandle(PSZ chrExePath) 661 { 662 UCHAR path[CCHMAXPATH]; 663 UCHAR buf[CCHMAXPATH]; 664 PCHAR found; 669 665 APIRET rc; 670 666 671 667 if(!RESSOURCEHANDLE) { 672 668 673 669 //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 676 672 resource DLL with the right language */ 677 do 673 do 678 674 { 679 static charchrLang[]="en_EN";680 PSZ pszLang= "";681 char *chrPtr;682 675 static UCHAR chrLang[]="en_EN"; 676 PSZ pszLang=NULL; 677 PUCHAR chrPtr; 678 683 679 /* Get Language var */ 684 if(NO_ERROR!=DosScanEnv( "LANG", &pszLang)) {680 if(NO_ERROR!=DosScanEnv((PSZ)"LANG", &pszLang)) { 685 681 pszLang=chrLang; 686 } 682 } 687 683 /* Skip leading spaces */ 688 684 chrPtr=pszLang; 689 685 while(*chrPtr==' ') 690 686 chrPtr++; 691 687 692 688 /* 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) 694 690 break; 695 696 sprintf( path,"%s", chrExePath);691 692 sprintf((PCHAR)path,"%s", chrExePath); 697 693 // SysWriteToTrapLog(path); 698 if((found=strrchr( path, '\\'))!=NULLHANDLE)694 if((found=strrchr((PCHAR)path, '\\'))!=NULLHANDLE) 699 695 *found=0; 700 696 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); 704 700 /* Insert message in Logfile */ 705 701 // SysWriteToTrapLog("Using the following DLL path: %s\n", path); 706 702 707 703 rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE); 708 704 if(rc==NO_ERROR) 709 705 break; 710 706 711 707 /* Insert message in Logfile */ 712 708 SysWriteToTrapLog("Ressource-DLL for the current country not found. Trying to load default one.\n"); 713 709 714 710 /* NLS DLL not found. Try to load default */ 715 found=strrchr( path,'\\');711 found=strrchr((PCHAR)path,(int)'\\'); 716 712 if(!found) 717 713 break; 718 714 719 715 *found=0; 720 sprintf( buf, DEFRESDLLNAME);721 strcat( path,buf);716 sprintf((PCHAR)buf, DEFRESDLLNAME); 717 strcat((PCHAR)path,(const PCHAR)buf); 722 718 //HlpWriteToTrapLog("Using the following DLL path: "); 723 719 //HlpWriteToTrapLog(path); 724 720 //HlpWriteToTrapLog("\n"); 725 726 721 722 727 723 rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE); 728 724 if(rc!=NO_ERROR) { … … 745 741 } 746 742 747 void HlpSendCommandToObject( char* chrObject, char*command)743 void HlpSendCommandToObject(PSZ chrObject, PSZ command) 748 744 { 749 745 HOBJECT hObject; 750 charchrCommand[CCHMAXPATH];746 UCHAR chrCommand[CCHMAXPATH]; 751 747 752 748 hObject=WinQueryObject(chrObject); 753 sprintf( chrCommand,"Querying object pointer for: %s\n", chrObject);749 sprintf((PCHAR)chrCommand,"Querying object pointer for: %s\n", chrObject); 754 750 writeLog(chrCommand); 755 751 if(hObject!=NULLHANDLE) { 756 strcpy( chrCommand,command);752 strcpy((PCHAR)chrCommand,(const PCHAR)command); 757 753 WinSetObjectData(hObject,chrCommand); 758 writeLog( "Sending command to object: ");754 writeLog((PSZ)"Sending command to object: "); 759 755 writeLog(command); 760 writeLog( "\n");756 writeLog((PSZ)"\n"); 761 757 } 762 758 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); 764 760 writeLog(chrCommand); 765 761 } 766 762 } 767 763 768
Note:
See TracChangeset
for help on using the changeset viewer.