Работа с памятью принтера.
От: maks_bander  
Дата: 26.10.05 08:44
Оценка:
Необходимо просто посылать данные в память принтера и читать из неё. Печать не должна производиться. Принтер usb, но может быть и по-другому подсоединён. ОС вин хр.
Re: Работа с памятью принтера.
От: maks_bander  
Дата: 31.10.05 21:15
Оценка:
Перефразирую
Народ, подскажите, пожалуйста: как отправить поток байтов на произвольный принтер? (пусть для определённости USB)
Re[2]: Работа с памятью принтера.
От: Patalog Россия  
Дата: 01.11.05 12:08
Оценка:
Здравствуйте, maks_bander, Вы писали:

[]

_>Народ, подскажите, пожалуйста: как отправить поток байтов на произвольный принтер? (пусть для определённости USB)


Если

ОС вин хр

см. WritePrinter и Ко.
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Почетный кавалер ордена Совка.
Re[3]: Работа с памятью принтера.
От: maks_bander  
Дата: 13.11.05 12:00
Оценка:
Здравствуйте, Patalog, Вы писали:

P>Здравствуйте, maks_bander, Вы писали:


P>[]


_>>Народ, подскажите, пожалуйста: как отправить поток байтов на произвольный принтер? (пусть для определённости USB)


P>Если

P>

ОС вин хр

P>см. WritePrinter и Ко.

Я пробовал как раз эти функции. Система ругается и кричит: "Неверный уровень системного вызова" (код 124)
Re[4]: Работа с памятью принтера.
От: Patalog Россия  
Дата: 14.11.05 07:12
Оценка:
Здравствуйте, maks_bander, Вы писали:

[]

_>Я пробовал как раз эти функции. Система ругается и кричит: "Неверный уровень системного вызова" (код 124)


Ты не умеешь их готовить. Код покажи.
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Почетный кавалер ордена Совка.
Re[5]: Работа с памятью принтера.
От: maks_bander  
Дата: 16.11.05 19:28
Оценка:
Здравствуйте, Patalog, Вы писали:

P>Здравствуйте, maks_bander, Вы писали:


P>[]


_>>Я пробовал как раз эти функции. Система ругается и кричит: "Неверный уровень системного вызова" (код 124)


P>Ты не умеешь их готовить. Код покажи.


Код вот

just FYI — есть специальный таг ccode, которым можно обрамлять куски кода дабы не портить отступы и получить подсветку — модератор

#include <afxwin.h>
#include <winspool.h>

#define IDC_MYBUTTON 100
#define IDC_MYEDIT 102

class CTestButton : public CButton
{
public:
    CTestButton();
    ~CTestButton();
    afx_msg void OnLButtonDblClk(UINT, CPoint);
    afx_msg void OnRButtonDblClk(UINT, CPoint);
    afx_msg void OnLButtonUp(UINT, CPoint);
    CHAR szBuf[80]; 
private:
    DECLARE_MESSAGE_MAP();
};

CTestButton::CTestButton()
{

}

CTestButton::~CTestButton()
{

}


void CTestButton::OnLButtonUp(UINT, CPoint)
{
   CString strStringItem;
   char strIntItem[20];
   DWORD NameLenght=30, Writed, bytesToWrite=32;
   CHAR strPrinter[30];
   HANDLE prHandle;
   CHAR WriteBuf[]="test text";
         
   GetDefaultPrinter(strPrinter, &NameLenght);
   OpenPrinter(strPrinter, &prHandle, NULL);
   //AfxMessageBox(strPrinter);
   //PrinterProperties(m_hWnd,prHandle);
   StartDocPrinter(prHandle,2,NULL);
   StartPagePrinter(prHandle);
   WritePrinter(prHandle, (VOID*)WriteBuf, bytesToWrite, &Writed);
   strStringItem="writed ";
   strStringItem+=itoa(Writed,strIntItem,10);
   AfxMessageBox(strStringItem);
   DWORD dw = GetLastError(); 
   strStringItem=itoa(dw,strIntItem,10);
   MessageBox(strStringItem, "Error", MB_OK); 
   
   FlushPrinter(prHandle, (VOID*)WriteBuf, 16, &Writed, 1);
   strStringItem="flushed ";
   strStringItem+=itoa(Writed,strIntItem,10);
   AfxMessageBox(strStringItem);
   EndPagePrinter(prHandle);
   EndDocPrinter(prHandle);


   ClosePrinter(prHandle);
}

BEGIN_MESSAGE_MAP(CTestButton, CButton) // таблица откликов на сообщения
    ON_WM_LBUTTONUP()
END_MESSAGE_MAP()


class CPrintButton : public CButton
{
public:
    CPrintButton();
    ~CPrintButton();
    afx_msg void OnLButtonDblClk(UINT, CPoint);
    afx_msg void OnRButtonDblClk(UINT, CPoint);
    afx_msg void OnLButtonUp(UINT, CPoint);
    CHAR szBuf[80]; 
private:
    DECLARE_MESSAGE_MAP();
};

CPrintButton::CPrintButton()
{
    //CreateDC;
}

CPrintButton::~CPrintButton()
{

}


