从c ++控制台应用程序调用ActiveX方法的灾难性故障

时间:2012-03-07 05:01:09

标签: c++ activex

我需要将ActiveX控件替换为新控件,以便在现有应用程序中使用,而无需修改现有应用程序。

我有原始的ocx文件和包装类的代码,用于在现有应用程序中创建和使用ActiveX控件。

我在VS 2005中创建了一个测试控制台应用程序,使用现有应用程序中的包装类,可以创建和使用旧的ActiveX控件。

我创建了一个新的ActiveX控件,其接口与旧的相同,修改了所有Class Ids以匹配并注册新的ocx。可以创建新控件,但在调用任何方法时,我遇到了灾难性故障,错误代码为7fff0001。

我退后一步,创建了另一个具有相同界面的新ActiveX控件,但没有修改Class Ids。然后,我使用包装器类构建了一个新的测试控制台应用程序,并为此新控件编译它。但是在调用控件的方法时,我仍然遇到了灾难性的失败。

我已经搜索了一个答案,但大多数都提到了从托管c#应用程序调用ActiveX方法的问题,并且没有为我的情况提供任何帮助。

请参阅下面的包装器和ActiveX控件导入文件的代码,感谢任何帮助。

ClientWrapper.h

#if !defined(AFX_CLIENTWRAPPER_H__D8C23AC2_6F22_11D6_9F45_0003B3008F24__INCLUDED_)
#define AFX_CLIENTWRAPPER_H__D8C23AC2_6F22_11D6_9F45_0003B3008F24__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#import <Msxml3.dll>

#import "ACDCLIENTX.OCX"

#include <atlbase.h>
#include <atlconv.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <assert.h>
#ifdef ASSERT
    #undef ASSERT
#endif
#define ASSERT assert

class CParsedResponse  
{
public:
    CParsedResponse():m_bIsApproved(false),m_bIsCaptured(false),
                      m_bIsSuccess(false),m_bIsError(false){;}
    virtual ~CParsedResponse(){;};
    CParsedResponse(const CParsedResponse& copy){*this = copy;}
    CParsedResponse& operator = (const CParsedResponse& that)
    {
        if(this == &that ) return *this;
        m_strErrorNo        =   that.m_strErrorNo;
        m_strVerbage        =   that.m_strVerbage;
        m_strBalance        =   that.m_strBalance; 
        m_strPrePaidExp     =   that.m_strPrePaidExp;
        m_strAuthCode       =   that.m_strAuthCode;
        m_strReferenceNo    =   that.m_strReferenceNo;
        m_strAcctNo         =   that.m_strAcctNo;
        m_strExpDate        =   that.m_strExpDate;
        m_strPurchaseAmount =   that.m_strPurchaseAmount;
        m_strInvoiceNo      =   that.m_strInvoiceNo;
        m_strOpId           =   that.m_strOpId;
        m_strAcqRefData     =   that.m_strAcqRefData;
        m_strOrigin         =   that.m_strOrigin;
        m_bIsApproved       =   that.m_bIsApproved;     
        m_bIsCaptured       =   that.m_bIsCaptured;
        m_bIsSuccess        =   that.m_bIsSuccess;
        m_bIsError          =   that.m_bIsError;
        return *this;
    }
    void Empty()
    {
        m_strErrorNo        =   
        m_strVerbage        =
        m_strBalance        =
        m_strPrePaidExp     =   
        m_strAuthCode       =   
        m_strReferenceNo    =   
        m_strAcctNo         =   
        m_strExpDate        =   
        m_strPurchaseAmount =   
        m_strInvoiceNo      =   
        m_strOpId           =   
        m_strAcqRefData     =   
        m_strOrigin         = "";   

        m_bIsApproved       =   
        m_bIsCaptured       =   
        m_bIsSuccess        =   
        m_bIsError          =   false;
    }

