|
paras_s12 wrote: can we define a function outside the main()
And how it can be defined inside main ?
This question is out side scope of this forum. Rather ask in VC++[^] forum.
|
|
|
|
|
prasad_som wrote: This question is out side scope of this forum. Rather ask in VC++[^] forum.
It's outside the scope of that forum too
Great job, team. Head back to base for debriefing and cocktails.
|
|
|
|
|
can anybody tell me abt this
hi
|
|
|
|
|
Would you mind posting it in correct forum ?
|
|
|
|
|
please sir tell me in which forum i will put this one
hi
|
|
|
|
|
This forum is for Managed c++/cli
Your c question must be in Visual C++ forum here on CP.
|
|
|
|
|
|
shut your big mouth and open your ears
|
|
|
|
|
I've better question:
Can we define a function inside the main() in c language?
buahaha
|
|
|
|
|
paras_s12 wrote: can we define a function outside the main() in c language
you ar eon wrong forum dude... try http://www.codeproject.com/script/comments/forums.asp?forumid=1647
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
I had written :
for(int i=0; i <10; i++){<br />
em[i]->pct = (gcnew System::Windows::Forms::PictureBox());<br />
em[i]->pct->Location = System::Drawing::Point(250, 250);<br />
em[i]->pct->Visible = true;<br />
em[i]->pct->Size = System::Drawing::Size(50, 50);<br />
}
And I got this error :
An unhandled exception of type 'System.NullReferenceException' occurred in Little tanks.exe
Additional information: Object reference not set to an instance of an object.
at this line : em[i]->pct = (gcnew System::Windows::Forms::PictureBox());
what did I do wrong?
|
|
|
|
|
How have you defined the em array?
|
|
|
|
|
em[i] is null, you probably created an array and didn't create the objects in it
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
the em array defined so : static array<tank^>^ em;
and tank is structure :
ref struct tank {<br />
int step_x, step_y; <br />
System::Windows::Forms::PictureBox^ pct;<br />
};
What do you mean saying to create objects for array?
|
|
|
|
|
thesad wrote: static array^ em;
You have not initialized array here.
Array can be initialized as given in MSDN example.
array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);
|
|
|
|
|
I wrote taht you had sad, but still at same line is that error
|
|
|
|
|
Would interesting to see, how you have done that. There are two possiblitites,
1. You have not allocated memory for it.
2. You are accessing invalid index.
|
|
|
|
|
Here is all code :
<br />
#pragma once<br />
namespace Littletanks {<br />
ref struct tank {<br />
int step_x, step_y; <br />
System::Windows::Forms::PictureBox^ pct;<br />
};<br />
using namespace System;<br />
using namespace System::ComponentModel;<br />
using namespace System::Collections;<br />
using namespace System::Windows::Forms;<br />
using namespace System::Data;<br />
using namespace System::Drawing;<br />
public ref class wnd_main : public System::Windows::Forms::Form {<br />
public: wnd_main(void) {<br />
InitializeComponent();<br />
}<br />
protected: ~wnd_main() {<br />
if (components) delete components;<br />
}<br />
private: System::ComponentModel::IContainer^ components;<br />
private: int max_x, max_y, min_x, min_y;<br />
private: tank usr, b_usr;<br />
private: static array<tank^>^ em; <br />
private: static array<tank^>^ b_em; <br />
<br />
#pragma region Windows Form Designer generated code<br />
void InitializeComponent(void)<br />
{<br />
this->components = (gcnew System::ComponentModel::Container());<br />
this->usr.pct = (gcnew System::Windows::Forms::PictureBox());<br />
this->b_usr.pct = (gcnew System::Windows::Forms::PictureBox());<br />
this->SuspendLayout();<br />
this->usr.pct->Location = System::Drawing::Point(235, 391);<br />
this->usr.pct->Size = System::Drawing::Size(50, 50);<br />
this->usr.pct->TabStop = false;<br />
array<tank^>^ em = gcnew array<tank^>(10);<br />
array<tank^>^ b_em = gcnew array<tank^>(10);<br />
for(int i=0; i <10; i++){<br />
this->em[i]->pct = gcnew System::Windows::Forms::PictureBox();<br />
this->em[i]->pct->Location = System::Drawing::Point(250, 250);<br />
this->em[i]->pct->Visible = true;<br />
this->em[i]->pct->Size = System::Drawing::Size(50, 50);<br />
this->b_em[i]->pct = gcnew System::Windows::Forms::PictureBox();<br />
this->b_em[i]->pct->Load("b_em[i]->jpg");<br />
this->b_em[i]->pct->Location = System::Drawing::Point(13, 64);<br />
this->b_em[i]->pct->Size = System::Drawing::Size(5, 5);<br />
this->b_em[i]->pct->Visible = false;<br />
this->Controls->Add(this->b_em[i]->pct);<br />
this->Controls->Add(this->em[i]->pct);<br />
} <br />
this->b_usr.pct->Load("b_usr.jpg");<br />
this->b_usr.pct->Location = System::Drawing::Point(97, 142);<br />
this->b_usr.pct->Size = System::Drawing::Size(5, 5);<br />
this->b_usr.pct->Visible = false;<br />
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);<br />
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;<br />
this->BackColor = System::Drawing::SystemColors::Window;<br />
this->ClientSize = System::Drawing::Size(500, 500);<br />
this->MaximizeBox = false;<br />
this->MinimizeBox = false;<br />
this->Controls->Add(this->b_usr.pct);<br />
this->Controls->Add(this->usr.pct);<br />
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &wnd_main::wnd_main_KeyDown);<br />
this->Name = L"wnd_main";<br />
this->Text = L"Little tanks ";<br />
this->statusStrip1->ResumeLayout(false);<br />
this->statusStrip1->PerformLayout();<br />
this->menuStrip1->ResumeLayout(false);<br />
this->menuStrip1->PerformLayout();<br />
this->ResumeLayout(false);<br />
this->PerformLayout();<br />
}<br />
#pragma endregion<br />
|
|
|
|
|
Here, you had made couple of mistakes,
thesad wrote: array^ em = gcnew array(10);
array^ b_em = gcnew array(10);
Here, again you are defining local variables. It should be like this,
this->em = gcnew array<tank^>(10);
this->b_em = gcnew array<tank^>(10);
Again, simply defining array doesn't initializes its members, you need to allocate tank variable for each index. So, your code can be modified like this,
thesad wrote: for(int i=0; i <10; i++){
this->em[i]->pct = gcnew System::Windows::Forms::PictureBox();
this->em[i]->pct->Location = System::Drawing::Point(250, 250);
Modify this to,
for(int i=0; i <10; i++){
em[i] = gcnew tank;
this->em[i]->pct = gcnew System::Windows::Forms::PictureBox();
this->em[i]->pct->Location = System::Drawing::Point(250, 250);
|
|
|
|
|
thank you for your help
|
|
|
|
|
If you create a new Array, of 100 tank objects, you have an array with 100 instances of null. You need it iterate over the array, and say
myArray[x] = new gcnew tank();
to create the actual objects in the array.
where x is the index into the array ( you'd probably do this in a loop )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: myArray[x] = new gcnew tank();
Typo.
|
|
|
|
|
Hi all,
I have an application in vc6,in that i am using XP style.
The way I am giving XP Style to my application is by adding an XML File
to my resource . The content of the Xml file is given below
/******************************************************************************/
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
="" manifestversion="1.0">
<assemblyidentity
version="1.0.0.0"
="" processorarchitecture="X86" name="Microsoft.Windows.YourApplication" type="win32">
<description>LitmusPro
<dependency>
<dependentassembly>
<assemblyidentity
type="win32"
="" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorarchitecture="X86" publickeytoken="6595b64144ccf1df" language="*">
/****************************************************************************/
It is working fine in VC6 .
But, when I compile my application in Visual Studio 2005 , this is not working . How can I make it work.
Please Help me
Thanks
Vinod
|
|
|
|
|
Remove the .manifest file from your resources (along with its reference in the .rc file). Then, go to Project Properties / Configuration Properties / Linker / Manifest File, and set Generate Manifest to Yes. Don't forget to call InitCommonControls in your InitInstance function.
This is not a C++/CLI question though, so you're in a wrong forum. Use Visual C++ / MFC[^] forum to discuss non-.NET C++ issues.
|
|
|
|
|
hey folks
I just found this old remote control from Pinnacle Systems and wanted to code an application (in C++/CLI) which uses the RC, means: respond to key presses on the RC (volume up/down etc).
It has an infrared receiver (no extra power or so is needed), which I connected to my serial port (luckily I got one on my new computer!).
The question is, how can I receive messages?
I already opened the port (COM1), but no messages were received
Is there any driver-stuff I need or something?
any C++/CLI code is appreciated!
thx in advance
|
|
|
|