CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2025
    Posts
    1

    Unhappy Trying to run Excel - can't create dispatch (Visual Studio 6 C++)

    Hi there! It seems I forgot some nuances in my own old code - take a look please:
    ...
    // Excel app initialization
    _Application oApp;
    oApp.CreateDispatch("Excel.Application");
    if (!oApp)
    {
    AfxMessageBox("Can't run Excel.");
    return;
    }
    ...
    So it works in my very old project (just compiled it from archive) but if try to copy/paste this part of code into another project - I receive "Can't run Excel" modal window while running my current project. I mean - same VM (Windows XP), same Visual Studio 6 and same Office (2003). So I already checked *.cpp and *.h files (excel9.cpp and excel9.h) - they are connected to the project. What could I have forgotten to check? Please help.

  2. #2
    Join Date
    Nov 2018
    Posts
    154

    Re: Trying to run Excel - can't create dispatch (Visual Studio 6 C++)

    I'd hazard a guess that this is an ANSI/Unicode mess.

    Really ancient VS assumed ANSI (like pre-2000).

    Really new VS assumes Unicode (like post-2010).

    Somewhere in the middle, you had to tell VS which kind of API you were using.

    For most purposes, you can insulate yourself with copious use of _T() macros.
    Code:
    oApp.CreateDispatch(_T("Excel.Application"));
    The rabbit hole starts here:
    https://devblogs.microsoft.com/oldne...12-00/?p=40643

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured