Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / December 2005



Tip: Looking for answers? Try searching our database.

Creating events in VC++ / ATL, receiving in VB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joachim - 10 Dec 2005 12:09 GMT
I'm trying to figure out how events are generated in VC++ ATL and then
received in VB. I already have a working example to which I want to add an
event function. In the IDL file I have added the function name to the
dispinterface as follows:

[id(10)] void Hover(BSTR someString);

Then, when I want to fire the event I call

obj->Fire_Hover(someString);

and the Fire_Hover function:

VOID Fire_Hover(BSTR someString)
{
T* pT = static_cast<T*>(this);
int nConnectionIndex;
CComVariant* pvars = new CComVariant[1];
int nConnections = m_vec.GetSize();

for (nConnectionIndex = 0; nConnectionIndex < nConnections;
nConnectionIndex++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
pT->Unlock();
IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch != NULL)
{
pvars[0] = someString;
DISPPARAMS disp = { pvars, NULL, 1, 0 };
pDispatch->Invoke(0x10, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&disp, NULL, NULL, NULL);
}
}
delete[] pvars;
}

Now, probably there's something I haven't done since the VB function

myObj_Hover(ByVal someString As String)

is not called. The Hover event appears for the class in the object
browser of VB. What have I forgotten?
Ralph - 10 Dec 2005 13:46 GMT
> I'm trying to figure out how events are generated in VC++ ATL and then
> received in VB. I already have a working example to which I want to add an
[quoted text clipped - 40 lines]
> is not called. The Hover event appears for the class in the object
> browser of VB. What have I forgotten?
Ralph - 10 Dec 2005 13:49 GMT
> I'm trying to figure out how events are generated in VC++ ATL and then
> received in VB. I already have a working example to which I want to add an
[quoted text clipped - 40 lines]
> is not called. The Hover event appears for the class in the object
> browser of VB. What have I forgotten?

Private WithEvents myObj As myObject  ???

Then select the events from the Object and Event dropdown list at the top of
the edit window. If you don't see them listed - then something else is
wrong.

-ralph
Joachim - 10 Dec 2005 14:17 GMT
> > I'm trying to figure out how events are generated in VC++ ATL and then
> > received in VB. I already have a working example to which I want to add an
[quoted text clipped - 42 lines]
>
> Private WithEvents myObj As myObject  ???

I don't know. It is created within the GUI. Where can I find that?

> Then select the events from the Object and Event dropdown list at the top of
> the edit window. If you don't see them listed - then something else is
> wrong.

The Hover function is listed in the dropdown box too.

> -ralph

Thanks,
Joachim
Ralph - 10 Dec 2005 16:51 GMT
> > > I'm trying to figure out how events are generated in VC++ ATL and then
> > > received in VB. I already have a working example to which I want to add an
[quoted text clipped - 55 lines]
> Thanks,
> Joachim

Oh, I was paying poor attention. <g>
Is this a component? ie, is something you 'drop' on a VB form?

As I have been using ATL and custom Addins (they handle all the details) for
so long, I'm not sure I am qualified to detect any apparent error in your
published code. It looks correct.

The IDL looks a little funny. Are you sure you have connected the method to
the interface?

But perhaps this might help. VB while avoiding many COM interfaces, supports
the usual in a very simple, if not practically 'transparent', manner. ie, if
you create a reference or add a component (the latter shows up on toolbox to
the left) and VB 'sees' it - offering an opportunity to select the event,
showing Intellisense, etc. Then it is the C++ side of things that is hosed.
Raw guess, your published interface is there, VB 'sees' a COM interface -
you just haven't 'connected' your method to it.

You may want to re-post in several of the VC++ newsgroups...
   microsoft.public.vc. ...
Provide a snippet of your idl (coclass,...) and snippets from all headers
where you reference your event.

-ralph
Joachim - 12 Dec 2005 10:15 GMT
Thanks Ralph,

What do you think is wrong with the IDL? The library looks like this:

[
    uuid(8DAFBF7E-46B0-40E9-87B3-8E5F61631159),
    version(1.0),
    helpstring("MYOWNLib 1.0 Type Library")
]
library MYOWNLib
{
    importlib("stdole32.tlb");
    importlib("stdole2.tlb");

    [
        uuid(6156B03D-186D-4DD1-AA48-92A92E5A5A72)
    ]
    dispinterface _IEvents
    {
        properties:
        methods:
/* A few other methods (that works!) */
...
        [id(10)]
        HRESULT Hover([in] BSTR someString);
    };

The coclass looks like this:

    [
        uuid(3D010728-CFD8-4ED5-ADAA-DA455E92C008),
        helpstring("Dummy Class"),
    ]
    coclass Dummy
    {
        [default] interface IMyOwnInterface;
        [default, source] interface _IEvents;
    };

I call the class dummy since the real implementation is in a completely
different project where I have another class to implement the interface.

Any ideas where I could have forgot about the connection? (I'll give a link
to this thread from the vc.atl discussion group as well - the discussion in
vc.atl can be found at
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.atl&tid
=4bb89a6f-4776-46c0-9a81-406aadfde67c&lang=en&cr=US&p=1
)

> > > > I'm trying to figure out how events are generated in VC++ ATL and then
> > > > received in VB. I already have a working example to which I want to
[quoted text clipped - 83 lines]
>
> -ralph
vivekuniq - 12 Dec 2005 10:59 GMT
did u add "withEvents" while declaring the object?

Dim WithEvents Obj As IMyATL

long time before i forgot to add this "withevents" in the client and i was
searching too much in the IDL.

-vivek
Joachim - 15 Dec 2005 14:29 GMT
Thanks Mr vivekuniq,

It is an object which I dragged in the GUI only. It is not declared at all
like that.

Joachim

> did u add "withEvents" while declaring the object?
>
[quoted text clipped - 4 lines]
>
> -vivek
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.