    std::string     m_strErrorNo,
            m_strVerbage,
            m_strBalance,
            m_strPrePaidExp,
            m_strAuthCode,
            m_strReferenceNo,
            m_strAcctNo,
            m_strExpDate,
            m_strPurchaseAmount,
            m_strInvoiceNo,
            m_strOpId,
            m_strAcqRefData,
            m_strOrigin;
    bool    m_bIsApproved,          
            m_bIsCaptured,
            m_bIsSuccess,
            m_bIsError;

};

class CClientWrapper  
{
    std::string m_strName;
    bool LooksLikeIp(const std::string IPorHostName);
    std::string GetIPAddressFromHostName(const std::string& Ip);
    bool GetIPFromXML(const std::string XML,std::string& Ip);
    void AddToStore(std::string & s,const std::string & ip);
    int GetNumIPStoredIPFromXML(const std::string XML);
    std::string BuildErrorResponse(const int ErrNo, const std::string strErrText);
    std::string BuildErrorResponse(const std::string ErrNo, const std::string strErrText);
    std::string CClientWrapper::BuildErrorResponse(const _com_error ComError);
public:
    std::string m_strError;
    std::string m_strServerPassword;
    CParsedResponse ExtractTransResponse(const std::string XmlResponse);
    std::string SendRequestReturnXML(const std::string strXML);
    CParsedResponse SendRequest(const std::string strXML);
    bool DoServerIp(const std::vector<std::string>& IpList);
    std::string PingStoredServerListReturnXML();

private:
    ACDCLIENTXLib::_DACDCLientXPtr m_pClient;   
    bool m_bComInit;
    bool m_bControlInit;

public:
    void Destroy();
    bool Create();
    void Cancel();
    CClientWrapper();
    virtual ~CClientWrapper();
    int SetConnectTimeout(const int t);
    int SetResponseTimeout(const int t);
    CParsedResponse PingStoredServerList();
    // 0 dialog // 1 no dialog  // 2 not currently supported in wrapper
    SHORT m_nDialogControl; 

};

#endif // !defined(AFX_CLIENTWRAPPER_H__D8C23AC2_6F22_11D6_9F45_0003B3008F24__INCLUDED_)

ClientWrapper.cpp

#include "StdAfx.h"

#include "ClientWrapper.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define WRAP_ERROR "900999"
CClientWrapper::CClientWrapper():m_bComInit(false),m_bControlInit(false),
    m_nDialogControl(0),m_strServerPassword("")
{

}

CClientWrapper::~CClientWrapper()
{
    Destroy();
}

void  CClientWrapper::Destroy()
{
    if(m_bControlInit)
    {
        m_pClient.Release();
        m_bControlInit = false;
    }

    if(m_bComInit)
    {
        ::CoUninitialize();
        m_bComInit = false;
    }

}
bool CClientWrapper::Create()
{

    USES_CONVERSION;
    Destroy();
    ASSERT(!m_bComInit);
    HRESULT hr = ::CoInitialize(NULL);     
    if (FAILED(hr))     
    {          
        m_strError = "CoInitialize Failed - Fatal Error!";
        return false;
    }
    m_bComInit = true;

    ASSERT(!m_bControlInit);
    hr = m_pClient.CreateInstance(__uuidof(ACDCLIENTXLib::ACDCLientX)); 
    if(FAILED(hr) )
    {
        m_strError = "Failed to Create ACDCLientX.ocx you may need to reinstall the product - Fatal Error!";
        return false;

    }
    m_bControlInit = true;
    // make sure xml parser is available 
    try
    {
        MSXML2::IXMLDOMDocumentPtr pDOMDoc(__uuidof(MSXML2::DOMDocument));
    }
    catch(_com_error e)
    {
        m_strError = "Msxml3.dll required for this application. You may need to reinstall the product - Fatal Error!";
        return false;
    }
    return true;

}



#pragma warning(disable:4786)

