我想将 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 的正确方法吗?有没有办法,或者我应该只传递字符串,从女巫 dll 中创建 xml?