|
HI all,
I am getting this error since morning, I am clue less as I am working first time on it (I am c# developer).
the code file are as follows and i compied using Commnad prompt
command cl /clr:oldSyntax DemoCPP.cpp
DemoCPP.cpp class
#include "DemoHeader.h"
DemoCPP::DemoCPP()
: Length(0.00), Height(0.00)
{
}
DemoCPP::DemoCPP(double L, double H)
: Length(L), Height(H)
{
}
DemoCPP::~DemoCPP()
{
}
double DemoCPP::getLength()
{
return Length;
}
void DemoCPP::setLength(double L)
{
Length = L;
}
double DemoCPP::getHeight()
{
return Height;
}
void DemoCPP::setHeight(double H)
{
Height = H;
}
void DemoCPP::setDimensions(double L, double H)
{
setLength(L);
setHeight(H);
}
double DemoCPP::Perimeter()
{
return 2 * (Length + Height);
}
double DemoCPP::Area()
{
return Length * Height;
}
header file DemoHeader.h
#pragma once
#using <mscorlib.dll>
__gc class DemoCPP
{
public:
DemoCPP();
DemoCPP(double L, double H);
~DemoCPP();
double getLength();
void setLength(double L);
double getHeight();
void setHeight(double H);
void setDimensions(double L, double H);
double Perimeter();
double Area();
private:
double Length;
double Height;
};
any body have any idea how to resolve this problem?
thanks in advance!
|
|
|
|
|
|
Since this is a DLL, you need to compile with /DLL compiler switch. BTW, why are you using old syntax?
|
|
|
|
|
Thanks for quick response!
Yes I have googled a lot and then placed question here...
the Old command i am using because it is recommended by the VS2005 when i tried to build the project from vs2005
I tried the project type as empty project as well as class library!
still I am getting the same error!
I have created the project using wizard itself!
any further help!
thanks in advance!
|
|
|
|
|
If you have VS, don't do command compilation. I never came across a situation where VS recommended old syntax. If you need to create a fully managed assembly, choose Class Library project type. Use new syntax and compile using /clr:safe .
if you need to communicate with native libraries, compile with /clr switch which will produce mixed assemblies. Since you have VS IDE, best option is to use it to compile rather than doing through command. VS does things like manifest embedding automatically.
|
|
|
|
|
thanks navneeth for ypur reply
I tried using /clr:safe option however i got the following error
Error 1 error C4980: '__gc' : use of this keyword requires /clr:oldSyntax command line option d:\excercise\dot net\cppclasslibrary\cppclasslibrary\CPPCLassLibrary.h 8
so as suggested I used the /clr:oldSyntax
and option _gc I am using as i want to consume this class libray in c#
|
|
|
|
|
Here is your class using new syntax.
#pragma once
using namespace System;
ref class DemoCPP
{
public:
DemoCPP();
DemoCPP(double L, double H);
~DemoCPP();
double getLength();
void setLength(double L);
double getHeight();
void setHeight(double H);
void setDimensions(double L, double H);
double Perimeter();
double Area();
private:
double Length;
double Height;
}; Now compile using /clr or /clr:safe .
|
|
|
|
|
I got the Answer
here it is
1. Project Properties -> General Tab
2. for Common Language Runtime Support select Old Syntax (/clr:oldSyntax) from drop down
now you do not need to play with command line .....
you can easily build your project from visual studio IDE itself
|
|
|
|
|
Here's some code :
private: System::Void TS11_MCli(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
Tsn11 = Tsn11 + 1 ;
if (Tsn11 = 0) { this->TS11->Image = Image::FromFile("C:/GamePics/NOTILE.png");}
else {
if (Tsn11 = 1){ this->TS11->Image = Image::FromFile("C:/GamePics/GREEN.png");}
else {
if (Tsn11 = 2){ this->TS11->Image = Image::FromFile("C:/GamePics/GRTRE.png");}
else {
if (Tsn11 = 3){ this->TS11->Image = Image::FromFile("C:/GamePics/ROAD.png");}
else {
if (Tsn11 = 4){ this->TS11->Image = Image::FromFile("C:/GamePics/WALL.png");}
};
};
};
};
};
};
};
|
|
|
|
|
Your questions is not clear. Please explain it clearly.
Also the code posted is less readable. Please remove unnecessary spaces and format it nicely. I think a switch case makes more sense here than nested if.
|
|
|
|
|
The question is ultra simple.
How do I get a mouseclick event work twice?!?
As for the code, it works.
The bug is either the variable won't increment more than once, either the procedure is usable only once.
I'm gonna try something.
|
|
|
|
|
Fenix2 wrote: The question is ultra simple.
Maybe to you!
Fenix2 wrote: As for the code, it works.
Obviously it doesn't, or you would not be asking this question.
Fenix2 wrote: I'm gonna try something.
I would suggest you start with your if (Tsn11 = x) statements.
|
|
|
|
|
Richard MacCutchan wrote: I would suggest you start with your if (Tsn11 = x) statements.
Funny. I haven't noticed if (Tsn11 = x) .
|
|
|
|
|
N a v a n e e t h wrote: Funny. I haven't noticed ...
Took me a few readings; I was looking at the wrong things!
|
|
|
|
|
Hi,
in C/C++/Java/C# the equality operator is ==
Tsn11 = 1 is an expression which both sets Tsn11 to 1 and evaluates to 1, so your if statements will not act as you expect.
FWIW: in VB/VB.NET the equality operator is =
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
So where are you suggesting to put ==?
at the IF statement, or at the increment?
|
|
|
|
|
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
It doesn't work.
If I guess,
I'd say myself that the error is in the starting of the form.h
What if the variables are always reset to 0?
What if the form, would be... in a repeatative process?
So where should I put the variable Tsn11 ?
|
|
|
|
|
Fenix2 wrote: It doesn't work.
What doesn't work?
You have statements of the form if (Tsn11 = 0) , which, as Luc pointed out are incorrect. The equality operator in C++ is == . Correct all your if statements and see what happens.
|
|
|
|
|
Yeah Thanks to all of you.
It works now.
|
|
|
|
|
Whats a natural successor to the COM object in the managed C++/CLI world?
I am migrating an app which has COM objects for no better reason that than is the only way I could get a form into a DLL to share between two exe's.
What should I be using in C++/CLI?
Ger
|
|
|
|
|
Ger Hayden wrote: What should I be using in C++/CLI?
It should be managed assemblies. You can pack windows forms in to assemblies(DLLs) which can be used with multiple applications. Create a Class Library project and add reference to System.Windows.Forms assembly.
|
|
|
|
|
I am migrating to Managed C++/CLI and .NET.
Previously I have used mysql++ with some difficutly.
Should I stick with it or move to ODBC or Connector/.NET?
Ger
|
|
|
|
|
In .NET, MySql connector is the best. It follows ADO.NET standards and provide a neat interface. Download from here[^].
|
|
|
|
|
Thanks. A few minutes to down load. Working example in less than half an hour....
Ger
|
|
|
|