std::string CClientWrapper::GetIPAddressFromHostName(const std::string& Ip)
{
    std::string rv;
    USES_CONVERSION;
    _bstr_t strIp(Ip.c_str());
    try
    {
        rv = W2T(m_pClient->GetIPAddressFromHostName(strIp,m_nDialogControl));
    }
    catch(const _com_error &e)
    {
        throw e;
    }

    return rv;
}

bool CClientWrapper::DoServerIp(const std::vector<std::string>& IpList)
{
    std::vector<std::string>::const_iterator i;
    USES_CONVERSION;
    assert(m_bComInit && m_bControlInit);
    ////
    ////
    try          
    {               
        std::string IpStore("");
        i = IpList.begin();
        while(i != IpList.end())
        {
            std::string Ip = *i;
            if(!Ip.length() )
            {
                ++ i;
                continue;
            }
            if(!LooksLikeIp(Ip) )
            {
                std::string  xml = GetIPAddressFromHostName(Ip);
                if(GetIPFromXML(xml,Ip) )
                {
                    AddToStore(IpStore,Ip);
                }
            }
            else
            {
                AddToStore(IpStore,Ip);
            }
            ++ i;
        }
        if(!IpStore.length())
        {
            m_strError = "No Resolved Ip Address.";
            return false;
        }
        _bstr_t strIpStore(IpStore.c_str());
        std::string  xml = W2T(m_pClient->ServerIPConfig(strIpStore,m_nDialogControl));
        if(GetNumIPStoredIPFromXML(xml) <= 0 )
        {
            m_strError = "No Resolved Ip Address.";
            return false;
        }

        //defaults to 10 seconds connect - 300 seconds response 
        #ifdef _DEBUG
            ASSERT(m_pClient->SetConnectTimeout(5) == 5);
        #else
            m_pClient->SetConnectTimeout(5);
        #endif
        //  VERIFY(m_pClient->SetConnectTimeout(5) == 5);
        //VERIFY(m_pClient->SetResponseTimeout(300) == 300);
        // you may wish to 'ping' the servers at this point
        // using PingStoredServerList(..)
        // or you could ping each before you store the ServerIpConfig(..)
        // using PingServer(..)
        // it is up to you whether you want your 
        // app not to start or give some other message because a server is down
        // if you decide not to ping AND the Server is DOWN when you attempt
        // an authorization the control will return an appropriate error. 

    }
    catch (const _com_error &ComError)
    {               
        m_strError = ComError.ErrorMessage() + std::string(" Fatal Error!");
        return false;

    }
    catch (...)
    {
        m_strError = "ATL/COM Error" + std::string(" Fatal Error!");
        return false;

    }
    char nameBuffer[101] = {0};
    DWORD size = 100;
    if(::GetUserName(nameBuffer,&size) )
        m_strName = nameBuffer;

    return true;

}

bool CClientWrapper::LooksLikeIp(const std::string IPorHostName)
{

    std::map<int,std::string> Map;
    std::map<int,std::string>::const_iterator iter;
    const std::string& s = IPorHostName;
    int x(0),len = s.length();
    char c,fsep = '.';
    std::string fieldText;
    int NumOctets (0);
    while(x < len)
    {
        c = s[x];
        if(c != fsep)
            fieldText += c;
        else
        {
            Map[NumOctets++]=fieldText;
            fieldText = "";
        }
        x++;
    }
    if(fieldText.length() )
        Map[NumOctets++]=fieldText;


    if(NumOctets != 4)
        return false;

    for(x = 0; x < 4 ; x ++ )
    {
        std::string octect;
        if((iter = Map.find(x))==Map.end() )
            return false;
        octect = (*iter).second;
        int val = _ttoi(octect.c_str());
        if(val == 0 )
        {
            //octect.TrimLeft();
            int len = octect.length();
            std::string temp("");
            for(int xx= 0; xx < len ; xx ++ )
            {
                char c = octect[xx];
                if(temp.length() || c != ' ' )
                {
                    temp += c;
                }
            }
            octect = temp;
            if(!octect.length() || octect[0] < 0x30 || octect[0] > 0x39)
                return false;
        }
        if(val < 0 || val > 255)
            return false;
    }
    return true;

}

