static void CreateDiscoveryPublisher_XMLContext_tests(void) { IWSDiscoveryPublisher *publisher = NULL; IWSDXMLContext *xmlContext, *returnedContext; HRESULT rc; int ref; /* Test creating an XML context and supplying it to WSDCreateDiscoveryPublisher */ rc = WSDXMLCreateContext(&xmlContext); ok(rc == S_OK, "WSDXMLCreateContext failed: %08x\n", rc); rc = WSDCreateDiscoveryPublisher(xmlContext, &publisher); ok(rc == S_OK, "WSDCreateDiscoveryPublisher(xmlContext, &publisher) failed: %08x\n", rc); ok(publisher != NULL, "WSDCreateDiscoveryPublisher(xmlContext, &publisher) failed: publisher == NULL\n"); rc = IWSDiscoveryPublisher_GetXMLContext(publisher, NULL); ok(rc == E_INVALIDARG, "GetXMLContext returned unexpected value with NULL argument: %08x\n", rc); rc = IWSDiscoveryPublisher_GetXMLContext(publisher, &returnedContext); ok(rc == S_OK, "GetXMLContext failed: %08x\n", rc); ok(xmlContext == returnedContext, "GetXMLContext returned unexpected value: returnedContext == %p\n", returnedContext); ref = IWSDXMLContext_Release(returnedContext); ok(ref == 2, "IWSDXMLContext_Release() has %d references, should have 2\n", ref); ref = IWSDiscoveryPublisher_Release(publisher); ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref); ref = IWSDXMLContext_Release(returnedContext); ok(ref == 0, "IWSDXMLContext_Release() has %d references, should have 0\n", ref); /* Test using a default XML context */ publisher = NULL; returnedContext = NULL; rc = WSDCreateDiscoveryPublisher(NULL, &publisher); ok(rc == S_OK, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: %08x\n", rc); ok(publisher != NULL, "WSDCreateDiscoveryPublisher(NULL, &publisher) failed: publisher == NULL\n"); rc = IWSDiscoveryPublisher_GetXMLContext(publisher, &returnedContext); ok(rc == S_OK, "GetXMLContext failed: %08x\n", rc); ref = IWSDXMLContext_Release(returnedContext); ok(ref == 1, "IWSDXMLContext_Release() has %d references, should have 1\n", ref); ref = IWSDiscoveryPublisher_Release(publisher); ok(ref == 0, "IWSDiscoveryPublisher_Release() has %d references, should have 0\n", ref); }
// <HostBuilderImplementation> HRESULT CreateStockQuoteHost( LPCWSTR pszDeviceAddress, const WSD_THIS_DEVICE_METADATA* pThisDeviceMetadata, IStockQuote* pIStockQuote, IWSDDeviceHost** ppHostOut, IWSDXMLContext** ppContextOut) { HRESULT hr = S_OK; IWSDXMLContext* pContext = NULL; IWSDDeviceHost* pHost = NULL; // // Validate parameters // if( NULL == pszDeviceAddress ) { return E_INVALIDARG; } if( NULL == pThisDeviceMetadata ) { return E_INVALIDARG; } // pIStockQuote is optional if( NULL == ppHostOut ) { return E_POINTER; } // ppContextOut is optional *ppHostOut = NULL; if( NULL != ppContextOut ) { *ppContextOut = NULL; } // // Create XML context for namespace and type registration // hr = WSDXMLCreateContext(&pContext); // // Register types used by the service // if( S_OK == hr ) { hr = StockQuoteRegisterTypes(pContext); } // // Register namespaces used by the service // if( S_OK == hr ) { hr = StockQuoteRegisterNamespaces(pContext); } // // Create device host // if( S_OK == hr ) { hr = WSDCreateDeviceHost(pszDeviceAddress, pContext, &pHost); } // // Register port types // if( S_OK == hr ) { hr = pHost->RegisterPortType(&PortType_StockQuotePortType); } // // Set metadata // if( S_OK == hr ) { hr = pHost->SetMetadata(&thisModelMetadata, pThisDeviceMetadata, &hostMetadata, NULL); } // // Register services and set discoverability // if( S_OK == hr && pIStockQuote != NULL ) { hr = pHost->RegisterService(L"http://example.com/stockquote/definitions/StockQuotePortType0", pIStockQuote); } // // Cleanup // if( S_OK == hr && ppContextOut ) { *ppContextOut = pContext; } else { if( NULL != pContext ) { pContext->Release(); } } if( S_OK == hr ) { *ppHostOut = pHost; } else { if( NULL != pHost ) { pHost->Release(); } } return hr; }
// <ProxyBuilderImplementations> HRESULT CreateCStockQuoteProxy( LPCWSTR pszDeviceAddress, LPCWSTR pszLocalAddress, CStockQuoteProxy** ppProxyOut, IWSDXMLContext** ppContextOut) { HRESULT hr = S_OK; IWSDXMLContext* pContext = NULL; IWSDDeviceProxy* pDeviceProxy = NULL; IWSDServiceProxy* pServiceProxy = NULL; CStockQuoteProxy* pProxy = NULL; // // Validate parameters // if( NULL == pszDeviceAddress ) { return E_INVALIDARG; } if( NULL == pszLocalAddress ) { return E_INVALIDARG; } if( NULL == ppProxyOut ) { return E_POINTER; } // ppContextOut is optional *ppProxyOut = NULL; if( NULL != ppContextOut ) { *ppContextOut = NULL; } // // Create XML context for namespace and type registration // hr = WSDXMLCreateContext(&pContext); // // Register types used by the service // if( S_OK == hr ) { hr = StockQuoteRegisterTypes(pContext); } // // Register namespaces used by the service // if( S_OK == hr ) { hr = StockQuoteRegisterNamespaces(pContext); } // // Create a proxy for the device host // if( S_OK == hr ) { hr = WSDCreateDeviceProxy(pszDeviceAddress, pszLocalAddress, pContext, &pDeviceProxy); } // // Create a proxy for the service // if( S_OK == hr ) { hr = pDeviceProxy->GetServiceProxyByType(&Names_Definitions[0], &pServiceProxy); } // // Create a proxy for the port type // if( S_OK == hr ) { pProxy = new CStockQuoteProxy(); if( NULL == pProxy ) { hr = E_OUTOFMEMORY; } } if( S_OK == hr ) { hr = pProxy->Init(pServiceProxy); } // // Cleanup // if( NULL != pServiceProxy ) { pServiceProxy->Release(); } if( NULL != pDeviceProxy ) { pDeviceProxy->Release(); } if( S_OK == hr && ppContextOut ) { *ppContextOut = pContext; } else { if( NULL != pContext ) { pContext->Release(); } } if( S_OK == hr ) { *ppProxyOut = pProxy; } else { if( NULL != pProxy ) { pProxy->Release(); } } return hr; }