Machhindra

Hi,

I have upgraded vc5 ATL server DLL to vc8 and vb5 client to vb6. I have a VC8 Atl server dll that I would like to fire an event to then be used by VB6 using the With Events keyword. BUT when DLL raises event, it throws an exception at the following statement..

pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL,NULL, NULL);

It was working fine with my original source code in vc5 and vb5 client.

Any ideas

Thanks,

Mac




Re: Visual C++ General Invoke throws an exception with VC8 ported code...

aao123

what is the exception



Re: Visual C++ General Invoke throws an exception with VC8 ported code...

Machhindra

Hi,

Thanks for reply..

I get following exception

Unhandled exception at 0x660c9b0e in SampleClient.exe: 0xC0000005: Access violation reading location 0x00000034.

Call stack trace is as follows..

msvbvm60.dll!660c9b0e()
[Frames below may be incorrect and/or missing, no symbols loaded for msvbvm60.dll]
ntdll.dll!7c91056d()
> CProxy_IPrSampleEvents<CPrSample>::Fire_CreateFinish() Line 24 C++

Thanks,

Mac






Re: Visual C++ General Invoke throws an exception with VC8 ported code...

aao123

I assume you tried to attach debugger to your VB process and line 24 is ¡°pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL,NULL, NULL);¡±. Could you list idl for CreateFinish and show how you populate disp parameters Parameters would be my first guess





Re: Visual C++ General Invoke throws an exception with VC8 ported code...

Machhindra

thanks again for reply..

This is how my CreateFinish looks like...

void Fire_CreateFinish()

{

T* pT = (T*)this;

pT->Lock();

IUnknown** pp = m_vec.begin();

while (pp < m_vec.end())

{

if (*pp != NULL)

{

DISPPARAMS disp = { NULL, NULL, 0, 0 };

IDispatch* pDispatch = reinterpret_cast<IDispatch*>(*pp);

pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL,NULL, NULL);

}

pp++;

}

pT->Unlock();

}






Re: Visual C++ General Invoke throws an exception with VC8 ported code...

Machhindra

This is my idl file...

[
uuid(8a907ee0-6ec0-11d2-875e-00c04fd12c85),
helpstring("Event interface for Sample Class")
]
dispinterface _IPrSampleEvents
{
properties:
//None
methods:
[id(1)] void CreateFinish();
};
[
uuid(E96A9EB0-4129-11D2-B7BA-00C04FD11883),
helpstring("PrSample Class")
]
coclass PrSample
{
[default] interface IPrSample;
[default, source] dispinterface _IPrSampleEvents;
}






Re: Visual C++ General Invoke throws an exception with VC8 ported code...

aao123

Yes seems simple ... Hmmm. When you add VB object to m_vec do you call AddRef



Re: Visual C++ General Invoke throws an exception with VC8 ported code...

Machhindra

Hi,

Thanks for your time..

I think, m_vec is memeber of IConnectionPointImpl. How to add AddRef while adding vbobject This will be done in ::Advise() method.

Could you please explain me in detail

Thanks,

Mac






Re: Visual C++ General Invoke throws an exception with VC8 ported code...

aao123

Please forgive me ¨C I did not do COM for long time, so I am going through ¡°usual suspects¡± check-list(Check for obvious cpp bugs, Check IDL for improper signatures). Your bug seems to be related to your VB object in the collection being prematurely released (IUnknown->Release() called to soon, or AddRef not called at all). I am trying to figure out were it is happening. The simplest way to check is to AddRef before you call Advise. It will generate memory leak, but if I am right your application will run fine. Could you please try that





Re: Visual C++ General Invoke throws an exception with VC8 ported code...

Machhindra

Hi,

It was properly working with VC5 and VB5.

I tried AddRef to vb object in overrided advise() method, but still the problem persists. Well I don't know how to call AddRef before Advise(), as it will be called automatically by vb I am using object with "withevent" in VB6.

Thanks for your time and consideration...

Mac






Re: Visual C++ General Invoke throws an exception with VC8 ported code...

aao123

well VC5 was not ... hmmm how to say it ... very successful. VB5 was a disaster. It is possible they were very forgiving, compare to much more stable but unforgiving 6s . Anyway that's all gone, we have problem at hand. Is it possible to publish more of your application here(c++ and VB code) I am guessing here , but looking at the code usually helps. If it is not trade secret , of course. If it is difficult lets try to isolate parts that create VB objects and dispose of them





Re: Visual C++ General Invoke throws an exception with VC8 ported code...

Machhindra

Hi,

My sample idl and CreateFinish() event implementation is given in above posts.

This is how VB6 client handles the event fired from the ATL server DLL...

Dim withevents theSample as IPrSample

Private Sub theSample_CreateFinish()

..........

End Sub

Lets see if it helps you in diagnostic the problem.

I tried creating ATL server in VS 2005 and client in VB6. It works fine. I don;t know what went worng in the migration from VC5 to VC8.

Thanks

Mac






Re: Visual C++ General Invoke throws an exception with VC8 ported code...

aao123

Sorry I did not explain well. What I am thinking is that you have a bug in place where you create the VB object.



Re: Visual C++ General Invoke throws an exception with VC8 ported code...

Machhindra

Hi

        Problem is identified and partially resolved.

In my com dll , one "thread" is forked which fire the event  "Fire_CreateFinish". The VB6 client should get that event and process it further.  This mechanism works in VC5 and VB5.  BUT does not work in upgraded VC8 and VB6 client.

When i tried to fire the same event instead of creating the thread, it works fine and VB6 client receives the event. 

What could be the reason Why it is failing if we fire the event from a secondary thread

Your help is greatly appreciated...

Thanks,

Mac

 






Re: Visual C++ General Invoke throws an exception with VC8 ported code...

Machhindra

Hi

Still I am searching for solution... Why it is failing if we fire the event from a secondary thread

Your help is greatly appreciated..

mac