bool CClientWrapper::GetIPFromXML(const std::string XML,std::string& Ip)
{

    USES_CONVERSION;
    try
    {
        _bstr_t strXML (XML.c_str());   
        MSXML2::IXMLDOMDocumentPtr pDOMDoc(__uuidof(MSXML2::DOMDocument));
        VARIANT_BOOL  varResult = pDOMDoc->loadXML(strXML);
        // any error is bad 
        if (VARIANT_FALSE == varResult)
            return false;
        MSXML2::IXMLDOMNodePtr pNode = pDOMDoc->selectSingleNode("//CmdStatus");
        if(0 == pNode )
            return false;
        std::string Result = W2T(pNode->Gettext() );
        if("Success" != Result)
            return false;
        pNode = pDOMDoc->selectSingleNode("//IpAddress");
        if(0 == pNode )
            return false;
        Ip = W2T(pNode->Gettext());
        return true;
    }
    catch(_com_error e)
    {
        #ifdef _DEBUG
        std::cerr << std::string("Caught Exception: GetIPFromXML") << std::endl;
        #endif
    }
    catch(...)
    {
        #ifdef _DEBUG
        std::cerr << std::string("Caught Exception: GetIPFromXML") << std::endl;
        #endif

    }
    return false;



}


void CClientWrapper::AddToStore(std::string & s,const std::string& ip)
{
    // if ip is empty ignore it 
    if(!ip.length() )
        return;
    // if the store is not empty it is ';' separated
    if(s.length() )
        s += std::string(";") + ip;
    else
        s = ip;

}


int CClientWrapper::GetNumIPStoredIPFromXML(const std::string XML)
{
    USES_CONVERSION;
    try
    {
        _bstr_t strXML (XML.c_str());   
        MSXML2::IXMLDOMDocumentPtr pDOMDoc(__uuidof(MSXML2::DOMDocument));
        VARIANT_BOOL  varResult = pDOMDoc->loadXML(strXML);
        // any error is bad 
        if (VARIANT_FALSE == varResult)
            return 0;
        MSXML2::IXMLDOMNodePtr pNode = pDOMDoc->selectSingleNode("//CmdStatus");
        if(0 == pNode )
            return 0;
        std::string Result = W2T(pNode->Gettext() );
        if("Success" != Result)
            return 0;
        pNode = pDOMDoc->selectSingleNode("//TextResponse");
        if(0 == pNode )
            return 0;
        return _ttoi(W2T(pNode->Gettext() ) );

    }
    catch(_com_error e)
    {
        #ifdef _DEBUG
        std::cerr << std::string("Caught Exception: GetNumIPStoredIPFromXML") << std::endl;
        #endif
    }
    catch(...)
    {
        #ifdef _DEBUG
        std::cerr << std::string("Caught Exception: GetNumIPStoredIPFromXML") << std::endl;
        #endif
    }
    return 0;


}







std::string CClientWrapper::BuildErrorResponse(const _com_error ComError)
{
    std::stringstream ssErrNo;
    ssErrNo << ComError.Error();


    return BuildErrorResponse(ssErrNo.str(), ComError.ErrorMessage());

}
std::string CClientWrapper::BuildErrorResponse(const std::string ErrNo, const std::string strErrText)
{
    return BuildErrorResponse(_ttoi(ErrNo.c_str()),  strErrText);
}
std::string CClientWrapper::BuildErrorResponse(const int ErrNo, const std::string strErrText)
{
#define TAB "\t"
#define CRLF "\r\n"

    std::ostringstream oss;
    oss <<  "<?xml version=\"1.0\"?>"CRLF
            "<RStream>"CRLF
            TAB "<CmdResponse>"CRLF
            TAB TAB "<ACDXReturnCode>"
        << std::setw(6) << std::setfill('0') << ErrNo
        <<  "</ACDXReturnCode>"CRLF
            TAB TAB "<CmdStatus>Error</CmdStatus>"CRLF
            TAB TAB "<TextResponse>"
        << strErrText.c_str()
        <<  "</TextResponse>"CRLF
            TAB "</CmdResponse>"CRLF
            "</RStream>"CRLF
        << std::endl;
    std::string rv(oss.str());
    return rv;
}








