Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. How to get IDispatch of an instance of Excel in C++ DLL called from Excel xla?

How to get IDispatch of an instance of Excel in C++ DLL called from Excel xla?

Scheduled Pinned Locked Moved COM
c++comhelptutorialquestion
4 Posts 2 Posters 14 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leo 0
    wrote on last edited by
    #1

    Hi I have created a c++ dll which works great in excel 2000, as I launch it as a com add-in, and get access to the IDispatch of the calling instance of excel via OnConnection (IDTExtensibility2). I would like to be able to launch the dll from excel 97, via an xla (or xll), which is not a problem, but I do not know how to get the IDispatch of the instance of excel that has the xla (or xll) running. (Excel.Application is no good, as it only finds the first instance of Excel.) If anyone knows the answer, please let me know Thanks!

    L L 2 Replies Last reply
    0
    • L leo 0

      Hi I have created a c++ dll which works great in excel 2000, as I launch it as a com add-in, and get access to the IDispatch of the calling instance of excel via OnConnection (IDTExtensibility2). I would like to be able to launch the dll from excel 97, via an xla (or xll), which is not a problem, but I do not know how to get the IDispatch of the instance of excel that has the xla (or xll) running. (Excel.Application is no good, as it only finds the first instance of Excel.) If anyone knows the answer, please let me know Thanks!

      L Offline
      L Offline
      leo 0
      wrote on last edited by
      #2

      Hi I have worked out how to do it from an xla , but if anyone knows how to do the same in an xll please let me know. From Auto_Open() sub of xla, pass Application to function in DLL i.e. in XLA !declaration of function in DLL Private Declare Function InitExcel97 Lib "MyDLL.dll" (ByVal app As Object) As Long Public Sub Auto_Open() Result = InitExcel97(Application) … End Sub in DLL extern "C" __declspec( dllexport ) LONG WINAPI InitExcel97(LPDISPATCH Application) { long result; g_pApplication = Application; //global declaration IDispatch* g_pApplication; theApp.InitializeExcel(); //calls same code as if launched by com addin in Excel2000 …. return result; }

      1 Reply Last reply
      0
      • L leo 0

        Hi I have created a c++ dll which works great in excel 2000, as I launch it as a com add-in, and get access to the IDispatch of the calling instance of excel via OnConnection (IDTExtensibility2). I would like to be able to launch the dll from excel 97, via an xla (or xll), which is not a problem, but I do not know how to get the IDispatch of the instance of excel that has the xla (or xll) running. (Excel.Application is no good, as it only finds the first instance of Excel.) If anyone knows the answer, please let me know Thanks!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Reference Article;- MSDN Q192348 & Q216686. This uses automation. Regards, K M Bansal

        L 1 Reply Last reply
        0
        • L Lost User

          Reference Article;- MSDN Q192348 & Q216686. This uses automation. Regards, K M Bansal

          L Offline
          L Offline
          leo 0
          wrote on last edited by
          #4

          Hi, Those examples do not relate to my question, for each example creates its own instance of excel, which it then uses. I want to attach to an existing instance, and using AttachDispatch with Excel.Application, is no solution as it will only find the first instance of excel. As I mentioned in my prior message, it is easy from a xla, but I would still be curious how to find the correct IDistatch from an xll (or any c++ written application). For your information, a much better method than proposed in Q192348 is Q186427. The closest MSDN example to my problem is found in Q190985, but there, Excel is running as a container. Regards Leo

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups