Barcode Xpress如何在Visual C++中作为COM对象使用(2)

  在前面的文章 Barcode Xpress使用教程:如何在Visual C++中作为COM对象使用(1)》中已经对在Visual C++中如何将 Barcode Xpress作为一个导入的COM 对象使用的步骤做了一些讲解,下面将继续上文。

    三、初始化COM

    在COM函数可以被调用之前,这个必须先初始化COM库,并且在程序退出之前必须关闭。在ReadBarcodeFromDIB.cpp文件中像下面这样说明:

  1. // CReadBarcodeFromDIBApp initialization  
  2. BOOL CReadBarcodeFromDIBApp::InitInstance()  
  3. {  
  4. // Initialize the COM library on the current apartment and identify  
  5. // the currency model as single-thread apartment (STA). Applications  
  6. // must initialize the COM  
  7. // library before they can call COM library functions other than  
  8. // CoGetMalloc and memory allocation functions.  
  9. HRESULT hRes = CoInitialize(NULL);  
  10. AfxEnableControlContainer();  
  11.     
  12. // Standard initialization  
  13. // If you are not using these features and wish to reduce the size  
  14. // of your final executable, you should remove from the following  
  15. // the specific initialization routines you do not need.  
  16.     
  17. #ifdef _AFXDLL  
  18. Enable3dControls(); // Call this when using MFC in a shared DLL  
  19. #else  
  20. Enable3dControlsStatic(); // Call this when linking to MFC statically  
  21. #endif  

>>> 完整代码

四、创建BarcodeXpress COM对象

    要使用BarcodeXpress,需要创建一个BarcodeXpress COM实例。在对象被创建之后,对象的属性和方法可以用于创建你的扫描应用程序。在ReadBarcodeFromDIB项目中,这个COM对象在 ReadBarcodeFromDIBDlg.cpp文件中如下创建:

  1. // CReadBarcodeFromDIBDlg message handlers  
  2. BOOL CReadBarcodeFromDIBDlg::OnInitDialog()  
  3. {  
  4. CDialog::OnInitDialog();  
  5.     
  6. // Set the icon for this dialog. The framework does this automatically  
  7. // when the application's main window is not a dialog  
  8. SetIcon(m_hIcon, TRUE); // Set big icon  
  9. SetIcon(m_hIcon, FALSE); // Set small icon  
  10.     
  11. // TODO: Add extra initialization here  
  12. CWnd* pControl = NULL;  
  13. pControl = GetDlgItem(Description);  
  14. if (pControl)  
  15. {  
  16. pControl->SetWindowText(lpctstrDescription);  
  17. }  

>>>完整代码

>>>Barcode Xpress 下载

转载于:https://my.oschina.net/u/913380/blog/164025

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值