std::string CClientWrapper::PingStoredServerListReturnXML()
{
    USES_CONVERSION;
    std::string rv;
    try
    {
        rv = W2T(m_pClient->PingStoredServerList("",m_nDialogControl) );
    }
    catch (const _com_error &ComError)
    {   
        rv = BuildErrorResponse(ComError);
    }
    catch (...)
    {
        rv = BuildErrorResponse(WRAP_ERROR,"ATLCOM ERROR");
    }
    return rv;


}





void CClientWrapper::Cancel()
{
    try
    {
        m_pClient->CancelRequest();
    }
    catch (const _com_error &ComError)
    {   
        std::string s = BuildErrorResponse(WRAP_ERROR,ComError.ErrorMessage() );
        #ifdef _DEBUG
        std :: cerr << s << std::endl;
        #endif
    }
    catch (...)
    {
        std::string s = BuildErrorResponse(WRAP_ERROR,"ATLCOM ERROR");
        #ifdef _DEBUG
        std :: cerr << s << std::endl;
        #endif

    }

}

CParsedResponse  CClientWrapper::SendRequest(const std::string strXML)
{
    return ExtractTransResponse(SendRequestReturnXML(strXML) );
}

std::string CClientWrapper::SendRequestReturnXML(const std::string strXML)
{
    USES_CONVERSION;
    std::string rv;

    try
    {
        _bstr_t strXml(strXML.c_str());
        _bstr_t strPasswd(m_strServerPassword.c_str());
        _bstr_t strName(m_strName.c_str());
        rv = W2T(m_pClient->ProcessTransaction(
                                        strXml,
                                        m_nDialogControl,
                                        strPasswd,
                                        strName) );
    }
    catch (const _com_error &ComError)
    {   
        rv = BuildErrorResponse(WRAP_ERROR,ComError.ErrorMessage() );
    }
    catch (...)
    {
        rv = BuildErrorResponse(WRAP_ERROR,"ATLCOM ERROR");
    }
    return rv;
}




