|
I am having problems writing an opc client using managed c++. I using an opcdotnetautomation.dll. When I go to read in a value from the OPC server. I am getting a signature I don't understand for the OPCItem Read method. Thank you in advance for assistance.
myServer = new OPCServerClass();
myServer->Connect(S"KEPware.KEPServerEx.V4",S"machineName");
myGroups = static_cast< OPCGroupsClass *> ( Marshal::CreateWrapperOfType( myServer->OPCGroups, __typeof( OPCGroupsClass ) ) );
vendor_textBox->Text = myServer->VendorInfo;
start_time_textBox->Text = myServer->StartTime.ToString();
current_time_textBox->Text = myServer->CurrentTime.ToString();
Updated_textbox->Text = myServer->LastUpdateTime.ToString();
groups_textBox->Text = myGroups->Count.ToString();
Server_textBox->Text = myServer->ServerName;
major_textBox->Text = myServer->MajorVersion.ToString();
minor_textBox->Text = myServer->MinorVersion.ToString();
build_textBox->Text = myServer->BuildNumber.ToString();
GroupA = myGroups->Add(S"GroupA");
//GroupB = myGroups->Add(S"GroupB");
AItems = GroupA->OPCItems;
item1 = AItems->AddItem(S"Channel_0_User_Defined.Sine.Sine1",1);
item2 = AItems->AddItem(S"Channel_0_User_Defined.Sine.Sine2",1);
item1->Read(OPCDataSource::OPCCache,?,?,?);
|
|
|
|
|
I'm still a rookie, so forgive me if this is simple.
I have a form and in the form's .h file i have the form's regular class stuff, but I have also added another class.
For example:
in my .h file i have something like this:
namespace MyNamespace
{
public __gc class Form1 : public System::Windows::Forms::Form
{
//then i have all of the regular form stuff
//I also have an event handler that is
//like this:
private: System::Void axTws1_tickPrice(System::Object * sender, AxInterop::TWSLib::_DTwsEvents_tickPriceEvent * e)
{
//when this event happens I want to create an
//instance of another class that I have defined
//within this same .h file, which you can see
//below.
//now when i try to do the following, i get an
//error message that states that
//"SymbolObject_Constructor" is an undeclared
//identifier:
SymbolObject_Constructor *tempObject = new SymbolObject_Constructor;
}//end of event handler
};//end of form class
public __gc class SymbolObject_Constructor
{
public: String *Stock_Ticker;
Decimal Bid;
Decimal Ask;
public: SymbolObject_Constructor()
{
Stock_Ticker = S"";
Bid = 0.0;
Ask = 0.0;
}
};//end of SymbolObject class
}//end of namespace
in my .cpp file for this form, i have a void method that creates an instance of the SymbolObject class, and I do it the same way as I attempted in the .h file; but in the .cpp file, I don't get the error message.
Can anyone see what I am doing wrong?
Thanks,
Jody Blau
|
|
|
|
|
Hai
Nothing wrong in ur code.
i also don't know why it happened.
But placing your second class before the Form1 calss will solve the problem.
ie define all your classes before it uses
by
Anisg
|
|
|
|
|
Hi, I have a C dll written using VC6, now I need a wrapper for it so that I can use the managed extension in .NET environment. I read the help page from Visual Studio .NET, they all show the unmananged code are cpp files. Do I need to convert my c dll to cpp before writing the wrapper for it? I notice that when I tried to open a c project from Visual Studio .NET, I accepted the conversion, but there are no stdafx.h and stdafs.cpp. When I wrote a wrapper file which is compiled using /clr and build it, error : D2016: '/YXstdafx.h' and '/clr' command-line options are incompatible. Please help.
Thanks
|
|
|
|
|
Hi,
U can Call Unmanaged From managed.i believe u r problem is calling .dll(unmanaged) from manged c++.
Pls read the following
http://www.codeguru.com/Cpp/COM-Tech/complus/managed/article.php/c3947/
by
baijumax
|
|
|
|
|
So I made an empty .Net Project and changed the project property so it will create dll which will call unmanage dll. These are the example of my cpp file
#using <mscorlib.dll>
#using <system.dll>
[DllImport("mycdll")]
extern "C" int function1(int);
extern "C" void function2(int);
It was built successfully, however, .exe file was created instead of .dll. I need to have the dll so I can call from VB .net project. What am I missing here?
|
|
|
|
|
All what I want is to use the STL string class in a class library. I tried with a console application and all things work fine. Than I created a class library and tried it again and got link error.
LINK : error LNK2020: unresolved token (0A000006) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000015) delete
The code:
#using <mscorlib.dll>
using namespace System;
#include < string >
#include < iostream >
using namespace std;
namespace Lib
{
__nogc class Class1
{
// TODO: Add your methods for this class here.
void printOut()
{
std::string s = "abc";
cout << s;
}
};
}
I checked the project options and they seem similar! What's wrong?
I use Visual Studio .NET 2003!
|
|
|
|
|
Did you link with the CRT?
|
|
|
|
|
This is my code,it has a few bugs and i have looked over them for hours on end but i am at my wits end,please help a brother out.I have to turn this thin in tomorrow at 9.00AM.
//Benibo Ajumogobia
//@02087650
//Project 2
//19/09/04
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
void total (int __gc[]);//Function declaration
void sort (int __gc[]);
void change (int __gc[], int);
int _tmain()
{
//Declaration of Array
int size __gc[] = {40,30,25,15,100,70,95,24,33,26,14,99};
Console::WriteLine(S"The Originalnumbers in the array are:");
for (int i = 0; i< size; i++ )
Console::Write(S" {0}", size[i].ToString());
Console::WriteLine();
void total(size);
int even = 0;//declaring even and odd numbers
int odd = 0;
for(int k = 0; k<= size;k++)
{
if (size[k] % 2== 0)
even = even + 1;
else
odd = odd + 1;
}
Console::WriteLine(S"The number of Even Numbers is: {0}",even.ToString());
Console::WriteLine(S"The number of Odd Numbers is: {0}",odd.ToString());
//begin sorting
sort(size);
Console::WriteLine(S" Numbers in the array in ascending order");
for (int i=0; i <= size; i++)
Console::Write(S" {0}", size[i].ToString());
Console::WriteLine();
Console::WriteLine(S"Please press enter to close");
String *exit = Console::ReadLine();
return 0;
}// end main
//calculate sum
void total(int b __gc[])
{
int sum = 0;
for (int i = 0; i<= b; i++)
sum = sum + b[i];
Console::Write(S"The total is:{0}", sum.ToString());
Console::WriteLine();
int avg = sum/12;
Console::WriteLine(S"The average is: {0}", avg.ToString());
}
//sort numbers
void sort (int c __gc[])
{
for (int pass = 1; pass<=c; pass++)
for (int i = 0; i < c - 1; i++)
if (c[i]>c[i+1])
change (c, i);
}
//Function to change numbers
void change(int d __gc[], int first)
{
int temp;
temp = d[first];
d[first] = d[first + 1];
d[first + 1] = temp;
}
This are the errors that i got and i was able to resolvce some but this ones persist:
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(24): error C2446: '<' : no conversion from 'int __gc[]' to 'int'
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(24): error C2693: '<' : illegal comparison for references to a __gc array
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(29): error C2182: 'total' : illegal use of type 'void'
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(29): error C2440: 'initializing' : cannot convert from 'int __gc[]' to 'int'
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(34): error C2446: '<=' : no conversion from 'int __gc[]' to 'int'
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(34): error C2693: '<=' : illegal comparison for references to a __gc array
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(49): error C2446: '<=' : no conversion from 'int __gc[]' to 'int'
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(49): error C2693: '<=' : illegal comparison for references to a __gc array
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(63): error C2446: '<=' : no conversion from 'int __gc[]' to 'int'
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(63): error C2693: '<=' : illegal comparison for references to a __gc array
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(76): error C2446: '<=' : no conversion from 'int __gc[]' to 'int'
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(76): error C2693: '<=' : illegal comparison for references to a __gc array
c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(78): error C2690: '-' : cannot perform pointer arithmetic on a __gc array
|
|
|
|
|
Why do you need to use managed C++ ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
You don't have conversion problems, you've put a function declaration inside a class, and you've attempted to use the array in the stop test of multiple for loops. You need array->Count instead of array in every instance, and then everything will be fine, except for that function declaration, which needs to be moved above _tmain, instead of inside it.
Oh, you also use <= instead of < in your for loops. Arrays are zero indexed.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Thanks,i was able to resolve the issues that you highlited and it worked just fine.Thank you very much.
|
|
|
|
|
Hi benibo,
I remember U .U r the Guy who pasted home work last time.i solved the problem with good intension but i got mail from MR.Chris...... the great "NAUGHTY PROFESSOR" specifying some 'Blablabla' comments .
I appreciate you since u have the intension to do home work. and u found "codeproject".some people won't.
So Try To Write Code without any help.any where u stuck understand that part[ Not The Entire Code u Wrote].and post U R Question.
by
baijumax
|
|
|
|
|
Is it possible to use a control created with VB.NET in an MFC app? If so how?
MT
|
|
|
|
|
Hi,
U Can Do That.One Of The Great Feature Of .net is Language inter-operability.U can Find The Article Here.
By
Baijumax
|
|
|
|
|
baiju.km wrote:
Hi,
U Can Do That.One Of The Great Feature Of .net is Language inter-operability.U can Find The Article Here.
By
Baijumax
Where?
M
|
|
|
|
|
Byte readBuffer[];
readBuffer = new Byte[10];
readBuffer[0] = 0x01;
readBuffer[1] = 0x02;
String* str = "\x02";
int index = readBuffer->IndexOf(readBuffer,str);
index = readBuffer->IndexOf(readBuffer,__box(0));
i am ver new to .net and mc++....
the code always gives me -1 as the indexof return value...
pls guide me to correctly code..
thanks and regards
Aji
|
|
|
|
|
All,
In an inherited managed c++ class, how do you call the contstructor of the parent class? I tried with the usual Parent::Parent(...), but get compiler error C3257. Any ideas?
Thanks,
Duncan.
|
|
|
|
|
It's called by itself. When you construct an instance of a class, the constructors you are derived from are also called, they have to be.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
All,
I have a question regarding modifying the metadata of a compiled assembly at runtime. I am creating objects to be added to a PropertyGrid control. In particular, I would like to modify the [Category("...")] and [Description("...")] attribute sections of the functions of objects added to the property grid, based on data read in at runtime. I had a look at the Reflection.Emit functionality, but I couldn't find anything that would allow the modification of an existing class. Is what I am trying to do possible - is the attribute metadata stored on an instance level or a class level? Any ideas?
Thanks,
Duncan.
|
|
|
|
|
My C# Windows app ultimately relies on some legacy COM objects to get most of its work done. As a result, my C# forms call some managed C++ which calls some unmanaged C++ which calls functionality embedded in a COM object. The functionality embedded in the COM object provides translation from Japanese to English. Japanese text is pulled from a C# TextBox form and placed in a .NET string, which is marshalled to a const char * using InteropServices. This null-terminated string is fed to a CString constructor at the unmanaged C++ level, which is finally convered to a BSTR using the AllocSysString method of the CString class. It's this last conversion that's problematic. Here's the gist of it:
USES_CONVERSION;
char *japaneseString = <japanese-string-constant-that-can't-be-cut-and-paste-in>;
CString japaneseTextAsCString(T2OLE(japaneseString));
BSTR japaneseStringAsBSTR = japaneseTextAsCString.AllocSysString() ;
You have to pretend that japaneseString is really a japanese string constant. :) In all cases, the CString encapsulates the same logical string addressed by japaneseString. However, the final line of the four does one of two things, depending on the Output Type project setting of the C# Windows application. <p>
When the output type of the demo is set to Console Application, japaneseStringAsBSTR encapsulates the same logical string encapsulated by the CString and addressed by the char *. In other words, it works perfectly. This string is then fed to the COM object I speak of, and out comes the English translation. </p><p>
When the output type of the demo is set to Windows Application, japaneseStringAsBSTR encapsulates complete GARBAGE. Garbled nonsense, that gets fed to my translation object to produce the English equivalent of that garbled nonsense, which, of course, is more garbled nonsense. Note that output type project property is the default. It was a random stroke of luck that prompted me to switch it to Console Application one day to find that everything worked as it was supposed to. It was a bug that plagued my group for weeks, and this workaround was viewed as a triumph at the time, but it's not the right answer, and it's not all that nice to have a console window sitting beneath the GUI of our application. </p><p>
Obviously, this particular project propety (Output Type: Console Application versus Windows Application) influences something relevant to the execution of the AllocSysString method (or perhaps the CString constructor and/or the T2OLE macro, but that seems less likely). If anyone can point me somewhere, or can explain how a Windows Forms application is influenced by this Output Type property, I'd be very, very grateful. </p><p>
Thanks,<br>
Jerry<br></p>
|
|
|
|
|
Breaking public key encryption. I need to find two best methods that generate all prime numbers from 1 to n where n(100000000) is very large number.can you tell me the best method for calculating prime numbers in c++. i have came up with one. pls write me back thank you so much for your help.
hpatel19
|
|
|
|
|
|
I dont see any help here...
hpatel19
|
|
|
|
|
To create a class for process objects that will sort an array of integers using the Bubblesort method, and test your design on three randomly generated arrays of length 10, 100 and 1000, respectively.
Tasks:
• Create a program to generate three files(data10.in data100.in data1000.in) that contains integer data (random) of size 10,100,1000
• Create a dataless class called BubbleSort, that inlcudes four member functions. This class will require both a header file (.h) and a source file.(.cpp).
o Bubblesort() - a constructor
o ~BubbleSort() - a destructor
o Sort(int * array, int size) - sorts the values in an array of length "size"
o Swap(int *A, int *B) - swaps the values for A and B. Note the use of pointers.
• Write and execute a C++ program based
Plesa send The Solve To My E-mail .......saji@yahadi.info
Thank You
JERUSALEM IN OUR HEARTS
|
|
|
|
|