Creating an Instance using precreated Web Service

I am trying to write a program that uses a Web Service in C++, VS 2005.
It fails because COM is not initialized.
When I try to initialize COM in the usual way by making a COM class
and then calling Initialize it fails to link saying CoInitialize is unresolved.
Is there a library I should link in?

class CCom
{
private :
HRESULT m_hr;

public:
CCom() : m_hr(E_FAIL)
{
}

HRESULT Initialize()
{
ATLASSERT(FAILED(m_hr));
return m_hr = CoInitialize(NULL);
}

~CCom()
{
if (SUCCEEDED(m_hr))
CoUninitialize();
}

};

// then later

CCom COM;
HRESULT hr = COM.Initialize();

So how do you get COM going in C++ VS8 for a Smart Device?

[1092 byte] By [Jraven] at [2008-2-4]
# 1

On Windows CE, you need to call CoInitializeEx as opposed to CoInitialize as CoInitialized isn't supported.

Mario

MarioChenier at 2007-9-8 > top of Msdn Tech,Smart Device Development,Smart Devices General...
# 2
Hi -
Was hoping for a little more help.
Now that I have COM initialized I was trying to do CreateInstance for the Web Service using the information in created when you add a Web Reference to your solution.
It gets setup automatically with C# or VB.
Maybe using the Web Reference is not the way to go here.
Maybe for C++ it all needs to be done by hand.
Anyway below is the header file created by the 'Add Web Reference' wizzard.

//
// sproxy.exe generated file
// do not modify this file
//
// Created: 06/10/2005@20:56:58
//

#pragma once

#if !defined(_WIN32_WINDOWS) && !defined(_WIN32_WINNT) && !defined(_WIN32_WCE)
#pragma message("warning: defining _WIN32_WINDOWS = 0x0410")
#define _WIN32_WINDOWS 0x0410
#endif

#include <atlsoap.h>

