Newbie: Using a com object in VC 7.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 instanceInDesign.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 -
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 instanceInDesign.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.PaThe 'using' statement should do the trick. Why do you have it commented out? gmileka
-
The 'using' statement should do the trick. Why do you have it commented out? gmileka
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
-
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 instanceInDesign.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.Payou use the variable
InDesign
, but it is declared nowhere... :doh:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
you use the variable
InDesign
, but it is declared nowhere... :doh:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
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
-
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
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