DOM
Expand Minimize

DllSetProperty Method

This method is a globally exported function in the MSXML DLL. This method sets a global property for the DLL.

HRESULT DllSetProperty(DWORD dwPropertyID, LPVOID pv);

dwPropertyID

The property ID to set.

pv

An [in] argument that specifies the property value.

Returns S_OK if no error is generated.

This function is used to set global properties for the DLL.

The only value supported for dwPropertyID is 1. Using this property ID, you can set a callback that will be called when when the physical memory for nodes is released . On Windows 7, Windows Sever 2008 R2 , Windows Vista, Windows Server 2008, and Windows XP, the callback is called when the internal garbage collector of MSXML finalizes the nodes. On Windows 8, the callback is called immediately after nodes are released.. The signature of the callback is:

void NodeFinalizeCallback(IUnknown* pUnknown);

The following example shows the use of this method to register a callback that is called when nodes are finalized:

#include <windows.h>
#include <dispex.h>
#include <urlmon.h>
#include <stdio.h>
#include <msxml6.h>
 
#define CHK(stmt) do{ hr=(stmt); if (FAILED(hr)) {printf("FAILED at " #stmt); goto CleanUp;} }while(0)
#define SAFE_RELEASE(p) do{ if ((p)) { (p)->Release(); (p) = NULL; } }while(0)
 
void NodeFinalizeCallback(IUnknown* pUnknown)
{
    printf("Finalize: %p\r\n", pUnknown);
}
 
typedef HRESULT (*LPFNDllSetProperty)(DWORD dw, LPVOID pv);
 
int __cdecl main(int argc, char ** argv)
{
    HRESULT hr = S_OK;
    CHK( CoInitialize(NULL));
    {
        VARIANT_BOOL isSuccessful;
        BSTR xml = NULL;
        IXMLDOMDocument3* pDoc = NULL;
        IXMLDOMNode* pN = NULL;
        IXMLDOMNode* pN2 = NULL;
        IXMLDOMElement* pElem = NULL;
 
        CHK( ::CoCreateInstance(CLSID_DOMDocument60, NULL, CLSCTX_ALL, IID_IXMLDOMDocument3, (void**)&pDoc) );
        HMODULE hMsxml6 = ::GetModuleHandleW(L"msxml6.dll");
        if (NULL==hMsxml6)
        {
            printf("unexpected: Creating DOMDocumen60 object should have loaded msxml6.dll");
            goto CleanUp;
        }
        LPFNDllSetProperty DllSetProperty = (LPFNDllSetProperty) GetProcAddress(hMsxml6, "DllSetProperty");
        if (NULL==DllSetProperty)
        {
            printf("This version of Msxml6 does not support DllSetProperty. You need at least Msxml6 SP2.");
            goto CleanUp;
        }
        DllSetProperty(1, NodeFinalizeCallback);
 
        CHK(pDoc->get_documentElement(&pElem));
 
        VARIANT v;
        V_VT(&v)=VT_I4;
        V_I4(&v)=NODE_DOCUMENT_FRAGMENT;
 
        CHK(pDoc->createNode(v, L"xmlns:x", NULL, &pN));
        {
            IUnknown* pU = NULL;
            pN->QueryInterface(IID_IUnknown, (void**)&pU);
            printf("Create: %p\r\n", pU);
            SAFE_RELEASE(pU);
        }
        SAFE_RELEASE(pDoc);
 
        CHK( pN->selectSingleNode(L".", &pN2));
 
CleanUp:
        SAFE_RELEASE(pElem);
        SAFE_RELEASE(pDoc);
        SAFE_RELEASE(pN2);
        SAFE_RELEASE(pN);
    }
 
    CoUninitialize();
    if(FAILED(hr))
        printf("failed");
    else
        printf("done");
    return 0;
}

Implemented in: MSXML 6.0 SP2 and later.

Show:
© 2015 Microsoft