CParsedResponse CClientWrapper::ExtractTransResponse(const std::string XmlResponse)
{
    CParsedResponse rv;
    USES_CONVERSION;
    try
    {
        _bstr_t strXML (XmlResponse.c_str());   
        MSXML2::IXMLDOMDocumentPtr pDOMDoc(__uuidof(MSXML2::DOMDocument));
        VARIANT_BOOL  varResult = pDOMDoc->loadXML(strXML);
        if (VARIANT_FALSE == varResult)
        {
            MSXML2::IXMLDOMParseErrorPtr pParseError = pDOMDoc->GetparseError();
            long dwError = pParseError->GeterrorCode();
            _bstr_t bstrReason = pParseError->Getreason();
            long num = pParseError->Getline();
            std::ostringstream oss;
            std::string strReason = W2T(bstrReason);
            oss << "XML Parse Error at line#:" << num << "\r\n" << strReason << std::endl;
            std::string error (oss.str() );

            rv.m_strErrorNo  = WRAP_ERROR;
            rv.m_strVerbage    = error;
            rv.m_bIsError = true;
            return rv;

        }
        MSXML2::IXMLDOMNodePtr pNode = pDOMDoc->selectSingleNode("//TextResponse");
        if(pNode)
        {
            rv.m_strVerbage = W2T(pNode->Gettext() );
        }
        pNode = pDOMDoc->selectSingleNode("//Balance");
        if(pNode)
        {
            rv.m_strBalance = W2T(pNode->Gettext() );
        }
        pNode = pDOMDoc->selectSingleNode("//PrePaidExp");
        if(pNode)
        {
            rv.m_strPrePaidExp = W2T(pNode->Gettext() );
        }

        pNode = pDOMDoc->selectSingleNode("//ResponseOrigin");
        if(pNode)
        {
            rv.m_strOrigin = W2T(pNode->Gettext() );
        }
        pNode = pDOMDoc->selectSingleNode("//ACDXReturnCode");
        if(pNode)
        {
            rv.m_strErrorNo = W2T(pNode->Gettext() );
        }               

        pNode = pDOMDoc->selectSingleNode("//CmdStatus");
        if(pNode)
        {
            std::string strText;
            strText = W2T(pNode->Gettext() );
            if("Approved" == strText ) 
            {
                rv.m_bIsApproved = true;                
                rv.m_strVerbage = "APPROVED";
                pNode = pDOMDoc->selectSingleNode("//AuthCode");
                if(pNode)
                {
                    rv.m_strAuthCode = W2T(pNode->Gettext());
                }
                pNode = pDOMDoc->selectSingleNode("//CaptureStatus");
                if(pNode)
                {
                    #if defined(__USING__MFC)
                    if("Captured" == CString(W2T(pNode->Gettext()) )  )
                    #else
                    if("Captured" == std::string(W2T(pNode->Gettext()) )  )
                    #endif  
                    {
                        rv.m_bIsCaptured = true;

                    }
                }       
                pNode = pDOMDoc->selectSingleNode("//RefNo");
                if(pNode)
                {
                    rv.m_strReferenceNo = W2T(pNode->Gettext());
                }
                pNode = pDOMDoc->selectSingleNode("//AccountNo");
                if(pNode)
                {
                    rv.m_strAcctNo   = W2T(pNode->Gettext()); 
                }       
                pNode = pDOMDoc->selectSingleNode("//ExpDate");
                if(pNode)
                {
                    rv.m_strExpDate   = W2T(pNode->Gettext());              
                }       
                pNode = pDOMDoc->selectSingleNode("//Purchase");
                if(pNode)
                {
                    rv.m_strPurchaseAmount  = W2T(pNode->Gettext());
                }       

                pNode = pDOMDoc->selectSingleNode("//InvoiceNo");
                if(pNode)
                {
                    rv.m_strInvoiceNo  = W2T(pNode->Gettext());
                }       
                pNode = pDOMDoc->selectSingleNode("//OperatorId");
                if(pNode)
                {
                    rv.m_strOpId  = W2T(pNode->Gettext());
                }       
                pNode = pDOMDoc->selectSingleNode("//AcqRefData");
                if(pNode)
                {
                    rv.m_strAcqRefData  = W2T(pNode->Gettext());
                }       

            }
            else if("Declined" == strText)
            {
                rv.m_bIsApproved = false;
                rv.m_bIsCaptured = false;
            }
            else  if("Success" == strText )
            {
                rv.m_bIsSuccess  =true;
            }
            else    if("Error" == strText )
            {
                rv.m_bIsError       =  true;
            }

            else
            {
                rv.m_strVerbage = "Received Invalid Result from ACDClientX Control.- \r\n"+ XmlResponse;
                rv.m_strErrorNo  = WRAP_ERROR;  
            }

        }
    }
    catch(_com_error e)
    {
        #ifdef _DEBUG
        std::cerr<< std::string("Caught Exception: ExtractTransResponse")<< std::endl;
        #endif
        rv.m_strErrorNo = WRAP_ERROR;
        rv.m_strVerbage = e.ErrorMessage();
        rv.m_bIsError       = true;

    }
    catch(...)
    {
        #ifdef _DEBUG
        std::cerr<< std::string("Caught Exception: ExtractTransResponse")<< std::endl;
        #endif
        rv.m_strErrorNo = WRAP_ERROR;
        rv.m_strVerbage = "Msxml3 Open Error";
        rv.m_bIsError      = true;
    }
    return rv;
}

