home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Unleashed
/
Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso
/
repease
/
rep_file.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-03
|
28KB
|
734 lines
/*==============================================================================
REP_FILE.C
Report Ease file i/o and report parameter functions.
Report Ease
Sub Systems, Inc.
ReportEase, Copyright (c) 1992, Sub Systems, Inc. All Rights Reserved.
159 Main Street, #8C, Stoneham, MA 02180
(617) 438-8901.
Software License Agreement (1992)
----------------------------------
This license agreement allows the purchaser the right to modify the
source code to incorporate in their application.
The target application must not be distributed as a standalone report writer
or a mail merge product.
Sub Systems, Inc. reserves the right to prosecute anybody found to be
making illegal copies of the executable software or compiling the source
code for the purpose of selling there after.
===============================================================================*/
#include "windows.h"
#if defined (_WIN32)
#if !defined(WIN32)
#define WIN32
#endif
#endif
#if !defined(WIN32)
#include "print.h"
#endif
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "fcntl.h"
#include "io.h"
#include "string.h"
#include "sys\types.h"
#include "sys\stat.h"
#include "setjmp.h"
#include "commdlg.h"
#include "rep.h"
#define PREFIX extern
#include "rep1.h"
/*****************************************************************************
FrRead:
Read the input file or parse the input buffer to separate each text line.
The routine return a TRUE value when successful.
******************************************************************************/
BOOL FrRead(LPSTR InputFile)
{
int rwMode=6,i;
int font,ItemSize;
HFILE iFile;
LPSTR pImage,pInfo;
BYTE signature;
DWORD ImageSize,InfoSize;
char line[LINE_WIDTH+2],ProfString[3][NAME_WIDTH+2];
strupr(InputFile);
rTrim(InputFile); // trim any spaces on right
if (strlen(InputFile)==0) {
InitNewForm(); // initialize the new form
return TRUE;
}
if (access(InputFile,rwMode)==-1) {
wsprintf(msg,"File: %s Does Not Exist, Create a New Form?",(LPSTR)InputFile);
if (IDNO==MessageBox(hFrWnd,msg,"New Form",MB_YESNO)) {
CloseFr();
return FALSE;
}
else {
InitNewForm(); // initialize the report
return TRUE; // the file will be created at update time
}
}
if ((iFile=_lopen(InputFile,OF_READ))==HFILE_ERROR) {
AbortFr("Could Not Open the Input File.",32);
}
SetCursor(hWaitCursor); // show hour glass while reading
// INITIALIZE FONTS
for (i=1;i<MAX_FONTS;i++) { // initialize the font table
if (FrFont[i].InUse) DeleteFrObject(i); // delete old font/picture
}
// READ HEADER
if (_lread(iFile,&FormHdr,sizeof(struct StrFormHdr))!=sizeof(struct StrFormHdr)
|| FormHdr.FormSign!=FORM_SIGN ) {
AbortFr("Not a valid form file",33);
}
TotalItems=FormHdr.TotalItems;
// READ TEXT LINES
FrHeight=0; // build the form height as well
if (FormHdr.FileFormatId<=2 && !Win32) ItemSize=OLD_ITEM_SIZE;
else ItemSize=sizeof(struct StrItem);
for(i=0;i<TotalItems;i++) { // read each text line
if (ItemSize<sizeof(struct StrItem)) FarMemSet(&(item[i]),0,sizeof(struct StrItem));
if (!FrFarRead(iFile,ItemSize,(char huge *)&(item[i]))) {
AbortFr("Error reading the item data",35);
}
if (item[i].type==LABEL || item[i].type==PICT || item[i].type==FIELD) {
font=item[i].font;
FrFont[font].InUse=TRUE; // font in use
}
if (item[i].type==SECTION) { // build the form height
FrHeight+=item[i].height; // current height of the form
}
}
// READ FIELDS
if (FormHdr.FileFormatId==0) { // old format: uses larger field records
for (i=0;i<FormHdr.FieldCount;i++) {// read one field at a time
// read one field
if (!FrFarRead(iFile,(long)sizeof(struct StrField),(char huge *)&(field[i])) ){
AbortFr("Error reading one field",36);
}
// read and discard extra 4 bytes that the old field format used
if (!FrFarRead(iFile,4,(char huge *)line) ){
AbortFr("Error reading field extra bytes",36);
}
}
}
else { // new field records are 256 bytes
if (!FrFarRead(iFile,(long)sizeof(struct StrField)*(long)FormHdr.FieldCount,(char huge *)field) ){
AbortFr("Error reading the fields",36);
}
}
// READ BREAK FIELD
if (!FrFarRead(iFile,(long)sizeof(struct StrBreakField)*(long)FormHdr.BreakFieldCount,(char huge *)BreakField) ){
AbortFr("Error reading the break fields",36);
}
// READ SECTIONS
if (FormHdr.FileFormatId<2) { // old format: uses only one detail section
for (i=0;i<=SEC_DETAIL1;i++) { // read upto the detail section
if (!FrFarRead(iFile,(long)sizeof(struct StrSection),(char huge *)&(section[i])) ) {
AbortFr("Error reading one section",36);
}
}
for (i=SEC_FTR_LVL9;i<MAX_SECTIONS;i++) { // read the footer sections
if (!FrFarRead(iFile,(long)sizeof(struct StrSection),(char huge *)&(section[i])) ) {
AbortFr("Error reading one section(B)",36);
}
}
// Fix indexes in the item array
for(i=0;i<TotalItems;i++) if (item[i].section>SEC_DETAIL1) item[i].section+=8; // 8 new sections added
// Fix indexes in the field array
for (i=0;i<FormHdr.FieldCount;i++) if (field[i].section>SEC_DETAIL1) field[i].section+=8; // 8 new sections added
// Fix indexes in the BreakField array
for (i=0;i<FormHdr.BreakFieldCount;i++) if (BreakField[i].section>SEC_DETAIL1) BreakField[i].section+=8; // 8 new sections added
}
else {
if (!FrFarRead(iFile,(long)sizeof(struct StrSection)*(long)MAX_SECTIONS,(char huge *)section) ) {
AbortFr("Error reading the sections",36);
}
}
if (!FrFarRead(iFile,(long)sizeof(struct StrDlgField)*(long)MAX_DLGS,(char huge *)DlgField)) {
AbortFr("Dialog fields missing!",37);
}
// READ FONT TABLE
if (!FrFarRead(iFile,1,&signature)) goto NO_FONT;
if (signature!=FontSign) goto NO_FONT;
TotalFonts=FormHdr.FontCount;
if (TotalFonts>MAX_FONTS) TotalFonts=MAX_FONTS;
for (i=0;i<TotalFonts;i++) { // read each font table element
if (!FrFarRead(iFile,sizeof(int),(char huge *)&(FrFont[i].IsPict))) goto NO_FONT;
if (FrFont[i].IsPict) { // read in the picture bitmap
//**** read the display dimensions of the picture ******
if (!FrFarRead(iFile,sizeof(UINT),(char huge *)&(FrFont[i].PictHeight))) goto NO_FONT;
if (!FrFarRead(iFile,sizeof(UINT),(char huge *)&(FrFont[i].PictWidth))) goto NO_FONT;
//*** read the picture storage size in bytes ***
if (!FrFarRead(iFile,sizeof(DWORD),(char huge *)&ImageSize)) goto NO_FONT;
if (!FrFarRead(iFile,sizeof(DWORD),(char huge *)&InfoSize)) goto NO_FONT;
FrFont[i].ImageSize=ImageSize;
FrFont[i].InfoSize=InfoSize;
if (InfoSize>0) {
//************ Allocate Space for image and info *********
if (NULL==(FrFont[i].hImage=GlobalAlloc(GMEM_MOVEABLE,ImageSize))
|| NULL==(FrFont[i].hInfo=GlobalAlloc(GMEM_MOVEABLE,InfoSize))
|| NULL==(pImage=GlobalLock(FrFont[i].hImage))
|| NULL==(pInfo=GlobalLock(FrFont[i].hInfo)) ) {
AbortFr("Ran Out of Memory for Picture Bitmap",ERR_NO_MEM);
}
//********** Read image and info data *******************
if (!FrFarRead(iFile,ImageSize,pImage)) goto NO_FONT;
if (!FrFarRead(iFile,InfoSize,pInfo)) goto NO_FONT;
GlobalUnlock(FrFont[i].hImage);
GlobalUnlock(FrFont[i].hInfo);
}
}
else { // read the logical font structure
if (!FrFarRead(iFile,sizeof(LOGFONT),(char huge *)&(FrFont[i].lFont))) goto NO_FONT;
}
}
goto END_FILE;
NO_FONT:
MessageBox(hFrWnd,"Font Table Incomplete!",NULL,MB_OK);
END_FILE:
_lclose(iFile);
TotalFields=FormHdr.FieldCount;
TotalBreakFields=FormHdr.BreakFieldCount;
TotalFonts=FormHdr.FontCount;
// FIND_PRINTER
if (strcmp(PrinterName,FormHdr.PrinterName)!=0 || strcmp(PrinterDriver,FormHdr.PrinterDriver)!=0) {
// form does not use the default printer
if (ParseProfileString("devices",FormHdr.PrinterName,ProfString[0],ProfString[1],ProfString[2])) {
strcpy(PrinterPort,ProfString[1]); // extract the device port
strcpy(PrinterName,FormHdr.PrinterName);
strcpy(PrinterDriver,ProfString[0]);
InitPrinter(); // read the printer data
}
}
// apply the header data to the printer structure
pDevMode->dmOrientation=FormHdr.Orientation;
pDevMode->dmPaperSize=FormHdr.PaperSize;
pDevMode->dmPaperLength=FormHdr.PaperLength;
pDevMode->dmPaperWidth=FormHdr.PaperWidth;
pDevMode->dmPrintQuality=FormHdr.PrintQuality;
CallPrinterDriver(DM_MODIFY|DM_UPDATE);
if (!UseScreen) { // create the printer device context
strcpy(line,PrinterDriver);
line[strlen(line)-4]=0; // strip the .drv extension
if (NULL==(hFrDC=CreateDC(line,PrinterName,PrinterPort,pDevMode))) {
AbortFr("Can not initialize printing",ERR_NO_DEVICE);
}
ResX=GetDeviceCaps(hFrDC,LOGPIXELSX); // number of pixels per inch of X direction
ResY=GetDeviceCaps(hFrDC,LOGPIXELSY); // number of pixels per inch of Y direction
SetLogicalUnit(hFrDC); // set the logical units
if (!GetTextMetrics(hFrDC,&FrTextMet)) { // get text metric for the newly created font
AbortFr("Unable to get text metric for the font.",ERR_DISPLAY);
}
}
ProcessPrinterData(); // calculate operational variables from the header fields
// REALIZE_FONTS
FrFont[0].InUse=TRUE; // default font always used
for (i=0;i<TotalFonts;i++) {
if (FrFont[i].InUse) {
if (FrFont[i].IsPict) { // create device bitmap
FrXlateDIB(hFrDC,i);
}
else {
if (!CreateOneFont(hFrDC,i)) { // create a new font
wsprintf(line,"Error Creating Font: %s",FrFont[i].lFont.lfFaceName);
AbortFr(line,ERR_DISPLAY);
}
}
}
else InitFrObject(i);
}
SetCursor(hArrowCursor); // Show regular cursor
return TRUE;
}
/*******************************************************************************
FrSaveAs:
Save the text to the output file. As for the file name.
*******************************************************************************/
BOOL FrSaveAs(LPSTR OutFile)
{
BOOL result;
strupr(OutFile);
if (strcmp(FormHdr.name,OutFile)==0) strcpy(FormHdr.name,""); // initialize form name
lstrcpy(msg,OutFile);
if (Win32) result=GetFileName(FALSE,msg,"ReportEase+ Files(*.FPC)|*.FPC|");
else result=GetFileName(FALSE,msg,"ReportEase+ Files(*.FP)|*.FP|");
if (!result) return FALSE;
lstrcpy(OutFile,msg);
strcpy(FormArg.file,OutFile);
return(FrSave(OutFile));
}
/*******************************************************************************
FrSave:
Save the text to the output file or output buffer.
*******************************************************************************/
BOOL FrSave(LPSTR OutFile)
{
int ExistMode=0,len,i,j,result;
HFILE oFile;
char BuFile[129];
LPSTR pImage,pInfo;
OFSTRUCT ofs;
if (strcmp(OutFile,"")==0) { // get file name, if not available
strcpy(msg,OutFile); // pass the previous file name to the dialog box
if (Win32) result=GetFileName(FALSE,msg,"ReportEase+ Files(*.FPC)|*.FPC|");
else result=GetFileName(FALSE,msg,"ReportEase+ Files(*.FP)|*.FP|");
if (!result) return FALSE;
strcpy(OutFile,msg); // retrieve the user provided file name
}
//********** check for a file extension, provide if not given **********
len=strlen(OutFile);
j=0;
for (i=len-1;i>=0;i--,j++) {
if (OutFile[i]=='.') break; // extension already exists
if (j==4 || i==0 || OutFile[i]=='\\') {// last 4 position don't have a period
if (Win32) strcat(OutFile,".FPC");
else strcat(OutFile,".FP");
break;
}
}
if (access(OutFile,ExistMode)==0) { // backup the previous file
strcpy(BuFile,OutFile); // build a backup file name with .TE extension
i=strlen(BuFile)-1;
while(i>=0 && i>=(int)strlen(BuFile)-4 && BuFile[i]!='.' && BuFile[i]!='\\') i--;
if (i>=0 && BuFile[i]=='.') BuFile[i]=0;
strcat(BuFile,".BP");
if (access(BuFile,ExistMode)==0) unlink(BuFile);
rename(OutFile,BuFile);
}
strupr(OutFile);
if (HFILE_ERROR==(oFile=OpenFile(OutFile,&ofs,OF_CREATE|OF_WRITE))) {
MessageBox(hFrWnd,"Error Opening the Output File",NULL,MB_OK);
rename(BuFile,OutFile);
goto WRITE_ERROR;
}
SetCursor(hWaitCursor); // show hour glass while waiting
StrTrim(FormHdr.name);
if (strlen(FormHdr.name)==0) strcpy(FormHdr.name,OutFile); // default report
FormHdr.FieldCount=TotalFields;
FormHdr.BreakFieldCount=TotalBreakFields;
FormHdr.FontCount=TotalFonts;
FormHdr.TotalItems=TotalItems;
FormHdr.FileFormatId=CUR_FILE_FORMAT; // file format id
// WRITE HEADER
if (_lwrite(oFile,(LPCSTR)&FormHdr,sizeof(struct StrFormHdr))!=sizeof(struct StrFormHdr)) {
MessageBox(hFrWnd,"Error writing to output file",NULL,MB_OK);
rename(BuFile,OutFile);
goto WRITE_ERROR;
}
// WRITE TEXT LINES
for(i=0;i<TotalItems;i++) { // read each text line
if (!FrFarWrite(oFile,sizeof(struct StrItem),(char huge *)&(item[i]))) {
MessageBox(hFrWnd,"Error writing to output file!",NULL,MB_OK);
rename(BuFile,OutFile);
goto WRITE_ERROR;
}
}
// WRITE FIELDS
if (!FrFarWrite(oFile,(long)sizeof(struct StrField)*(long)FormHdr.FieldCount,(char huge *)field)
|| !FrFarWrite(oFile,(long)sizeof(struct StrBreakField)*(long)FormHdr.BreakFieldCount,(char huge *)BreakField)
|| !FrFarWrite(oFile,(long)sizeof(struct StrSection)*(long)MAX_SECTIONS,(char huge *)section)
|| !FrFarWrite(oFile,(long)sizeof(struct StrDlgField)*(long)MAX_DLGS,(char huge *)DlgField) ){
MessageBox(hFrWnd,"Error Writing the field information!",NULL,MB_OK);
rename(BuFile,OutFile);
goto WRITE_ERROR;
}
// WRITE FONT TABLE
if (!FrFarWrite(oFile,1,&FontSign)) goto WRITE_ERROR;
for (i=0;i<TotalFonts;i++) { // write each font record
if (!(FrFont[i].InUse)) InitFrObject(i);
if (!FrFarWrite(oFile,sizeof(int),(char huge *)&(FrFont[i].IsPict))) goto WRITE_ERROR;
if (FrFont[i].IsPict) { // save pictures
if (!FrFont[i].InUse) FrFont[i].ImageSize=FrFont[i].InfoSize=0;
//**** write the display dimensions of the picture ******
if (!FrFarWrite(oFile,sizeof(UINT),(char huge *)&(FrFont[i].PictHeight))) goto WRITE_ERROR;
if (!FrFarWrite(oFile,sizeof(UINT),(char huge *)&(FrFont[i].PictWidth))) goto WRITE_ERROR;
//**** write the storage requirement ********************
if (!FrFarWrite(oFile,sizeof(DWORD),(char huge *)&(FrFont[i].ImageSize))) goto WRITE_ERROR;
if (!FrFarWrite(oFile,sizeof(DWORD),(char huge *)&(FrFont[i].InfoSize))) goto WRITE_ERROR;
if (FrFont[i].InfoSize>0) {
//************ lock image and info *********
if ( NULL==(pImage=GlobalLock(FrFont[i].hImage))
|| NULL==(pInfo=GlobalLock(FrFont[i].hInfo)) ) {
MessageBox(hFrWnd,"Ran Out of Memory","File Save Incomplete!",MB_OK);
goto WRITE_ERROR;
}
//********** Read image and info data *******************
if (!FrFarWrite(oFile,FrFont[i].ImageSize,pImage)) goto WRITE_ERROR;
if (!FrFarWrite(oFile,FrFont[i].InfoSize,pInfo)) goto WRITE_ERROR;
GlobalUnlock(FrFont[i].hImage);
GlobalUnlock(FrFont[i].hInfo);
}
}
else { // write the font logical structure
if (!FrFarWrite(oFile,sizeof(LOGFONT),(char huge *)&(FrFont[i].lFont))) goto WRITE_ERROR;
}
}
// END FILE
FrModified=FALSE;
SetWindowText(hFrWnd,OutFile);
WRITE_ERROR:
if (oFile) _lclose(oFile);
SetCursor(hArrowCursor);
return TRUE;
}
/******************************************************************************
GetFileName:
This function gets the file name from the user. The first argument is
TRUE for 'open' dialog box, and FALSE for the 'Save As' dialog box.
The second argument can be used to specify the initial file name and
get the file selection from the user. The third argument (filter) must
be '|' for delimters for wild card pairs.
******************************************************************************/
BOOL GetFileName(BOOL open,LPSTR file,LPSTR filter)
{
int i,len,result;
OPENFILENAME ofn;
MSG msg;
// preprare to get the bitmap file name from the user
FarMemSet(&ofn,0,sizeof(OPENFILENAME)); // initialize
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.hwndOwner=hFrWnd;
len=lstrlen(filter);
for (i=0;i<len;i++) if (filter[i]=='|') filter[i]=0;
ofn.lpstrFilter=filter;
if (len) ofn.nFilterIndex=1;
else ofn.nFilterIndex=0;
ofn.lpstrFile=file;
ofn.nMaxFile=128;
ofn.Flags=OFN_SHOWHELP|OFN_HIDEREADONLY|OFN_NOCHANGEDIR;
// get the file name from the user
if (open) result=GetOpenFileName(&ofn);
else result=GetSaveFileName(&ofn);
// discard any mouse messages left from the above call
while (PeekMessage(&msg,hFrWnd,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE|PM_NOYIELD));;
return result;
}
/******************************************************************************
FrFarRead:
This routine reads a specified number of bytes(long) from the input
file. A far pointer to the receiving buffer and the input stream
is given by the arguments.
The routine returns a TRUE or FALSE result.
*******************************************************************************/
FrFarRead(HFILE iFile,long len,char huge *OutBuf)
{
DWORD OutPos;
int TempBufLen=LINE_WIDTH,ReadLen;
char temp[LINE_WIDTH+2];
OutPos=0;
while (len>0) {
ReadLen=TempBufLen;
if ((long)ReadLen>len) ReadLen=(int)len;
len=len-ReadLen;
if (_lread(iFile,temp,ReadLen)!=(UINT)ReadLen) return FALSE;
HugeMove(temp,&OutBuf[OutPos],ReadLen);
OutPos=OutPos+ReadLen;
}
return TRUE;
}
/******************************************************************************
FrFarWrite:
This routine writes a specified number of bytes(long) to the output.
A far pointer to the input buffer and the output file stream is
specified by the arguments.
The routine returns a TRUE or FALSE result.
*******************************************************************************/
FrFarWrite(HFILE oFile,long len,char huge *InBuf)
{
DWORD InPos;
int TempBufLen=LINE_WIDTH,WriteLen;
char temp[LINE_WIDTH+2];
InPos=0;
while (len>0) {
WriteLen=TempBufLen;
if ((long)WriteLen>len) WriteLen=(int)len;
len=len-WriteLen;
HugeMove(&InBuf[InPos],temp,WriteLen);
if (_lwrite(oFile,temp,WriteLen)!=(UINT)WriteLen) return FALSE;
InPos=InPos+WriteLen;
}
return TRUE;
}
/******************************************************************************
FrRepParameters:
This routine allows the user to specify the report parameters such
as page margins, date format, etc.
******************************************************************************/
FrRepParameters()
{
int i;
if (CallDialogBox("RepParam",RepParam,0L)) {
// recalculate drawing sizes
ProcessPrinterData(); // apply new margins
// recalculate the detail section width
for (i=0;i<TotalItems;i++) if (item[i].type==SECTION && item[i].section==SEC_DETAIL1) break;
if (i<TotalItems) item[i].width=(FrWidth-(int)(UNITS_PER_INCH*(FormHdr.LeftMargin+FormHdr.RightMargin)))/section[SEC_DETAIL1].columns;
// recalculate window zone sizes
GetWinDimension(); // get window dimensions
PaintFlag=PAINT_WIN; // paint the entire window
FrPaint();
}
return TRUE;
}
/******************************************************************************
FrPrintOptions:
This routine printer specific options.
******************************************************************************/
FrPrintOptions()
{
int i;
// select a printer
CallDialogBox("PrinterParam",PrinterParam,0);
// recalculate drawing sizes
ProcessPrinterData(); // apply new margins
// recalculate the detail section width
for (i=0;i<TotalItems;i++) if (item[i].type==SECTION && item[i].section==SEC_DETAIL1) break;
if (i<TotalItems) item[i].width=(FrWidth-(int)(UNITS_PER_INCH*(FormHdr.LeftMargin+FormHdr.RightMargin)))/section[SEC_DETAIL1].columns;
FrModified=TRUE;
FrPaint();
return TRUE;
}
/******************************************************************************
FrRepFilter:
Accept the record selection criteria for the report.
******************************************************************************/
FrRepFilter()
{
int NewExp[NAME_WIDTH+2];
int i;
if (ModifyExp(FormHdr.SelExp,NewExp,"Record Selection Criteria",EXP_PARM)!=-1) {
i=0;
while(NewExp[i]!=END_OF_EXP) {
FormHdr.SelExp[i]=NewExp[i];
i++;
}
FormHdr.SelExp[i]=NewExp[i];
FrModified=TRUE;
}
return TRUE;
}
/******************************************************************************
CallPrinterDriver:
Call the vendor's printer driver for the current printer.
*******************************************************************************/
BOOL CallPrinterDriver(WORD mode)
{
HANDLE hDriver;
#if defined (WIN32)
if (OpenPrinter(PrinterName,&hDriver,NULL)) {
if (!DocumentProperties(hFrWnd,hDriver,PrinterName,pDevMode,pDevMode,mode)) {
MessageBox(hFrWnd,"Error Initializing the printer(CallPrinterDriver)",NULL,MB_OK);
}
ClosePrinter(hDriver);
return TRUE;
}
#endif
if (NULL!=(hDriver=LoadLibrary(PrinterDriver))) {
int (WINAPI _export *fpDeviceMode)(HWND,HANDLE,DEVMODE FAR *,LPSTR,LPSTR,DEVMODE FAR *,LPSTR,WORD);
fpDeviceMode=(void far *)GetProcAddress(hDriver,"ExtDeviceMode"); // if available, get the address of ExtDeviceMode function in the library
if (fpDeviceMode!=NULL) { // ExtDeviceMode function is supported by the driver
if ((*fpDeviceMode)(hFrWnd,hDriver,pDevMode,(LPSTR)PrinterName,(LPSTR)PrinterPort,pDevMode,(LPSTR)NULL,mode)<0) {
MessageBox(hFrWnd,"Error Initializing the Printer Options","Printer Error",MB_OK);
}
}
FreeLibrary(hDriver); // unload the driver from the memory
}
return TRUE;
}
/******************************************************************************
GetPrinterList:
This function returns a far pointer to the long string containing the
printer names from the win.ini file. The calling routine should
free the space for the printer list using the OurFree function. The argument
returns the number of printers in the list.
*******************************************************************************/
LPSTR GetPrinterList(int far *count)
{
int BufSize=1500,StringSize,CurSize,len;
LPSTR string;
if (NULL==(string=OurAlloc(BufSize))) return NULL;
StringSize=GetProfileString("devices",NULL,"",string,BufSize);
CurSize=0;
(*count)=0;
while(CurSize<StringSize) {
(*count)++;
len=lstrlen(&string[CurSize]);
CurSize=CurSize+len+1;
}
return string;
}
/******************************************************************************
HugeMove:
Use this function to move data from one buffer to another when the
buffer may be larger than 64K. This function handles overlapping
buffers.
Small/Medium Model Note: This function will not work if compiled
as an EXECUTABLE under small/medium model using the Borland compiler.
This is because Borland 'C' does not have a fmemmove library function.
Note that this restriction is only for an executable and not for a DLL.
*******************************************************************************/
void HugeMove(void huge *src,void huge * dest, long count)
{
#if defined(WIN32)
memmove(dest,src,count);
#else
long BuffSize=0x1000; // 4 K
long BytesMoved=0;
long MoveSize;
void far *CurSrc,far *CurDest;
char huge *CharSrc; // source cast as character pointer
char huge *CharDest; // destination cast as character pointer
if (count<=0 || src==dest) return;
if (count<=0xFFFFL) { // less than 64 K
FarMoveOl(src,dest,(WORD)count);
return;
}
// move in 64K blocks now
CharSrc=(char huge *)src;
CharDest=(char huge *)dest;
while (count>0) {
// calculate amount to move
if (count>=BuffSize) MoveSize=BuffSize;
else MoveSize=count;
// calculate source and destination addresses
if (src>dest) { // move from the top
CurSrc=(void far *)&CharSrc[BytesMoved];
CurDest=(void far *)&CharDest[BytesMoved];
}
else { // move from the bottom to handle overlapping block
CurSrc=(void far *)&CharSrc[count-MoveSize];
CurDest=(void far *)&CharDest[count-MoveSize];
}
// move this block
FarMoveOl(CurSrc,CurDest,(WORD)MoveSize);
count-=MoveSize; // bytes left to move
BytesMoved+=MoveSize;
}
#endif
return;
}