Solved

OLE access violation with Excel

Posted on 2003-12-08
9
405 Views
Last Modified: 2013-11-25
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
0
Comment
Question by:LittlePerson
  • 4
  • 3
  • 2
9 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9896012
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
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 50 total points
ID: 9896020
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
 

Author Comment

by:LittlePerson
ID: 9896027
That had crossed my mind, thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9896059
Forgot the following for the code snippet
      LPDISPATCH pDisp;
      LPUNKNOWN pUnk;
0
 
LVL 10

Expert Comment

by:Duy Pham
ID: 9897331
Try this :

CreateDispatch("ExcelApplication", NULL);
0
 

Author Comment

by:LittlePerson
ID: 9912631
Try this :

CreateDispatch("ExcelApplication", NULL);

Did not work
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9912666
Have you tried it via the clsid yet?
0
 

Author Comment

by:LittlePerson
ID: 9912811
No, sorry I haven;t yet. I'll try soon. I've been tracking down the installation disks!

Thanks
0
 
LVL 10

Expert Comment

by:Duy Pham
ID: 9919386
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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best way to accomplish this task? 3 93
wordmultiple challenge 12 157
Thin secure Windows 10 5 108
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,328
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question