Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OLE access violation with Excel

Posted on 2003-12-08
9
Medium Priority
?
411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 45

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 45

Accepted Solution

by:
AndyAinscow earned 200 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 45

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 45

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…

618 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