I am currently working on a project that is unable to link against the MFC. This precludes the use of the MFC based classes provided with Measurement Studio. I have gotten a lot of the COM code completed. I have been able to make connections to a DataSocket server without any problems. However, I am running into a bit of an issue coding a class that implements _INIDSCtlEvents so that I can get the OnDataUpdated and OnStatusUpdated handlers. I have the IUnknown and _INIDSCtlEvents members implemented. The sticking point is the implementation of the the IDispatch members that are implied by _INIDSCtlEvents.
I am able to add setup the event connection just fine. However, whenever an event is fired that I should get things get hairy.
When the GetTypeInfoCount member is called I encounter a problem. The parameter to this function is a far pointer to an unsigned int. The value that gets passed in here is 0x00000001. This obviously causes an error when I try to set the value at this pointer to 1 to indicate that my class supports type info reporting.
I was wondering if there was something that I was missing, or why the DataSocket object is passing in this bad pointer.
I appreciate your assistance. I've added a code snippet bellow illustrating what I am doing.
BSTR url;
IConnectionPointContainer *pContainer = NULL;
IConnectionPoint *pConnection = NULL;
HRESULT hr = E_UNEXPECTED;
DWORD adviseCookie;
dataSocket.CreateInstance(__uuidof(CWDataSocket));
url = SysAllocString(L"dstp://localhost/samplenum");
hr = dataSocket->QueryInterface(__uuidof(IConnectionPointContainer), (void **)&pContainer); // This returns S_OK
if (SUCCEEDED(hr))
{
hr = pContainer->FindConnectionPoint(__uuidof(_INIDSCtlEvents), &pConnection); // This returns S_OK
if (SUCCEEDED(hr))
{
IUnknown *me = NULL;
gpEventSink = new CDSEventSink();
gpEventSink->QueryInterface(__uuidof(IUnknown), (void **)&me); // This returns a pointer to the event sink
hr = pConnection->Advise(me, &adviseCookie); // This returns S_OK
}
pContainer->Release();
}
dataSocket->ConnectTo(url, cwdsReadAutoUpdate); // When this is called the GetTypeInfoCount(...) member of the gpEventSink instance of CDSEventSink gets passed an invalid pointer (0x00000001) and thus I can't set the value and return.
SysFreeString(url);
Here is my implementation of GetTypeInfoCount(...)
HRESULT CDSEventSink::GetTypeInfoCount(unsigned int FAR* pctinfo)
{
if (pctinfo == NULL) {
return E_INVALIDARG;
}
*pctinfo = 1;
return S_OK;
}
pctinfo points to the address 0x00000001 when this is called.