namespace StockQuote
{

template <typename TClient = CSoapSocketClientT<> >
class CStockQuoteT :
public TClient,
public CSoapRootHandler
{
protected:

const _soapmap ** GetFunctionMap();
const _soapmap ** GetHeaderMap();
void * GetHeaderValue();
const wchar_t * GetNamespaceUri();
const char * GetServiceName();
const char * GetNamespaceUriA();
HRESULT CallFunction(
void *pvParam,
const wchar_t *wszLocalName, int cchLocalName, size_t nItem);
HRESULT GetClientReader(ISAXXMLReader **ppReader);

public:

HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
{

if (ppv == NULL)
{
return E_POINTER;
}

*ppv = NULL;

if (InlineIsEqualGUID(riid, IID_IUnknown) ||
InlineIsEqualGUID(riid, IID_ISAXContentHandler))
{
*ppv =
static_cast<ISAXContentHandler *>(this);
return S_OK;
}

return E_NOINTERFACE;

}

ULONG __stdcall AddRef()

{
return 1;
}

ULONG __stdcall Release()

{
return 1;
}

CStockQuoteT(ISAXXMLReader *pReader = NULL)
:TClient(_T(
"http://www.webservicex.net/StockQuote.asmx"))
{
SetClient(
true);
SetReader(pReader);
}

~CStockQuoteT()
{
Uninitialize();
}

void Uninitialize()
{
UninitializeSOAP();
}

HRESULT GetQuote(
BSTR symbol,
BSTR* GetQuoteResult
);
};

typedef CStockQuoteT<> CStockQuote;

struct __CStockQuote_GetQuote_struct
{
BSTR symbol;
BSTR GetQuoteResult;
};

extern __declspec(selectany) const _soapmapentry __CStockQuote_GetQuote_entries[] =
{

{
0x150C4A36,
"symbol",
L"symbol",
sizeof("symbol")-1,
SOAPTYPE_STRING,
SOAPFLAG_NONE | SOAPFLAG_IN | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL | SOAPFLAG_NULLABLE,
offsetof(__CStockQuote_GetQuote_struct, symbol),
NULL,
NULL,
-1,
},
{
0xADEDE4CD,
"GetQuoteResult",
L"GetQuoteResult",
sizeof("GetQuoteResult")-1,
SOAPTYPE_STRING,
SOAPFLAG_NONE | SOAPFLAG_OUT | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL | SOAPFLAG_NULLABLE,
offsetof(__CStockQuote_GetQuote_struct, GetQuoteResult),
NULL,
NULL,
-1,
},
{ 0x00000000 }
};

extern __declspec(selectany) const _soapmap __CStockQuote_GetQuote_map =
{
0xE0A16C5D,
"GetQuote",
L"GetQuoteResponse",
sizeof("GetQuote")-1,
sizeof("GetQuoteResponse")-1,
SOAPMAP_FUNC,
__CStockQuote_GetQuote_entries,
sizeof(__CStockQuote_GetQuote_struct),
1,
-1,
SOAPFLAG_NONE | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL,
0x8EAC1FF6,
"http://www.webserviceX.NET/",
L"http://www.webserviceX.NET/",
sizeof("http://www.webserviceX.NET/")-1
};

extern __declspec(selectany) const _soapmap * __CStockQuote_funcs[] =
{
&__CStockQuote_GetQuote_map,
NULL
};

template <typename TClient>
inline HRESULT CStockQuoteT<TClient>::GetQuote(
BSTR symbol,
BSTR* GetQuoteResult
)
{
if ( GetQuoteResult == NULL )
return E_POINTER;

HRESULT __atlsoap_hr = InitializeSOAP(NULL);
if (FAILED(__atlsoap_hr))
{
SetClientError(SOAPCLIENT_INITIALIZE_ERROR);
return __atlsoap_hr;
}

CleanupClient();

CComPtr<IStream> __atlsoap_spReadStream;
__CStockQuote_GetQuote_struct __params;
memset(&__params, 0x00, sizeof(__params));
__params.symbol = symbol;

__atlsoap_hr = SetClientStruct(&__params, 0);
if (FAILED(__atlsoap_hr))
{
SetClientError(SOAPCLIENT_OUTOFMEMORY);
goto __skip_cleanup;
}

__atlsoap_hr = GenerateResponse(GetWriteStream());
if (FAILED(__atlsoap_hr))
{
SetClientError(SOAPCLIENT_GENERATE_ERROR);
goto __skip_cleanup;
}

__atlsoap_hr = SendRequest(_T("SOAPAction: \"http://www.webserviceX.NET/GetQuote\"\r\n"));
if (FAILED(__atlsoap_hr))
{
goto __skip_cleanup;
}
__atlsoap_hr = GetReadStream(&__atlsoap_spReadStream);
if (FAILED(__atlsoap_hr))
{
SetClientError(SOAPCLIENT_READ_ERROR);
goto __skip_cleanup;
}

// cleanup any in/out-params and out-headers from previous calls
Cleanup();
__atlsoap_hr = BeginParse(__atlsoap_spReadStream);
if (FAILED(__atlsoap_hr))
{
SetClientError(SOAPCLIENT_PARSE_ERROR);
goto __cleanup;
}

*GetQuoteResult = __params.GetQuoteResult;
goto __skip_cleanup;

__cleanup:
Cleanup();
__skip_cleanup:
ResetClientState(true);
memset(&__params, 0x00, sizeof(__params));
return __atlsoap_hr;
}

template <typename TClient>
ATL_NOINLINE inline const _soapmap ** CStockQuoteT<TClient>::GetFunctionMap()
{
return __CStockQuote_funcs;
}

template <typename TClient>
ATL_NOINLINE inline const _soapmap ** CStockQuoteT<TClient>::GetHeaderMap()
{
static const _soapmapentry __CStockQuote_GetQuote_atlsoapheader_entries[] =
{
{ 0x00000000 }
};

static const _soapmap __CStockQuote_GetQuote_atlsoapheader_map =
{
0xE0A16C5D,
"GetQuote",
L"GetQuoteResponse",
sizeof("GetQuote")-1,
sizeof("GetQuoteResponse")-1,
SOAPMAP_HEADER,
__CStockQuote_GetQuote_atlsoapheader_entries,
0,
0,
-1,
SOAPFLAG_NONE | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL,
0x8EAC1FF6,
"http://www.webserviceX.NET/",
L"http://www.webserviceX.NET/",
sizeof("http://www.webserviceX.NET/")-1
};


static const _soapmap * __CStockQuote_headers[] =
{
&__CStockQuote_GetQuote_atlsoapheader_map,
NULL
};

return __CStockQuote_headers;
}

template <typename TClient>
ATL_NOINLINE inline void * CStockQuoteT<TClient>::GetHeaderValue()
{
return this;
}

template <typename TClient>
ATL_NOINLINE inline const wchar_t * CStockQuoteT<TClient>::GetNamespaceUri()
{
return L"http://www.webserviceX.NET/";
}

template <typename TClient>
ATL_NOINLINE inline const char * CStockQuoteT<TClient>::GetServiceName()
{
return NULL;
}

template <typename TClient>
ATL_NOINLINE inline const char * CStockQuoteT<TClient>::GetNamespaceUriA()
{
return "http://www.webserviceX.NET/";
}

template <typename TClient>
ATL_NOINLINE inline HRESULT CStockQuoteT<TClient>::CallFunction(
void *,
const wchar_t *, int,
size_t)
{
return E_NOTIMPL;
}

template <typename TClient>
ATL_NOINLINE inline HRESULT CStockQuoteT<TClient>::GetClientReader(ISAXXMLReader **ppReader)
{
if (ppReader == NULL)
{
return E_INVALIDARG;
}

CComPtr<ISAXXMLReader> spReader = GetReader();
if (spReader.p != NULL)
{
*ppReader = spReader.Detach();
return S_OK;
}
return TClient::GetClientReader(ppReader);
}

} // namespace StockQuote

Jraven at 2007-9-8 > top of Msdn Tech,Smart Device Development,Smart Devices General...