使用visual C ++ 2008解决/调试未处理的异常错误?

时间:2015-08-24 09:06:54

标签: c++ visual-c++ dll mfc

我做了一个dll,最终需要在Window中有一些activeX(在这种情况下是来自第三方的activeX控制器)命令。

当我在解决方案中测试DLL时,我得到:

" 处理SamsungTester.exe中0x076b00bc处的attachFirst-chance异常:0xC0000005:访问冲突。 SamsungTester.exe中0x076b00bc处的未处理异常:0xC0000005:访问冲突。 "

我的代码我有一个扩展CDialog的课程(" myDialog.g")

class myDialog : public CDialog
{
    DECLARE_DYNAMIC(myDialog)

public:
    myDialog(CWnd* pParent = NULL);   // standard constructor
    virtual ~myDialog();

// Dialog Data
    enum { IDD = IDD_DIALOG1 };

protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

DECLARE_MESSAGE_MAP()

public:
    CXnssdkdevicectrl1 m_ctrlXnsDevice;
    long initializeSDK();
};

然后扩展CWinApp的其他类

class CMyMFCDLLApp : public CWinApp
{
public:
    HANDLE recMutex;
    CMyMFCDLLApp();


// Overrides
public:
    virtual BOOL InitInstance();
    myDialog dlg;
    DECLARE_MESSAGE_MAP()
};

然后在CPP

#include "stdafx.h"
#include "MyMFCDLL.h"
#include "mydialog.h";
#include "dllDeclaration.h"
#include "Test.h"
#include <initguid.h>
#include "MyMFCDLL_i.c"

// [ XNS ACTIVEX HELP ]
// -----------------------------------------------------------------------
// This files are installed in {$SDK path}\sample_code\include 
// You should include this files
// -----------------------------------------------------------------------
#include "XnsCommon.h"
#include "XnsDeviceInterface.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

class CMyMFCDLLModule :
    public CAtlMfcModule
{
public:
    DECLARE_LIBID(LIBID_MyMFCDLLLib);
    DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MYMFCDLL, "{1AFA86BF-3CCC-4A17-B023-F61E8DE38ED6}");};

CMyMFCDLLModule _AtlModule;

BEGIN_MESSAGE_MAP(CMyMFCDLLApp, CWinApp)
END_MESSAGE_MAP()


CMyMFCDLLApp::CMyMFCDLLApp()
{
}


BOOL CMyMFCDLLApp::InitInstance()
{
    CWinApp::InitInstance();

    AtlAxWinInit();
    COleObjectFactory::RegisterAll();

    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // Set this to include all the common control classes you want to use
    // in your application.
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    AfxOleInit();
    AfxEnableControlContainer();

    CoInitialize(0);
    recMutex=CreateEvent(NULL, FALSE,FALSE, NULL);


    return TRUE;
}


long init2(){

    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    theApp.dlg.Create(myDialog::IDD);
    theApp.dlg.ShowWindow(SW_SHOW);

    theApp.dlg.initializeSDK();
    return 0;
}

当我在Cdialog中使用activeX控件时,会生成.h:

#pragma once

// ÄÄÇ»ÅÍ¿¡¼­ Microsoft Visual C++¸¦ »ç¿ëÇÏ¿© »ý¼ºÇÑ IDispatch ·¡ÆÛ Å¬·¡½ºÀÔ´Ï´Ù.

// Âü°í: ÀÌ ÆÄÀÏÀÇ ³»¿ëÀ» ¼öÁ¤ÇÏÁö ¸¶½Ê½Ã¿À. Microsoft Visual C++¿¡¼­
//  ÀÌ Å¬·¡½º¸¦ ´Ù½Ã »ý¼ºÇÒ ¶§ ¼öÁ¤ÇÑ ³»¿ëÀ» µ¤¾î¾¹´Ï´Ù.

/////////////////////////////////////////////////////////////////////////////
// CXnssdkdevicectrl ·¡ÆÛ Å¬·¡½ºÀÔ´Ï´Ù.

class CXnssdkdevicectrl : public CWnd
{
protected:
    DECLARE_DYNCREATE(CXnssdkdevicectrl)
public:
    CLSID const& GetClsid()
    {
        static CLSID const clsid
            = { 0xXPTO, 0xXPTO, 0xXPTO, { 0xXP, 0xXP, 0xXP, 0xXP, 0xXP, 0xXP, 0xXP, 0xXP } };
        return clsid;
    }
    virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
                        const RECT& rect, CWnd* pParentWnd, UINT nID, 
                        CCreateContext* pContext = NULL)
    { 
        return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); 
    }

    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, 
                UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
                BSTR bstrLicKey = NULL)
    { 
        return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
        pPersist, bStorage, bstrLicKey); 
    }

// Ư¼ºÀÔ´Ï´Ù.
public:


// ÀÛ¾÷ÀÔ´Ï´Ù.
public:

// _DXnsSdkDevice

// Functions
//

    long Initialize()
    {
        long result;
        InvokeHelper(0x1, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);
        return result;
    }

要初始化activeX,请调用调用调用Invoker的activeX Initialize函数的InitializeSDK:

InvokeHelper(0x1, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);

然后在以下位置提供例外:

// make the call
SCODE sc = m_lpDispatch->Invoke(dwDispID, IID_NULL, 0, wFlags,
    &dispparams, pvarResult, &excepInfo, &nArgErr);

0 个答案:

没有答案