CParsedResponse CClientWrapper::PingStoredServerList()
{
    return ExtractTransResponse(PingStoredServerListReturnXML() );

}

int CClientWrapper::SetResponseTimeout(const int t)
{
    USES_CONVERSION;
    int rv;
    try
    {
        rv = m_pClient->SetResponseTimeout(t);
    }
    catch (const _com_error &ComError)
    {   
        m_strError = BuildErrorResponse(WRAP_ERROR,ComError.ErrorMessage() );
        rv = -1;
    }
    catch (...)
    {
        m_strError = BuildErrorResponse(WRAP_ERROR,"ATLCOM ERROR");
        rv = -1;
    }
    return rv;

}

int CClientWrapper::SetConnectTimeout(const int t)
{
    USES_CONVERSION;
    int rv;
    try
    {
        rv = m_pClient->SetConnectTimeout(t);
    }
    catch (const _com_error &ComError)
    {   
        m_strError = BuildErrorResponse(WRAP_ERROR,ComError.ErrorMessage() );
        rv = -1;
    }
    catch (...)
    {
        m_strError = BuildErrorResponse(WRAP_ERROR,"ATLCOM ERROR");
        rv = -1;
    }
    return rv;

}

acdclientx.tlh

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

namespace ACDCLIENTXLib {

//
// Forward references and typedefs
//

struct __declspec(uuid("87476f1d-9a0f-4e4e-bd38-0378b35d71b8"))
/* LIBID */ __ACDCLIENTXLib;
struct __declspec(uuid("4ff86764-9448-4e1d-a160-4e55c7151c3d"))
/* dispinterface */ _DACDCLientX;
struct __declspec(uuid("fd6514db-1fa1-43c2-982a-9bf3a4f63c71"))
/* dispinterface */ _DACDCLientXEvents;
struct /* coclass */ ACDCLientX;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(_DACDCLientX, __uuidof(_DACDCLientX));
_COM_SMARTPTR_TYPEDEF(_DACDCLientXEvents, __uuidof(_DACDCLientXEvents));

//
// Type library items
//

struct __declspec(uuid("4ff86764-9448-4e1d-a160-4e55c7151c3d"))
_DACDCLientX : IDispatch
{
    //
    // Wrapper methods for error-handling
    //

    // Methods:
    _bstr_t ProcessTransaction (
        _bstr_t XMLCommand,
        short ProcessControl,
        _bstr_t ClientServerPassword,
        _bstr_t UserTraceData );
    _bstr_t ServerIPConfig (
        _bstr_t HostList,
        short ProcessControl );
    _bstr_t PingStoredServerList (
        _bstr_t IpPort,
        short ProcessControl );
    long CancelRequest ( );
    _bstr_t GetIPAddressFromHostName (
        _bstr_t HostName,
        short ProcessControl );
    _bstr_t PingServer (
        _bstr_t IpAddress,
        _bstr_t IpPort,
        short ProcessControl );
    short SetConnectTimeout (
        short TimeoutSec );
    short SetResponseTimeout (
        short TimeoutSec );
    _bstr_t ProcessCanadianTransaction (
        _bstr_t XMLCommand,
        short ProcessControl,
        _bstr_t ClientServerPassword,
        _bstr_t UserTraceData );
};

struct __declspec(uuid("fd6514db-1fa1-43c2-982a-9bf3a4f63c71"))
_DACDCLientXEvents : IDispatch
{};

struct __declspec(uuid("d76e402e-c138-4480-a8a3-bc840d6a2a4e"))
ACDCLientX;
    // [ default ] dispinterface _DACDCLientX
    // [ default, source ] dispinterface _DACDCLientXEvents

//
// Wrapper method implementations
//

#include "acdclientx.tli"

} // namespace ACDCLIENTXLib

#pragma pack(pop)

acdclientx.tli

#pragma once

//
// dispinterface _DACDCLientX wrapper method implementations
//

