Subj : problem including a logo in a print program To : borland.public.cpp.borlandcpp From : Morosh Date : Mon May 02 2005 11:04 am Hello: 1- I'm trying to make a command line print program using borland v5.02, and I like to include a logo at the header of each page, (I like the logo.bmp to be merged in the ..exe file)the compilation is OK, when I launch the program I have "abnormal program termination". the program is: **************************************************************************** #include #include #include #include #include #define SCALE 2.25 #define DEBUG FILE *fpp; #ifdef DEBUG #define fdebug(msg) fputs(msg,fpp);fflush(fpp); #else #define fdebug(msg) #endif #define margx 200 #define margy 200 FILE *fp; TPrinter Printer1; TFont Pol1("Arial", 100); TFont Pol2("Arial", 150); TFont Pol3("Arial", 200); TFont Pol4("Arial", 260,0,0,0,FW_BOLD); TFont Pol5("Arial", 400,0,0,0,FW_BOLD); TFont Pol[5]={Pol1,Pol2,Pol3,Pol4,Pol5}; TPen stylo1(TColor::Black,2); TPen stylo2(TColor::Black,4); TPen stylo3(TColor::Black,7); TPen stylo4(TColor::Black,2,PS_DOT); TPen stylo[4]={stylo1,stylo2,stylo3,stylo4}; TBrush brosse1(TColor::White); TBrush brosse2(TColor::Black,HS_BDIAGONAL); TBrush brosse3(TColor::Gray); TBrush brosse[3]={brosse1,brosse2,brosse3}; /*TDib dib("logo.bmp");*/ TDib dib("image"); TRect src(0,0,dib.Width(),dib.Height()), dst(margx,margy,(dib.Width())*SCALE, (dib.Height())*SCALE*1.25); class TApp : public TApplication { void InitMainWindow(); public: TApp(char *nom=0) : TApplication(nom) {} }; TApp Apli1; class TImpression : public TPrintout // classe relative au document // à imprimer { void PrintPage(int page, TRect& rect, unsigned flags); bool HasPage(int); public: TImpression(const char* title) : TPrintout(title) {} }; bool TImpression::HasPage(int page) { if (page <= 1) return true; else return false; } void TImpression::PrintPage(int page, TRect&, unsigned) { fdebug("printPage in\n"); char dumy[100],dumy1[100],str1[100],str2[100]; int x,y,x1,y1,no_font,wid,no_fill; GetPrintDC()->StretchDIBits(dst,src,dib); GetPrintDC()->SelectObject(Pol[1]); while(!feof(fp)) { fgets(dumy,100,fp); sscanf(dumy,"%s",str1); if(!strcmp(str1,"set_font")) { sscanf(dumy,"%s %i",str1,&no_font); GetPrintDC()->SelectObject(Pol[no_font-1]); } if(!strcmp(str1,"print")) { sscanf(dumy,"%s %i %i ",str1,&x,&y); sprintf(dumy1,"print %i %i ",x,y); strcpy(str2,dumy+strlen(dumy1)); str2[strlen(str2)-1]=0; GetPrintDC()->TextOut(margx+x,margy+y,str2); } if(!strcmp(str1,"set_width")) { sscanf(dumy,"%s %i",str1,&wid); GetPrintDC()->SelectObject(stylo[wid-1]); } if(!strcmp(str1,"line")) { sscanf(dumy,"%s %i %i %i %i",str1,&x,&y,&x1,&y1); GetPrintDC()->MoveTo(margx+x,margy+y); GetPrintDC()->LineTo(margx+x1,margy+y1); } if(!strcmp(str1,"set_fill")) { sscanf(dumy,"%s %i",str1,&no_fill); GetPrintDC()->SelectObject(brosse[no_fill-1]); } if(!strcmp(str1,"rect")) { sscanf(dumy,"%s %i %i %i %i",str1,&x,&y,&x1,&y1); GetPrintDC()->SetBkMode(TRANSPARENT); GetPrintDC()->Rectangle(margx+x,margy+y,margx+x1,margy+y1); } if(!strcmp(str1,"set_align_left")) GetPrintDC()->SetTextAlign(TA_LEFT); if(!strcmp(str1,"set_align_right")) GetPrintDC()->SetTextAlign(TA_RIGHT); } } class TFenApp : public TWindow { public: TFenApp(); }; TFenApp::TFenApp() : TWindow(0, 0, 0) { fdebug("TFenApp in\n"); static bool prompt = false; // laisser le choix de l'imprimante TImpression Imp("Impression"); Printer1.Print(this, Imp, prompt); } void TApp::InitMainWindow() { fdebug("InitMainWindow in\n"); MainWindow = new TFrameWindow(0, "Impressions", new TFenApp); fdebug("InitMainWindow out\n"); exit(1); } int OwlMain(int argc, char *argv[]) { fpp=fopen("fdebug.txt","w"); if((fp=fopen(argv[1],"r"))==NULL) { exit(1); } fdebug("owlmain in\n"); return Apli1.Run(); fclose(fpp); } **************************************************************************** the ressource file is: **************************************************************************** #include #include #include image BITMAP logo.bmp **************************************************************************** the generated make file **************************************************************************** # # Borland C++ IDE generated makefile # Generated 05/02/05 at 09:43:41 AM # ..AUTODEPEND # # Borland C++ tools # IMPLIB = Implib BCC32 = Bcc32 +BccW32.cfg BCC32I = Bcc32i +BccW32.cfg TLINK32 = TLink32 ILINK32 = Ilink32 TLIB = TLib BRC32 = Brc32 TASM32 = Tasm32 # # IDE macros # # # Options # IDE_LinkFLAGS32 = -LC:\compiler\BC5\LIB IDE_ResFLAGS32 = LinkerLocalOptsAtW32_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = -v -Tpe -aa -V4.0 -c ResLocalOptsAtW32_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = BLocalOptsAtW32_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = CompInheritOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = -IC:\compiler\BC5\INCLUDE -DSTRICT;_OWLPCH; LinkerInheritOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = -x LinkerOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = $(LinkerLocalOptsAtW32_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) ResOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = $(ResLocalOptsAtW32_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) BOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = $(BLocalOptsAtW32_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) # # Dependency List # Dep_pprint = \ E:\MY_DATA\PROG\CPP\EXE\pprint.exe pprint : BccW32.cfg $(Dep_pprint) echo MakeNode Dep_EcbMY_DATAbPROGbCPPbEXEbpprintdexe = \ E:\MY_DATA\PROG\CPP\INTERMEDIATE\pprint.res\ E:\MY_DATA\PROG\CPP\INTERMEDIATE\pprint.obj E:\MY_DATA\PROG\CPP\EXE\pprint.exe : $(Dep_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) $(ILINK32) @&&| /v $(IDE_LinkFLAGS32) $(LinkerOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) $(LinkerInheritOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) + C:\compiler\BC5\LIB\c0w32.obj+ E:\MY_DATA\PROG\CPP\INTERMEDIATE\pprint.obj $<,$* C:\compiler\BC5\LIB\owlwf.lib+ C:\compiler\BC5\LIB\bidsf.lib+ C:\compiler\BC5\LIB\import32.lib+ C:\compiler\BC5\LIB\cw32.lib E:\MY_DATA\PROG\CPP\INTERMEDIATE\pprint.res | E:\MY_DATA\PROG\CPP\INTERMEDIATE\pprint.res : ..\src\pprint.rc $(BRC32) -R @&&| $(IDE_ResFLAGS32) $(ROptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) $(CompInheritOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) -FO$@ ...\src\pprint.rc | E:\MY_DATA\PROG\CPP\INTERMEDIATE\printer.res : C:\compiler\BC5\INCLUDE\owl\printer.rc $(BRC32) -R @&&| $(IDE_ResFLAGS32) $(ROptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) $(CompInheritOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) -FO$@ C:\compiler\BC5\INCLUDE\owl\printer.rc | E:\MY_DATA\PROG\CPP\INTERMEDIATE\except.res : C:\compiler\BC5\INCLUDE\owl\except.rc $(BRC32) -R @&&| $(IDE_ResFLAGS32) $(ROptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) $(CompInheritOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) -FO$@ C:\compiler\BC5\INCLUDE\owl\except.rc | E:\MY_DATA\PROG\CPP\INTERMEDIATE\pprint.obj : ..\src\pprint.cpp $(BCC32) -c @&&| $(CompOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) $(CompInheritOptsAt_EcbMY_DATAbPROGbCPPbEXEbpprintdexe) -o$@ ...\src\pprint.cpp | # Compiler configuration file BccW32.cfg : Copy &&| -w -R -v -WM- -vi -H -H=pprint1.csm -H=PPRINT.CSM -v -R -5 -He -N -W -H"owl\pch.h" | $@ **************************************************************************** 2- while testing, I've put momentarily the line 43 in comments and uncommented line42, so they became: TDib dib("logo.bmp"); /* TDib dib("image");*/ (run is OK, but the image is external and not merged in the .exe file) compilation is OK, but if in target expert I choose "static" instead of "dynamic", run is OK but I have a error message: "this program has performed an illegal operation and will be shut down". In Details, I have: PPRINT caused an invalid page fault in module at 00e7:006f00b1. Registers: EAX=00402850 CS=0187 EIP=006f00b1 EFLGS=00010246 EBX=006f306d SS=018f ESP=006dfc4c EBP=006dfc54 ECX=0043052a DS=018f ESI=006dfcb0 FS=51af EDX=006f00a8 ES=018f EDI=00000000 GS=0000 Bytes at CS:EIP: 28 6f 00 b0 00 6f 00 b0 00 6f 00 80 29 6f 00 80 Stack dump: 006f285c 0043052a 006dfca8 0040c442 004305a4 0043052a 00000000 00400000 00401bfd 006dfcb8 0041c62c 0042a8e8 006dfc64 00000044 00410000 004287a1 Although I can print normally. Can anyone help? (I really prefer the static mode and the picture merged with exe file). thanks in advance Maurice SAAB .