在前面的文章
《
Barcode Xpress使用教程:如何在Visual C++中做爲COM對象使用(1)》中已經對在Visual C++中如何將
Barcode Xpress做爲一個導入的COM 對象使用的步驟作了一些講解,下面將繼續上文。
3、初始化COM html
在COM函數能夠被調用以前,這個必須先初始化COM庫,而且在程序退出以前必須關閉。在ReadBarcodeFromDIB.cpp文件中像下面這樣說明: app
- // CReadBarcodeFromDIBApp initialization
- BOOL CReadBarcodeFromDIBApp::InitInstance()
- {
- // Initialize the COM library on the current apartment and identify
- // the currency model as single-thread apartment (STA). Applications
- // must initialize the COM
- // library before they can call COM library functions other than
- // CoGetMalloc and memory allocation functions.
- HRESULT hRes = CoInitialize(NULL);
- AfxEnableControlContainer();
-
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
-
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
>>>
完整代碼
4、建立BarcodeXpress COM對象 ide
要使用BarcodeXpress,須要建立一個BarcodeXpress COM實例。在對象被建立以後,對象的屬性和方法能夠用於建立你的掃描應用程序。在ReadBarcodeFromDIB項目中,這個COM對象在 ReadBarcodeFromDIBDlg.cpp文件中以下建立: 函數
- // CReadBarcodeFromDIBDlg message handlers
- BOOL CReadBarcodeFromDIBDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
- CWnd* pControl = NULL;
- pControl = GetDlgItem(Description);
- if (pControl)
- {
- pControl->SetWindowText(lpctstrDescription);
- }
>>>完整代碼 this
>>>Barcode Xpress 下載 spa