|
With MC++ (VS 7.0 and 7.1), you have to do a little extra work to convert a "boxed" enum. You have to cast the "boxed" enum to an Int32* and then cast the dereferenced result to the enum:
Type* tp = __typeof(Shortcut);
Object* obj = (Enum::Parse(tp, txt));
Shortcut scut = static_cast<Shortcut>(*(dynamic_cast<Int32*>(obj)));
menuItem_action->set_Shortcut(scut);
-- modified at 12:38 Friday 5th May, 2006
|
|
|
|
|
It worked perfectly. Thank you very much.
FYI, my final code:
Object* obj = (Enum::Parse(__typeof(Shortcut), menushortcut));<br />
<br />
menuItem_action->Shortcut = static_cast<Shortcut>(* (dynamic_cast<Int32*>(obj)) );
|
|
|
|
|
Is it possible to add files to a digital camera using WIA 1.0?
Mike - I love to program!
|
|
|
|
|
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<br />
Try<br />
Dim ind As InDesign.Application<br />
ind = CreateObject("InDesign.Application.CS2", "localhost")<br />
Dim x As String = ind.DoScript(script, InDesign.idScriptLanguage.idJavascript)<br />
Return x<br />
Catch ex As Exception<br />
Return "An error occurred: " & ex.Message<br />
End Try<br />
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"<br />
#include "InDesignCS2Class.h"<br />
#include "Global.asax.h"
//using namespace Interop::InDesign;
namespace InDesignCS2<br />
{<br />
String* InDesignCS2Class::RunScript(String* script)<br />
{
// 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.Pages[1]; //1e pagina
// get the first textframe
//InDesign.TextFrame frame = (InDesign.TextFrame) page.TextFrames[1];
// write contents of textframe
//Console.WriteLine(frame.Contents.ToString());
// set contents of textframe
//frame.Contents = "Andere content";
return script;<br />
}<br />
};
error C2065: 'InDesign' : undeclared identifier
Can anyone please tell me what I'm doing wrong, or what I've forgotten to do.
TIA,
Erik Bruinsma
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
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
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 have a problem. I have been trying to output a triangle using asterisks. However I know I need to use nesting. For example: What other instructions do I need to finish this problem?
#include '<iostream>'
using namespace std;
void main()
{
int = '*';
int = counter + 1;
for(counter + 1; counter >= 10; counter = counter + 1)
{
cout << '*' << endl;
}
}
Charles Reese
|
|
|
|
|
1. Try to avoid double posting (Don't worry, sometimes it happend to me)
2. This thread should be in "Visual c++/MFC" not in "C++/CLI"
3. Is this C or C++
Charles Reese wrote: int = '*';
int = counter + 1;
4. I don't get it, something is missing.
5. The problem is very simple you need 3 for loops
<br />
for (int i = 0; i>= 10; i++)<br />
{<br />
int h=i/2;<br />
int numberofasterix = i*2+1;<br />
for (int j= 1; j>=numberofasterix ; j=++)<br />
{<br />
for (int k=h; k>=0; k--)<br />
{<br />
cout << " ";<br />
}<br />
cout << "*";<br />
}<br />
cout << endl;<br />
}
ps: I hope this works, because i currently didn't install Visual Studio 2005. Maybe the code will not work propeperly, but it is still better than yours.
|
|
|
|
|
I have a problem. I have been trying to output a triangle using asterisks. However I know I need to use nesting. For example: What other instructions do I need to finish this problem?
#include <iostream>
using namespace std;
void main()
{
int = '*';
int = counter + 1;
for(counter + 1; counter >= 10; counter = counter + 1)
{
cout << '*' << endl;
}
}
Charles Reese
|
|
|
|
|
I'm now doing a project, and what I need to do is firstly read a txt file using i/o stream. I've include the lib and since I need to do it in the .NET form (header) and I want to make it such that when I click the button, it will do the file read-in.
But I cannot add file declaration such things into the header, as there's no main func there. What should I do? Coz I wanna relate the file read-in to the button.
Million thanks!!
|
|
|
|
|
kkyeung wrote: But I cannot add file declaration such things into the header, as there's no main func there. What should I do? Coz I wanna relate the file read-in to the button.
The main func only show one form. Then the form is handling evrything else.
declare in a forn inside class of the form.
kkyeung wrote: I've include the lib and since I need to do it in the .NET form
you don't need to include lib. you can use .net:
using namespace System::IO;
StreamReader;
-- modified at 2:39 Thursday 4th May, 2006
|
|
|
|
|
I have a form called form1.h, and respectively form1.cpp. I have the following code:
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>
#include <iostream>
#include <fstream>
using namespace fyp1;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
ifstream iFile("test.txt");
Application::Run(new Form1());
return 0;
}
I wanna add ifstream into above so that I can read-in a file, then pass the parameter into Form1(). But how can I do that? (ignore the button problem, i don't need it now)The above code cannot be compiled.
Thanks again.
-- modified at 15:09 Thursday 4th May, 2006
|
|
|
|
|
As i told you, you will need StreamReader. It is .NET class, not MFC or other, so there you musn't include iostream, fstream and windows.h. Include file Windows.h often couses compile problem in .Net framework project. so remove all these include
you will Need to add in form1.h file not in form1.cpp.
using namespace System::IO;
public ref class Form1: public System::Windows::Forms::Form
{
public:
Form1(void) ...
...
Private: StreamReader ^streamFile;
Private: String ^streamReadLine;
...
public: ReadFile(void)
{
streamFile = File::OpenText("test.txt");
while (streamFile->EndOfStream != true)
{
streamReadLine = streamFile->ReadLine();
}
}
};
If you still don't know, at least tell me witch .net framework you are using.
|
|
|
|
|
I maintain a Visual C++ Version 6 app. It takes data structures from an Excel app, processes results, and returns structures to Excel. I must now write a C++ .Net wrapper, to take datasets from a VB.Net calling app, create structures from the datasets, send the structures to the Visual C++ Version 6 app, get the return structures, then create and return a dataset to the VB.Net calling app.
I have not been able to expose a public function in the C++ .Net wrapper.
The C++ .Net header code is:
using namespace System;
using namespace System::Data;
using namespace System::Runtime::InteropServices;
namespace TK_DLL_Header {
public class TK_DLL
{
public:
// constructor
TK_DLL();
// destructor
~TK_DLL();
unsigned short ProcessResults (DataSet dsStudyParm, DataRow drFinParms);
};
}
The C++ .Net .cpp code is:
#include "StdAfx.h"
#include "TK_CPlusPlus_Class_Library.h"
using namespace System;
using namespace System::Runtime::InteropServices;
const unsigned short TK_TRUE = 1;
const unsigned short TK_FALSE = 0;
//#define BDS_TK_API __declspec(dllexport)
using namespace TK_DLL_Header;
//namespace TK_DLL_Header {
unsigned short TK_DLL::ProcessResults(System::Data::DataSet dsStudyParm, System::Data::DataRow drFinParms)
{
BDS_ClearAggreg();
return TK_TRUE;
}
[DllImport("BDS_TK.dll", EntryPoint="BDS_ClearAggreg")]
short BDS_ClearAggreg();
I have attempted to access the ProcessResults function in a VB.Net app, in two ways. First, using intellisense:
‘ this statement works
Dim tk As New TK_DLL_Header.TK_DLL
‘ this statement does not work; ProcessResults is not in the list of items after tk.
result = tk.ProcessResults(dsStudyParm, drFinParms)
tk.ProcessResults has a blue line under it; a mouse-over message says “ProcessResults is not a member of TK_DLL_Header.TK_DLL”
In the same VB.Net app, I have added the following declaration at the top of the file:
Private Declare Function ProcessResults Lib "TK_CPlusPlus_Class_Library.dll" (ByRef dsStudyParm As DataSet, ByRef drFinParms As DataRow) As Integer
Using the following call:
result = ProcessResults(dsStudyParm, drFinParms)
Raises the error message:
“Unable to find an entry point named ‘ProcessResults’ in DLL ‘TK_CPlusPlus_Class_Library.dll’
I am missing something very fundamental here. If anyone can help, re how to expose a public function from VC++ .Net, it would be greatly appreciated.
Thanks.
ppanke
|
|
|
|
|
Your assumption is very correct that you are missing something very fundamental here .
The class you declared is not a managed class. it is an unmanaged. To make it a managed type change the class declaration by adding the modifer ref (for .Net 2.0) or __gc (for .Net 1.1) .
so the new class declaration will be:
.net 1.1<br />
namespace TK_DLL_Header {<br />
<br />
public __gc class TK_DLL<br />
{<br />
public: <br />
TK_DLL();<br />
~TK_DLL();<br />
<br />
unsigned short ProcessResults (DataSet dsStudyParm, DataRow drFinParms);<br />
};<br />
}<br />
<br />
.net 2.0:<br />
<br />
namespace TK_DLL_Header {<br />
<br />
public ref class TK_DLL<br />
{<br />
public: <br />
TK_DLL();<br />
~TK_DLL();<br />
<br />
unsigned short ProcessResults (DataSet dsStudyParm, DataRow drFinParms);<br />
};<br />
}
cheers..mil10
|
|
|
|
|
Thanks, but when I added the ref keyword, the class would not compile (it compiles fine without ref). I got an "unresolved externals" error. I do not know why.
P. Panke
|
|
|
|
|
what is he unresoleved external sybal. I meant which function is unresolved ?
|
|
|
|
|
I want to use the timeSetEvent in the C++/CLI for a 1msec timing resolution.
I seem to have a problem in the CALLBACK function and when i try to replace it with a delegate i have other problems.
Can anyone show me the way to use timeSetEvent with a CALLBACK/Delegate function that actually work?
|
|
|
|
|
SampleForm::SampleForm()
{
InitForm();
}
void SampleForm::InitForm()
{
Timer* timer1;
timer1 = new Timer();
timer1->Interval = 3000; // 3 seconds resolution
timer1->add_Tick(new EventHandler(this,OnTimer));
timer1->Start();
}
void SampleForm::OnTimer(System::Object* obj,System::EventArgs* ea) //declare as static method in .h file
{
}
^-^
@|@
- redCat
|
|
|
|
|
this is now the timeSetEvent, but the Timer class.
The Timer class accuracy is very poor, unlike the timeSetEvent.
Can anybody show me how to use it in c++/cli .net 2005?
|
|
|
|
|
First of all, you should note that accuracy is not the same as precision[^]. 10ms is pretty much the most accurate you can get with Win32, without screwing with the operating system metrics or reinstalling the HAL.
But anyway, you use timeSetEvent in C++/CLI the same way you use it in Win32.
#include <windows.h>
#pragma comment(lib, "winmm")
public ref class TimerWrapper
{
EventHandle ^eventHandle;
public:
TimerWrapper()
: eventHandle(false, EventResetMode::AutoReset)
{
}
int TimerFunc()
{
for( ; ; )
{
eventHandle->WaitOne();
...
}
}
void UseTimeEvent()
{
timeSetEvent(100, 55, reinterpret_cast<LPTIMECALLBACK>(
eventHandle->SafeWaitHandle->DangerousWaitHandle().ToPointer()),
0, TIME_ONESHOT | TIME_CALLBACK_EVENT_SET);
...
}
};
-- modified at 17:31 Saturday 13th May, 2006
|
|
|
|
|
can anyone tell me how do i get the current directory in VC++ managed code?
|
|
|
|