void CPrintButton::OnLButtonUp(UINT, CPoint)
{
   CString strStringItem;
   char strIntItem[20];
   DWORD NameLenght=30, Writed, bytesToWrite=32,dw;
   CHAR strPrinter[30];
   HANDLE prHandle;
   CHAR WriteBuf[]="test text";
   LPVOID lpMsgBuf;
   GetDefaultPrinter(strPrinter, &NameLenght);
   OpenPrinter(strPrinter, &prHandle, NULL);
if (!FormatMessage( 
    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    FORMAT_MESSAGE_FROM_SYSTEM | 
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,
    0,
    NULL ))
{
   // Handle the error.
   return;
}

// Process any inserts in lpMsgBuf.
// ...

// Display the string.
MessageBox( (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );

// Free the buffer.
LocalFree( lpMsgBuf );


   //dw = GetLastError(); 
   //strStringItem=itoa(dw,strIntItem,10);
   //strStringItem="open printer "+strStringItem;
   //MessageBox(strStringItem, "Error", MB_OK); 
   //AfxMessageBox(strPrinter);
   //PrinterProperties(m_hWnd,prHandle);
   StartDocPrinter(prHandle,2,NULL);
   
if (!FormatMessage( 
    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    FORMAT_MESSAGE_FROM_SYSTEM | 
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,
    0,
    NULL ))
{
   // Handle the error.
   return;
}

// Process any inserts in lpMsgBuf.
// ...

// Display the string.
MessageBox( (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );

// Free the buffer.
LocalFree( lpMsgBuf );

   //dw = GetLastError(); 
   //strStringItem=itoa(dw,strIntItem,10);
   //strStringItem="start doc "+strStringItem;
   //MessageBox(strStringItem, "Error", MB_OK); 
   //strStringItem=itoa(prHandle,strIntItem,10);
   //AfxMessageBox(strIntItem);
   StartPagePrinter(prHandle);
   dw = GetLastError(); 
   strStringItem=itoa(dw,strIntItem,10);
   MessageBox(strStringItem, "Error", MB_OK); 
   //WritePrinter(prHandle, (VOID*)WriteBuf, bytesToWrite, &Writed);
   //strStringItem=itoa(Writed,strIntItem,10);
   //AfxMessageBox(strIntItem);
   //strStringItem="writed ";
   //strStringItem+=itoa(Writed,strIntItem,10);
   //AfxMessageBox(strStringItem);

   dw = GetLastError(); 
   strStringItem=itoa(dw,strIntItem,10);
   MessageBox(strStringItem, "Error", MB_OK); 
   
   FlushPrinter(prHandle, (VOID*)WriteBuf, 16, &Writed, 1);
   strStringItem="flushed ";
   strStringItem+=itoa(Writed,strIntItem,10);
   AfxMessageBox(strStringItem);
   EndPagePrinter(prHandle);
   EndDocPrinter(prHandle);
   ClosePrinter(prHandle);
    
}

BEGIN_MESSAGE_MAP(CPrintButton, CButton) // таблица откликов на сообщения
    ON_WM_LBUTTONUP()
    //ON_WM_RBUTTONDBLCLK()
END_MESSAGE_MAP()


//class CMyPrinter : public win32_printer
//{
//};
class CMainWnd : public CFrameWnd
{
public:
    CMainWnd();
    ~CMainWnd();
    //void error(LPSTR lpszFunction);
private:
    CEdit* MyEdit;
    CStatic* MyStatic;
    CTestButton* TestButton;
    CPrintButton* PrintButton;
};

CMainWnd::CMainWnd()
{
Create(NULL, "test_printer_api", WS_OVERLAPPEDWINDOW, rectDefault, NULL, NULL);
MyStatic=new CStatic();
if(MyStatic)
    MyStatic->Create("MyStatic", WS_CHILD | WS_VISIBLE | SS_CENTER,    CRect(10,10,200,150), this);
MyEdit=new CEdit();
if(MyEdit)
    MyEdit->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(220, 10, 420, 150), this, IDC_MYEDIT);
TestButton=new CTestButton();
if(TestButton)
    TestButton->Create("Test", WS_CHILD | WS_VISIBLE | SS_CENTER,
    CRect(440, 10, 580, 50),this, IDC_MYBUTTON);
PrintButton=new CPrintButton();
if(PrintButton)
    PrintButton->Create("Print", WS_CHILD | WS_VISIBLE | SS_CENTER,
    CRect(440,110,580,150),this, IDC_MYBUTTON);
}

CMainWnd::~CMainWnd()
{
    if(MyStatic) delete MyStatic;
    if(TestButton) delete TestButton;
//    if(PrintButton) delete PrintButton;
    if(MyEdit) delete MyEdit;
}

class CMyApp : public CWinApp
{
public:
    CMyApp();
    virtual BOOL InitInstance();
};

CMyApp::CMyApp()
{
}

BOOL CMyApp::InitInstance()
{
    m_pMainWnd=new CMainWnd();
    ASSERT(m_pMainWnd);
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
    return TRUE;
}

CMyApp theApp;


З.Ы. пишу на работе, а инет дома — поэтому отвечаю на почту с такими затупами

З.З.Ы. Дело в том, что мне надо, чтобы в момент передачи данных не было печати страниц. Т.Е. писать надо просто в устройство. ГЛАВНОЕ, чтобы по усб кабелю шло 01010101010...... вот, собственно, в чём задача. Для этого, я так понял, надо использовать порт-монитор для принтера. Так ддк говорит, вроде. Разобраться с написанием дров трудновато((( Я человек в винде новый.
А может есть возможность писать прямо в усб устройство из прикладной программы? Ка тогда определить, к какому порту подключён случайный принтер?
Короче, будут теститься принтеры (разные, усб и нет). По кабелю надо гнать 010101. Наконец-то объяснил ))) Извини за путаницу в высказываниях
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.