inline _bstr_t _DACDCLientX::ProcessTransaction ( _bstr_t XMLCommand, short ProcessControl, _bstr_t ClientServerPassword, _bstr_t UserTraceData ) {
    BSTR _result = 0;
    _com_dispatch_method(this, 0x1, DISPATCH_METHOD, VT_BSTR, (void*)&_result, 
        L"\x0008\x0002\x0008\x0008", (BSTR)XMLCommand, ProcessControl, (BSTR)ClientServerPassword, (BSTR)UserTraceData);
    return _bstr_t(_result, false);
}

inline _bstr_t _DACDCLientX::ServerIPConfig ( _bstr_t HostList, short ProcessControl ) {
    BSTR _result = 0;
    _com_dispatch_method(this, 0x2, DISPATCH_METHOD, VT_BSTR, (void*)&_result, 
        L"\x0008\x0002", (BSTR)HostList, ProcessControl);
    return _bstr_t(_result, false);
}

inline _bstr_t _DACDCLientX::PingStoredServerList ( _bstr_t IpPort, short ProcessControl ) {
    BSTR _result = 0;
    _com_dispatch_method(this, 0x3, DISPATCH_METHOD, VT_BSTR, (void*)&_result, 
        L"\x0008\x0002", (BSTR)IpPort, ProcessControl);
    return _bstr_t(_result, false);
}

inline long _DACDCLientX::CancelRequest ( ) {
    long _result = 0;
    _com_dispatch_method(this, 0x4, DISPATCH_METHOD, VT_I4, (void*)&_result, NULL);
    return _result;
}

inline _bstr_t _DACDCLientX::GetIPAddressFromHostName ( _bstr_t HostName, short ProcessControl ) {
    BSTR _result = 0;
    _com_dispatch_method(this, 0x5, DISPATCH_METHOD, VT_BSTR, (void*)&_result, 
        L"\x0008\x0002", (BSTR)HostName, ProcessControl);
    return _bstr_t(_result, false);
}

inline _bstr_t _DACDCLientX::PingServer ( _bstr_t IpAddress, _bstr_t IpPort, short ProcessControl ) {
    BSTR _result = 0;
    _com_dispatch_method(this, 0x6, DISPATCH_METHOD, VT_BSTR, (void*)&_result, 
        L"\x0008\x0008\x0002", (BSTR)IpAddress, (BSTR)IpPort, ProcessControl);
    return _bstr_t(_result, false);
}

inline short _DACDCLientX::SetConnectTimeout ( short TimeoutSec ) {
    short _result = 0;
    _com_dispatch_method(this, 0x7, DISPATCH_METHOD, VT_I2, (void*)&_result, 
        L"\x0002", TimeoutSec);
    return _result;
}

inline short _DACDCLientX::SetResponseTimeout ( short TimeoutSec ) {
    short _result = 0;
    _com_dispatch_method(this, 0x8, DISPATCH_METHOD, VT_I2, (void*)&_result, 
        L"\x0002", TimeoutSec);
    return _result;
}

inline _bstr_t _DACDCLientX::ProcessCanadianTransaction ( _bstr_t XMLCommand, short ProcessControl, _bstr_t ClientServerPassword, _bstr_t UserTraceData ) {
    BSTR _result = 0;
    _com_dispatch_method(this, 0x9, DISPATCH_METHOD, VT_BSTR, (void*)&_result, 
        L"\x0008\x0002\x0008\x0008", (BSTR)XMLCommand, ProcessControl, (BSTR)ClientServerPassword, (BSTR)UserTraceData);
    return _bstr_t(_result, false);
}

1 个答案:

答案 0 :(得分:2)

找到答案: http://support.microsoft.com/kb/146120/EN-US

需要在我的ActiveX控件中定义此功能

BOOL CMyOleControl::IsInvokeAllowed (DISPID)
{
   // You can check to see if COleControl::m_bInitialized is FALSE
  // in your automation functions to limit access.
  return TRUE;
}