Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Using DataSocket in an ATL server without GUI

I am working on a free-threaded ATL server (exe). In this program I create a
DataSocket object using a smart pointer and CoCreateInstance(..). This works
fine. I also want to sink the DataSocket events (OnDataUpdated and
OnStatusUpdated), but can't get it right.

My event class inherits from "public IDispEventImpl<....> and I define the
two events
in SINK_ENTRY's. I connect to the DataSocket events using
DispEventAdvise(..).
Library info is imported using "#import "C:\WINNT\System32\nids.dll"
named_guids

My sink function "OnDataUpdated" fires correctly but I am not allowed to
access
the event input parameter: (struct ICWData * Data) ???????

This is the event declarations:
HRESULT __stdcall OnDataUpdated (st
ruct ICWData * Data);
HRESULT __stdcall OnStatusUpdated (enum CWDSStatus Status, long Error,
_bstr_t Message);

The error message in debug-mode is: "First-chance exception in
XXXServer.exe: 0xC0000005: Access
Violation."

Does anybody have any idea whats causing this error (I suspect that the
ICWData pointer needs some kind of marshalling)?

Thanks,
Arve Haavik
Cardiac AS
0 Kudos
Message 1 of 3
(3,694 Views)
Arve,
There are a couple of minor problems with your approach. First, you must
#import "C:\WINNT\System32\cwds.ocx". The interface you are using is an
internal one and not intended for use from other programs. Note that OLEVIEW
gives you an error if you try to open nids.dll in the type library viewer.
Given that you are importing the wrong .dll, I am not sure how you were able
to connect. I got access violations when I tried this.

This means that you have to change your code a bit. You will have to define
the GUID for the type library so that you can pass it as a template
parameter to the IDispEventImpl base class declaration. Also, the GUID
identifiers for the datasocket interface, datasocket data interface,
datasocket events interface, and datasocket coclass are different when you
import the .ocx.

I think the problem you are having with accessing ICWData * (which will be
CWDSLib::_DCWData * when you import the .ocx) is that you are trying to
access it as a dual interface, which it is not. When you #import the .dll,
VC for some reason thinks that the datasocket data interface is dual. It
therefore generates wrappers that call directly into the datasocket data
interface methods. In fact, the datasocket data interface is not dual, so
you must call its methods through invoke. When you #import the .ocx, VC
generates the correct wrappers. I will email you a sample ATL server and
MFC client program that demonstrates how to do this. I will see about
getting this sample posted on dzone.

David Rohacek
National Instruments

"Arve Haavik" wrote in message
news:39fd930d@newsgroups.ni.com...
> I am working on a free-threaded ATL server (exe). In this program I create
a
> DataSocket object using a smart pointer and CoCreateInstance(..). This
works
> fine. I also want to sink the DataSocket events (OnDataUpdated and
> OnStatusUpdated), but can't get it right.
>
> My event class inherits from "public IDispEventImpl<....> and I define the
> two events
> in SINK_ENTRY's. I connect to the DataSocket events using
> DispEventAdvise(..).
> Library info is imported using "#import "C:\WINNT\System32\nids.dll"
> named_guids
>
> My sink function "OnDataUpdated" fires correctly but I am not allowed to
> access
> the event input parameter: (struct ICWData * Data) ???????
>
> This is the event declarations:
> HRESULT __stdcall OnDataUpdated (struct ICWData * Data);
> HRESULT __stdcall OnStatusUpdated (enum CWDSStatus Status, long Error,
> _bstr_t Message);
>
> The error message in debug-mode is: "First-chance exception in
> XXXServer.exe: 0xC0000005: Access
> Violation."
>
> Does anybody have any idea whats causing this error (I suspect that the
> ICWData pointer needs some kind of marshalling)?
>
> Thanks,
> Arve Haavik
> Cardiac AS
>
>
0 Kudos
Message 2 of 3
(3,694 Views)
My previous post was correct only for DataSocket 3.0. In DataSocket 4.0,
the control was moved to nids.dll, so that is the file you must #import.
The event mechanism is not working properly in 4.0 due to a change in the
type library that exposes an ATL bug. The bug is reported in the MSDN
Knowledge Base. Its ID is Q237771. I have an ATL example that uses
DataSocket 4.0 and incorporates the workaround for the ATL bug if anyone in
addition to Arve is interested.

- David

"David Rohacek" wrote in message
news:39fe4969@newsgroups.ni.com...
> Arve,
> There are a couple of minor problems with your approach. First, you must
> #import "C:\WINNT\System32\cwds.ocx". The interface you are using is an
> internal one and not intended for use from other programs. Note that
OLEVIEW
> gives you an error if you try to open nids.dll in the type library viewer.
> Given that you are importing the wrong .dll, I am not sure how you were
able
> to connect. I got access violations when I tried this.
>
> This means that you have to change your code a bit. You will have to
define
> the GUID for the type library so that you can pass it as a template
> parameter to the IDispEventImpl base class declaration. Also, the GUID
> identifiers for the datasocket interface, datasocket data interface,
> datasocket events interface, and datasocket coclass are different when
you
> import the .ocx.
>
> I think the problem you are having with accessing ICWData * (which will be
> CWDSLib::_DCWData * when you import the .ocx) is that you are trying to
> access it as a dual interface, which it is not. When you #import the
..dll,
> VC for some reason thinks that the datasocket data interface is dual. It
> therefore generates wrappers that call directly into the datasocket data
> interface methods. In fact, the datasocket data interface is not dual, so
> you must call its methods through invoke. When you #import the .ocx, VC
> generates the correct wrappers. I will email you a sample ATL server and
> MFC client program that demonstrates how to do this. I will see about
> getting this sample posted on dzone.
>
> David Rohacek
> National Instruments
>
> "Arve Haavik" wrote in message
> news:39fd930d@newsgroups.ni.com...
> > I am working on a free-threaded ATL server (exe). In this program I
create
> a
> > DataSocket object using a smart pointer and CoCreateInstance(..). This
> works
> > fine. I also want to sink the DataSocket events (OnDataUpdated and
> > OnStatusUpdated), but can't get it right.
> >
> > My event class inherits from "public IDispEventImpl<....> and I define
the
> > two events
> > in SINK_ENTRY's. I connect to the DataSocket events using
> > DispEventAdvise(..).
> > Library info is imported using "#import "C:\WINNT\System32\nids.dll"
> > named_guids
> >
> > My sink function "OnDataUpdated" fires correctly but I am not allowed to
> > access
> > the event input parameter: (struct ICWData * Data) ???????
> >
> > This is the event declarations:
> > HRESULT __stdcall OnDataUpdated (struct ICWData * Data);
> > HRESULT __stdcall OnStatusUpdated (enum CWDSStatus Status, long Error,
> > _bstr_t Message);
> >
> > The error message in debug-mode is: "First-chance exception in
> > XXXServer.exe: 0xC0000005: Access
> > Violation."
> >
> > Does anybody have any idea whats causing this error (I suspect that the
> > ICWData pointer needs some kind of marshalling)?
> >
> > Thanks,
> > Arve Haavik
> > Cardiac AS
> >
> >
>
>
0 Kudos
Message 3 of 3
(3,694 Views)