// Copyright 2005 Doi Shigeki // list050a.cpp USB-プリンタ・ケーブルを使った外部制御1 // #include #include main() { HANDLE h; if( ! OpenPrinter("NEC PC-PR101", // シンプルなプリンタを仮に指定 &h, // ハンドル NULL ) ){ // 単純出力の場合はNULL printf("open err\n"); return; } DOC_INFO_1 docinfo; DWORD dwjob; // ジョブの開始 docinfo.pDocName = "My Document"; // ドキュメント名,何でもよい docinfo.pOutputFile = NULL; // ファイルは使用しないのでNULL docinfo.pDatatype = "RAW"; // そのまま出力 dwjob = StartDocPrinter( h, 1, (LPBYTE)&docinfo); if (dwjob == 0) { printf("start err\n"); ClosePrinter( h ); return; } // ページの開始 if ( ! StartPagePrinter( h )) { printf("page err\n"); EndDocPrinter( h ); ClosePrinter( h ); return; } DWORD n; // 出力されたバイト数 // 指定されたプリンタにデータを書き込むよう印刷スプーラに通知 if( ! WritePrinter( h, "0123456789", 10, &n )){ printf("write err \n"); } EndPagePrinter( h ); EndDocPrinter( h ); ClosePrinter( h ); }