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. Managed C++/CLI
  4. Newbie: Using a com object in VC 7.1

Newbie: Using a com object in VC 7.1

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++comcsharpjava
6 Posts 3 Posters 0 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.
  • E Offline
    E Offline
    ebruinsma
    wrote on last edited by
    #1

    Hello, After trying to figure this out for days, and getting more and more frustrated, I decided that I need some help with my problem. I'm working in Microsoft Visual C++ .NET version 2003 Standard, an just learnt from posting in the Visual C++ forum that I'm using managed C++, so I'm reposting my question in this forum. My problem is this, I'm trying to create a webservice that allows me to run Java scripts in an Adobe InDesign instance. I've got sample code of how someone else created it in Visual Basic, but I've only got visual c++ v7.1 (bought it for an InDesign plugin Project, wich we're not going to do because it's just to complicated, and the Javascript seems to be enough for our needs) Seeing that the only code that he needed to insert himself is about 8 lines, and the rest was automaticly generated by starting a new webservice project, I foolishly thought that it shouldn't be that hard to recreate that functionality into c++. Creating the webservice was that easy indeed, you even got a "hello world" without even coding a single line. The VB I want to recreate is: Public Function DoScript(ByVal script As String) As String Try Dim ind As InDesign.Application ind = CreateObject("InDesign.Application.CS2", "localhost") Dim x As String = ind.DoScript(script, InDesign.idScriptLanguage.idJavascript) Return x Catch ex As Exception Return "An error occurred: " & ex.Message End Try End Function I found this article on this site and used it as a lead. http://www.codeproject.com/Purgatory/Adobe_InDesign_COM_object.asp[^] So I started by adding a reference to the InDesign com object to my project, and as far as I can see that was succesful. But when I want to compile the following code, I get the following error message: #include "stdafx.h" #include "InDesignCS2Class.h" #include "Global.asax.h" //using namespace Interop::InDesign; namespace InDesignCS2 { String* InDesignCS2Class::RunScript(String* script) { // create an InDesign instance InDesign.Application app = (InDesign.Application) COMCreateObject("InDesign.Application"); // get a reference to the current active document //InDesign.Document doc = app.ActiveDocument; // get the first page //InDesign.Page page = (InDesign.Page) doc.Pa

    G T 2 Replies Last reply
    0
    • E ebruinsma

      Hello, After trying to figure this out for days, and getting more and more frustrated, I decided that I need some help with my problem. I'm working in Microsoft Visual C++ .NET version 2003 Standard, an just learnt from posting in the Visual C++ forum that I'm using managed C++, so I'm reposting my question in this forum. My problem is this, I'm trying to create a webservice that allows me to run Java scripts in an Adobe InDesign instance. I've got sample code of how someone else created it in Visual Basic, but I've only got visual c++ v7.1 (bought it for an InDesign plugin Project, wich we're not going to do because it's just to complicated, and the Javascript seems to be enough for our needs) Seeing that the only code that he needed to insert himself is about 8 lines, and the rest was automaticly generated by starting a new webservice project, I foolishly thought that it shouldn't be that hard to recreate that functionality into c++. Creating the webservice was that easy indeed, you even got a "hello world" without even coding a single line. The VB I want to recreate is: Public Function DoScript(ByVal script As String) As String Try Dim ind As InDesign.Application ind = CreateObject("InDesign.Application.CS2", "localhost") Dim x As String = ind.DoScript(script, InDesign.idScriptLanguage.idJavascript) Return x Catch ex As Exception Return "An error occurred: " & ex.Message End Try End Function I found this article on this site and used it as a lead. http://www.codeproject.com/Purgatory/Adobe_InDesign_COM_object.asp[^] So I started by adding a reference to the InDesign com object to my project, and as far as I can see that was succesful. But when I want to compile the following code, I get the following error message: #include "stdafx.h" #include "InDesignCS2Class.h" #include "Global.asax.h" //using namespace Interop::InDesign; namespace InDesignCS2 { String* InDesignCS2Class::RunScript(String* script) { // create an InDesign instance InDesign.Application app = (InDesign.Application) COMCreateObject("InDesign.Application"); // get a reference to the current active document //InDesign.Document doc = app.ActiveDocument; // get the first page //InDesign.Page page = (InDesign.Page) doc.Pa

      G Offline
      G Offline
      georgeraafat
      wrote on last edited by
      #2

      The 'using' statement should do the trick. Why do you have it commented out? gmileka

      E 1 Reply Last reply
      0
      • G georgeraafat

        The 'using' statement should do the trick. Why do you have it commented out? gmileka

        E Offline
        E Offline
        ebruinsma
        wrote on last edited by
        #3

        I had this commented out, and some other parts, because i've been trying to combine different examples I found on the net. And the "using" doesn't seem to make a difference, while I still get the same "error C2065: 'InDesign' : undeclared identifier " error.:( Erik

        G 1 Reply Last reply
        0
        • E ebruinsma

          Hello, After trying to figure this out for days, and getting more and more frustrated, I decided that I need some help with my problem. I'm working in Microsoft Visual C++ .NET version 2003 Standard, an just learnt from posting in the Visual C++ forum that I'm using managed C++, so I'm reposting my question in this forum. My problem is this, I'm trying to create a webservice that allows me to run Java scripts in an Adobe InDesign instance. I've got sample code of how someone else created it in Visual Basic, but I've only got visual c++ v7.1 (bought it for an InDesign plugin Project, wich we're not going to do because it's just to complicated, and the Javascript seems to be enough for our needs) Seeing that the only code that he needed to insert himself is about 8 lines, and the rest was automaticly generated by starting a new webservice project, I foolishly thought that it shouldn't be that hard to recreate that functionality into c++. Creating the webservice was that easy indeed, you even got a "hello world" without even coding a single line. The VB I want to recreate is: Public Function DoScript(ByVal script As String) As String Try Dim ind As InDesign.Application ind = CreateObject("InDesign.Application.CS2", "localhost") Dim x As String = ind.DoScript(script, InDesign.idScriptLanguage.idJavascript) Return x Catch ex As Exception Return "An error occurred: " & ex.Message End Try End Function I found this article on this site and used it as a lead. http://www.codeproject.com/Purgatory/Adobe_InDesign_COM_object.asp[^] So I started by adding a reference to the InDesign com object to my project, and as far as I can see that was succesful. But when I want to compile the following code, I get the following error message: #include "stdafx.h" #include "InDesignCS2Class.h" #include "Global.asax.h" //using namespace Interop::InDesign; namespace InDesignCS2 { String* InDesignCS2Class::RunScript(String* script) { // create an InDesign instance InDesign.Application app = (InDesign.Application) COMCreateObject("InDesign.Application"); // get a reference to the current active document //InDesign.Document doc = app.ActiveDocument; // get the first page //InDesign.Page page = (InDesign.Page) doc.Pa

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          you use the variable InDesign, but it is declared nowhere... :doh:


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          E 1 Reply Last reply
          0
          • T toxcct

            you use the variable InDesign, but it is declared nowhere... :doh:


            TOXCCT >>> GEII power

            [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

            E Offline
            E Offline
            ebruinsma
            wrote on last edited by
            #5

            I have added the reference to the com object, what do I have to do to get an object of the type InDesign.Application? Or am I going wrong way with this :confused: Let me clearify what I'm trying to get: I want a simple webservice, that will allow me to call the 'runscript' method on the Adobe InDesign COM object. The webservice I was able to create, now I only need to call the runscript from the webservice and return it's results. So if someone knows a different way to do this in c++, your help is more than welcome... TIA Erik

            1 Reply Last reply
            0
            • E ebruinsma

              I had this commented out, and some other parts, because i've been trying to combine different examples I found on the net. And the "using" doesn't seem to make a difference, while I still get the same "error C2065: 'InDesign' : undeclared identifier " error.:( Erik

              G Offline
              G Offline
              georgeraafat
              wrote on last edited by
              #6

              The following line: InDesign.Application app = (InDesign.Application) COMCreateObject("InDesign.Application"); should be: InDesign::Application app = (InDesign::Application) COMCreateObject("InDesign.Application"); (not sure what COMCreateObject returns). In general, whenever you are qualifying something with a namespace, use the scope operator ::. Unlike C#, C++ differentiates between types and instance of types. For type qualification, it's type::identifier or namespace::identifier For instance qualification, it's instance.identifier or instance->identifier (those are only examples of course). C# always uses the dot operator no matter what... gmileka

              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