OLE access violation with Excel

Hi

I have an application in which I automate excel, its been a while since I
looked at it and I am having the problem that when the app is in debug
mode an access violation is thrown when I reach the following line

XL::_Application xlApp;

if(!xlApp.CreateDispatch("Excel.Application"))                               /// Access violation is here
      AfxMessageBox("Unable to create dispatch for Excel");


In release mode every thing is working fine, does anyone have any ideas
what might be happening here?

Thanks in advance

LittlePerson
LittlePersonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Is the following of use?

      CLSID clsid;

      ::CLSIDFromProgID(L"Excel.Application", &clsid); // from registry


            if(!m_pExcelApp->CreateDispatch(clsid))
            {
                  TRACE("Attatching after create\n");
                  if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK)
                  {
                        TRACE("attaching after create - with the prog\n");
                        VERIFY(pUnk->QueryInterface(IID_IDispatch, (void**) &pDisp) == S_OK);
                        m_pExcelApp->AttachDispatch(pDisp, false);      //I want to keep Excel running so I don't auto-detatch
                        pUnk->Release();
                  }
0
AndyAinscowFreelance programmer / ConsultantCommented:
You have had a few questions recently with things not working in debug mode but working in release mode.  Maybe you ought to consider de-installing, rebooting and installing VC++.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LittlePersonAuthor Commented:
That had crossed my mind, thanks.
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

AndyAinscowFreelance programmer / ConsultantCommented:
Forgot the following for the code snippet
      LPDISPATCH pDisp;
      LPUNKNOWN pUnk;
0
Duy PhamFreelance IT ConsultantCommented:
Try this :

CreateDispatch("ExcelApplication", NULL);
0
LittlePersonAuthor Commented:
Try this :

CreateDispatch("ExcelApplication", NULL);

Did not work
0
AndyAinscowFreelance programmer / ConsultantCommented:
Have you tried it via the clsid yet?
0
LittlePersonAuthor Commented:
No, sorry I haven;t yet. I'll try soon. I've been tracking down the installation disks!

Thanks
0
Duy PhamFreelance IT ConsultantCommented:
Did you try to call CoInitialize(NULL) for enabling COM component in your app ?
If you did, could you paste your code up for us to see it clearly ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.