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. My problem is this, I'm rying 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.Pages[1]; //1e pagina // get the first textframe //InDesign.TextFrame frame = (InDesign.Tex -
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. My problem is this, I'm rying 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.Pages[1]; //1e pagina // get the first textframe //InDesign.TextFrame frame = (InDesign.TexYou are working in C++ right ? The code of the article is for managed (I suppose because I'm not familiar with the syntax). Or at least, this isn't C++. That's why you get errors.
-
You are working in C++ right ? The code of the article is for managed (I suppose because I'm not familiar with the syntax). Or at least, this isn't C++. That's why you get errors.
-
Hi Cedric, Yes, I'm working in Microsoft Visual C++ .NET version 2003 Standard. That will be the problem then, but can you tell me what is the correct way to use a/the InDesign com object, because I'm completely lost. Erik
ebruinsma wrote:
I'm working in Microsoft Visual C++ .NET version 2003 Standard.
this doesn't mean in which language you code (i leave in france, but could be speaking english, german or chinese). Cedric's question is : "do you program in Native C++, Managed C++, C#, VB.NET..." ?
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
ebruinsma wrote:
I'm working in Microsoft Visual C++ .NET version 2003 Standard.
this doesn't mean in which language you code (i leave in france, but could be speaking english, german or chinese). Cedric's question is : "do you program in Native C++, Managed C++, C#, VB.NET..." ?
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
Sorry, I don't know what the diference is between those languages:confused:, I thought that when I use MicroSoft's visual C++ that I was using c++, with their compiler. How can I see what I'm using. What I did to create the project, was: Choose new project from the file menu, and choose: visual c++ project/.net/ ASP.NET web service. So, my question still is what do I need to do, to get a webservice that allows me to call runscrip in InDesign. TIA Erik.
-
Sorry, I don't know what the diference is between those languages:confused:, I thought that when I use MicroSoft's visual C++ that I was using c++, with their compiler. How can I see what I'm using. What I did to create the project, was: Choose new project from the file menu, and choose: visual c++ project/.net/ ASP.NET web service. So, my question still is what do I need to do, to get a webservice that allows me to call runscrip in InDesign. TIA Erik.
ebruinsma wrote:
I thought that when I use MicroSoft's visual C++ that I was using c++, with their compiler.
yes, that is an obvious thought. unfortunately, MS Visual C++ .NET 2003 (and later) compiler understands 2 different kind of C++ : Native (pure console, Win32, MFC/ATL/WTL projects) Managed (the one compiled for .net framework). it seems that you created a managed C++ project, so you code in Managed C++ (also called C++/CLI in newer version of the language). unfortunately, this is not the right forum to ask such a question (most people here don't know MC++), so, i suggest you to ask it here[^] to get better answers ;)
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
ebruinsma wrote:
I thought that when I use MicroSoft's visual C++ that I was using c++, with their compiler.
yes, that is an obvious thought. unfortunately, MS Visual C++ .NET 2003 (and later) compiler understands 2 different kind of C++ : Native (pure console, Win32, MFC/ATL/WTL projects) Managed (the one compiled for .net framework). it seems that you created a managed C++ project, so you code in Managed C++ (also called C++/CLI in newer version of the language). unfortunately, this is not the right forum to ask such a question (most people here don't know MC++), so, i suggest you to ask it here[^] to get better answers ;)
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]