views:

414

answers:

3

after successful coInitialize and cocreateinstance (COM server registration is perfect).. When i access a method in class it returns the error: "First-chance exception in XYZ.exe (OLEAUT32.DLL): 0xC0000005: Access Violation".

By step by step debugging i found it gives this error while calling

// make the call
SCODE sc = m_lpDispatch->Invoke(dwDispID, IID_NULL, 0, wFlags, &dispparams, pvarResult, &excepInfo, &nArgErr);

in OLEDIST2.CPP file.

please help

A: 

Right now I can think of following checks:

  • Just check if you have a chance to debug and see the value of m_lpDispatch. Whether the value is proper?( not NULL)
  • Just check whether accidentally CoUninitialize() has been called ?
  • Just check whether COM object is properly reference counted ?
aJ
A: 

Based on your code, the only thing that immediately jumps out is that m_lpDispatch could be NULL or an invalid pointer. Nothing else in that line should lead to an access violation as it doesn't actually access any memory.

If you can confirm that m_lpDispatch is indeed a valid variable it's possible it's a method being called by Invoke that's causing the problem. If so then you might want to turn on first chance exception handling for access violations in Visual Studio.

  • Go to: Debug -> Exceptions -> Win32 Exceptions
  • Check "Access Violation"

Then run your scenario under the debugger. It will cause visual studio to break at the point of the access violation. That should make it a bit more obvious where the actual problem is.

JaredPar
+1  A: 

Hi all, thanks for your time.

the problem is solved at my end.

Problem lies in importing the type library (tlb) of the COM server in to my client application. Because of which, object gets a corrupted pointer. when a member function is called it gives ACCESS VOILATION error.

I actually imported the typelibrary in my Visual C++ application using "CLASS WIZARD" as mentioned @ MSDN link: http://msdn.microsoft.com/en-us/library/aa279228(VS.60).aspx Which actually caused the above problem.

Later I found by importing typelibrary using simple #import "xyz.tlb" it generates two files .tlh and .tli files which also contains all the classes and member function definitions. When i used these files in my project it worked.

Sorry for bothering you......

thanks and regards sandeep r.

You might want to "accept" this answer since it documents how the problem was actually solved...
RBerteig