|
In Managed C++, you can use the static method on the Enum namespace which will give you an array of all the possible values. Just get the count of those values.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I need to wrap a native class for using it in C#
the class contain CString objects.
in old MC++ ver 2003 i write somthing like :
__property String * get_ImageName ()
{
return mBillPopJobParameters-> m_ImageName ;
}
__property void set_ImageName (String * pValue )
{
mBillPopJobParameters-> m_ImageName = pValue;
}
(m_ImageName is a CString.)
and it work ok.
when i try to use it in C++/CLI
property String^ ImageName
{
String^ get()
{
return mPrintSetParameters->m_ImageName ;
}
void set(String^ pValue)
{
mPrintSetParameters-> m_ImageName = pValue;
}
}
i get error that it can not convert from CString to String
any one know how to it right ?
Thanks.
Avraham Cohen.
|
|
|
|
|
Hi,
try This
if u R Accepts System::String _gc*
then (LPCTSTR) YourCString
by
baijumax
|
|
|
|
|
Hello
I am coding an application I do have problem to work with one ActiveX COM. I do not know how to convert
System::String * form structure or char and pass to property (set_Value())function with argument which is type of System::Object _gc * _gc *.
When I call this function in VB.NET works fine and I do not need to do anything to conver string.
Does anybody can help???
Tnx
Mirdous
|
|
|
|
|
Hi,
try this
System::String str1 = _gc new String();
by
baijumax
|
|
|
|
|
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.
|
|
|
|