Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print on Usb0001

Status
Not open for further replies.

gae75

Programmer
Sep 4, 2002
2
0
0
IT
Hello
My problem is.
I can't to print with this program on my USB printer
This is my code:

#include <stdio.h>
void main ()
{
fprintf(stdprn,&quot;\n\n PROVA DI STAMPA \n\n&quot;);
}

In this way i can print on Lpt1 printer:

#include <stdio.h>
void main void()
{
FILE * fp;

fp=fopen(“Lpt1”,”w”);
if(fp==NULL)
{
printf(“ERROR \n”);
}
fprintf(fp,”HELLO\n”);
fclose(fp);
}

what can i do?
many thanks

 
Hi.

You are using console functions to try to access the printer. If you have a USB printer (and I assume you are using windows) it would be easier to use the 'PrintDlg' function, a Windows function which will display the default print dialog box. An example code is below. Any problems, just post them. :) Adonai
Code:
#include <windows.h>

PRINTDLG pd;
MSG msg;
char *text = &quot;Hello, Printer !&quot;;

int WINAPI WinMain (HINSTANCE hInst,
                    HINSTANCE hPrev,
                    LPSTR szCmd,
                    int nShow)
{
  memset(&pd, 0,sizeof(PRINTDLG));
  pd.lStructSize = sizeof(PRINTDLG);
  pd.Flags = PD_RETURNDC;
  if (PrintDlg(&pd) != 0)
  {
    Escape(pd.hDC, STARTDOC, 10, &quot;Print Test&quot;, 0);
    TextOut(pd.hDC, 100, 100, text, strlen(text));
    Escape(pd.hDC, ENDDOC, 0, 0, 0);
  }
  return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top