Solved

OLE access violation with Excel

Posted on 2003-12-08
9
397 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
Comment Utility
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
Comment Utility
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
Comment Utility
That had crossed my mind, thanks.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Forgot the following for the code snippet
      LPDISPATCH pDisp;
      LPUNKNOWN pUnk;
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 10

Expert Comment

by:Duy Pham
Comment Utility
Try this :

CreateDispatch("ExcelApplication", NULL);
0
 

Author Comment

by:LittlePerson
Comment Utility
Try this :

CreateDispatch("ExcelApplication", NULL);

Did not work
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Have you tried it via the clsid yet?
0
 

Author Comment

by:LittlePerson
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 70
fix34  challenge 9 95
Which Microsoft MSDN Package Is The One I need? 3 36
Explain Unit of Work pattern 2 46
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now