我是利用一个已有的程序来开发,开发了一半才发现不能同时连两台打印机当一台打印机时的程序主要代码如下:CCoPtr m_Ptr1;//CCoPtr为POSPrinter ActiveX Control 对应加入的类//Dlg.cpp中
void CPrinterDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPrinterDlg)
DDX_Control(pDX, IDC_EDIT_RETRIEVST, m_edtRetrieveSt);
DDX_CBIndex(pDX, IDC_CMB_COUNTER, m_Counter);
DDX_Control(pDX, IDC_POSPRINTER1, m_Ptr1);//这儿不太懂
//}}AFX_DATA_MAP
}
BOOL *::OnInition()
{
BOOL bError = FALSE;
while( 1 ) {
//Open the device
//Use a Logical Device Name which has been set on the SetupPOS.
m_Ptr1.Open("Unit1");
//Check whether the device is succeed to open, or not
if( m_Ptr1.GetResultCode() != OPOS_SUCCESS ) {
MessageBox("device has not been registered,orcannotuse.");
bError = TRUE;
break;
}        //Get the exclusive control right for the opened device.
        //Then the device is disable from other application.
        //(Notice:When using an old CO, use the Claim.)
m_Ptr1.ClaimDevice( 1000 );
        if( m_Ptr1.GetResultCode() != OPOS_SUCCESS ) {
            MessageBox("Fails to get the exclusive right for the device.");
bError = TRUE;
break;
        }
..........
..........
当第二次调用这个方法来初始化打印机的时候出错MessageBox("device has not been registered,orcannotuse.");,看来是m_Ptr1变量已经使用(加入的第一台打印机)。请问如何加入再加入一个新的类似CCoPtr m_Ptr1;的变量来控制第二台打印机,或者仍然使用这个变量怎么控制?不会是一个POSPrinter ActiveX Control ,只能支持一台打印机吧?

解决方案 »

  1.   

    m_Ptr1.Open("Unit1")中Unit1为打印机名
      

  2.   

    1.在声明时用指针。在初始化时,分别new出两个对象来。(记住在退出时清除)
    2.如果以上方法不行,说明这个驱动的调用是独占式的,你你就放弃吧。
      

  3.   

    是不是一个外设的ActiveX Control只能对应一个外设???具体的打印程序完全是用m_Ptr1.*(方法名)来控制的