c++ - 如何将 DOMDocument 从 VBA 传递到 C++ dll

标签 c++ vba domdocument

我想将 xml 文档从 VBA 模板传递到 C++ dll。我在这个 dll 中准备了函数:

extern "C" __declspec(dllexport) int __stdcall  ProcessRequest(IXMLDOMDocument* request, IXMLDOMDocument* response);

int __stdcall ProcessRequest(IXMLDOMDocument* request, IXMLDOMDocument* response)
{
    IXMLDOMElement* root = NULL;
    request->get_documentElement(&root);

    BSTR bstrVal = NULL;
    root->get_text(&bstrVal);

    ::MessageBox(NULL, bstrVal, L"lol", MB_OK);

    return 0;
}

我从 VBA 中这样调用它:

Public Declare Function ProcessRequest Lib "DllName" Alias "_ProcessRequest@8" (ByRef xml1 As DOMDocument, ByRef xml2 As DOMDocument) As Long

Public Sub ProcessRequestTest()
    Dim xml1 As New DOMDocument
    Dim xml2 As New DOMDocument
    Dim x As Long

    xml1.loadXML "<xml>lol</xml>"

    x = ProcessRequest(xml1, xml2)
End Sub

然而,我在以下方面收到违规错误:request->get_documentElement(&root); 为什么会这样?这不是传递 DOMDocument 的正确方法吗?有没有办法,或者我应该只传递字符串,从 witch dll 中创建 xml?

最佳答案

您已在 C++ 中将函数声明为 ByVal,但在 VB declare 语句中声明为 ByRef。

要传递接口(interface) ByRef,您需要将其声明为 IXMLDOMDocument**

例如你在 C++ 中需要这个:

extern "C" __declspec(dllexport) int __stdcall  ProcessRequest(IXMLDOMDocument** pprequest, IXMLDOMDocument** response);

int __stdcall ProcessRequest(IXMLDOMDocument** request, IXMLDOMDocument** ppresponse)

关于c++ - 如何将 DOMDocument 从 VBA 传递到 C++ dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18229518/

相关文章:

c++ - 如何从子类的构造函数初始化父类的私有(private)成员

c++ - 将 Yuv420 转换为 rgb 并在 qt 像素图上显示

vba - 获取一个月的最后一天

php - 如何使用 DOMDocument 向 HTML5 添加脚本

c++ - 通常使用什么类型的数据结构来保存从固件/压缩图像中提取的大量文件信息?

c++ - 从使用模板的类继承时如何覆盖方法?

ms-access - access 2007 bug - 间歇性查询参数提示

visual-studio-2010 - 如何在 Visual Basic 中给文本加下划线(使用 Visual Studio 2010)

php - 将命名空间属性添加到php中的xml节点

java - 从 XMLResourceParser 获取 org.w3c.dom.Document