|
Hi!
I've created an application using Managed C++. I've created a setup file using Visual Studio Deployment Project. In the "Dependencies" properties of the ".exe" and "Active Project Output", there is one entry called "Microsoft .NET FrameWork". What to do to run the setup on a machine where Visual Studio and .NET Framework is not installed? Do I need to install .NET Framework at all the machines where I install my setup file?
|
|
|
|
|
Hi,
I am facing a strange problem with the existing code. it suddenly started failing. The problem happens only in one of the machines, while the same code works in other machines.
It fails at the below line.
obj1 = new _objifptr(_uuidof(objif));
I did check that __uuidof returns the correct uuid. but fails when "new _objifprt" is called. The .dll, .tlb and .pdb are all available in the working directory. They have been registered using regasm successfully.
I see that the errors thrown are
FileLoadException followed by TypeInitializationException.
Please help with your thoughts.
Thanks,
Dhana.
|
|
|
|
|
Please post your question in one forum only.
|
|
|
|
|
Hi,
I googled this but I'm still confused. How does one go about adding sound effects to a .Net application?
Thanks.
|
|
|
|
|
Very few people actually frequent this forum. You might have better luck with this question in the C# forum.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Any progress on Intellisense for C++/CLI in VS2010 (Apologies if you read this on the VS board). Been googling and I cant find a satisfactory answer other than return to VS2008...
Ger
|
|
|
|
|
Here's the status as I understand it from watching the vcblog and other postings.
VS2010sp1 doesn't add Intellisense for C++/CLI files. This leaves us to expect it in v.next. I use Visual Assist and like it a lot and that does give me Intellisense in C++/CLI files. VA does get confused sometimes but it's far better than nothing.
VS2010 SP1 is supposed to improve the F12 Go to declaration/definition time for C++ code but I'm not seeing any improvement.
I would love to think that there could be interim updates for C++ users but personally I don't think that'll happen. We can hope though...
Would love to hear newer, better info from anyone.
John
|
|
|
|
|
I separate all of my C++/CLI code into two solutions; one in 2010 and one in 2008....
|
|
|
|
|
I'm not sure how to go about this. What to use to draw the snake to the screen and how to get it to animate properly like grow in size when it collects an item or just moving around the screen. I was told not to use a Picture box but to use Panels and no timers.
http://www.youtube.com/watch?v=s2tlk1LpWjI&feature=related
Maybe start off more simple like in the vid the snake just grows and the entire snake body doesn't move.
Thanks in advance.
modified on Friday, March 25, 2011 8:38 PM
|
|
|
|
|
Well, what's your best guess at how to accomplish this?
Most likely it has something to do with what's been taught most recently. What kinds of graphics features have been gone over?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
hmm my best guess would be to paint the snake onto the screen using some onpaint method which I don't know which one to use. And how to update it so it can be animated. I don't know much about Brushes or graphics in .net. But I did use owner drawn tool tips and menues.
I tried this and updated it using a timer and "this->Invalidate();" but it didn't do what I wanted.
virtual void OnPaint(PaintEventArgs^ e) override
{
}
|
|
|
|
|
Personally, I would create segments of the snake out of small panel objects that have a solid foreground color.
Then, to move the snake, simply move the panel that's at the rear of the snake to the front of the snake.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
So far I created a Snake_Part class. When the Form1 class is first created is calls the Make_Snake Function which creates 4 Snake_Part objects which are added to the list.
How do I move the last panel to the front. I'm using a list to store the Snake_Part instances. A timer will be used to move the snake. I need to some how find the last/first elements in the list and then move them acordingly.
#include "stdafx.h"
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Collections::Generic;
public ref class Snake_Part
{
public:
Panel^ panel;
Snake_Part( Form ^ form )
{
panel = gcnew Panel();
panel->BackColor = Color::Blue;
panel->Width = 20; panel->Height = 20;
form->Controls->Add(panel);
}
};
public ref class Form1 : public Form
{
public:
List<Snake_Part^>^ Parts;
int length;
Timer^ Timer1;
Form1()
{
Parts = gcnew List<Snake_Part^>();
Timer1 = gcnew Timer();
Timer1->Interval = 2000;
Timer1->Start();
Timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
Make_Snake();
}
void Make_Snake()
{
double clr = 255;
double dclr = 128 / 2;
for(int I = 0; I <= 3; I++)
{
Snake_Part^ p = gcnew Snake_Part(this);
p->panel->BackColor = Color::FromArgb(0,0,clr);
Parts->Add(p);
clr -= dclr;
}
for each (Snake_Part^ p in Parts)
{
length += p->panel->Width + 2;
p->panel->Left = length;
}
}
void move_snake()
{
}
System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
move_snake();
}
};
[STAThread]
int main()
{
Application::Run(gcnew Form1());
}
Thanks
|
|
|
|
|
A couple of suggestions. You might want to use a Queue to store the snake segments. That makes it easy to retrieve the last segment and push it onto the front. But a List will work too.
You'll need a value that determines what direction the snake is moving in. Maybe two values, an X and Y value. These should be integers so that they can store 1, 0, or -1.
From there, you can calculate where to position the panel, based upon the head segment's X and Y values, multiplied by the movement indicator values.
The flow would be as follows:
Retrieve the last segment.
Store it in the Head segment holder variable.
Push it onto the front of the snake.
Calculate the new head position.
Position the Head segment according to the new position.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thanks for the helpful suggestions. I got it to move the snake right fine but I need help with some of the coding to get it to move properly in the other directions. I'm curently trying to move the snake downwards but I'm stuck. Thanks.
#include "stdafx.h"
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Collections::Generic;
public ref class snake_segment
{
public:
Panel^ panel;
snake_segment( Form ^ form )
{
panel = gcnew Panel();
panel->BackColor = Color::Blue;
panel->Width = 20; panel->Height = 20;
form->Controls->Add(panel);
}
};
public ref class Form1 : public Form
{
public:
List<snake_segment^>^ segments;
int l;
int size;
int last;
int x, y;
int x2,y2;
Timer^ Timer1;
bool game_started;
Form1()
{
segments = gcnew List<snake_segment^>();
Timer1 = gcnew Timer();
Timer1->Interval = 2000;
Timer1->Start();
Timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form_KeyDown);
Make_Snake();
}
void Make_Snake()
{
double clr = 255;
double dclr = 128 / 2;
for(int I = 0; I <= 3; I++)
{
snake_segment^ s = gcnew snake_segment(this);
s->panel->BackColor = Color::FromArgb(0,0,clr);
segments->Add(s);
clr -= dclr;
}
for each (snake_segment^ s in segments)
{
l += s->panel->Width + 2;
s->panel->Left = l;
}
}
void get_size_of_snake()
{
size=0;
for each (snake_segment^ s in segments)
{
size++;
}
}
void head_position()
{
x = segments[size-1]->panel->Left;
y = segments[size-1]->panel->Top;
}
void move_snake()
{
if(x2 ==1){segments[last]->panel->Left = x + segments[last]->panel->Width + 2;}
if(y2 == -1){segments[last]->panel->Left = x;segments[last]->panel->Top = x;}
x = segments[last]->panel->Left;
y = segments[last]->panel->Top;
last++;
if(last >= size){last=0;}
}
System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
get_size_of_snake();
if(!game_started){head_position();game_started=true;}
move_snake();
}
System::Void Form_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
if(e->KeyCode == Keys::Down){y2 = -1;}
if(e->KeyCode == Keys::Up){y2 = 1;}
if(e->KeyCode == Keys::Left){x2 = -1;}
if(e->KeyCode == Keys::Right){x2 = 1;}
}
};
[STAThread]
int main()
{
Application::Run(gcnew Form1());
}
|
|
|
|
|
I think you have the values for y2 reversed in the Key handler.
If you want the snake to move down, you should be incrementing y2 , and decrementing it for up.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The snake automaticaly moves once the right key is pressed. It sorta works but not sure on how to code it for it moving downwords.
Here is the move_snake function;
void move_snake()
{
if(x2 ==1)
{
segments[last]->panel->Left = x + segments[last]->panel->Width + 2;
x = segments[last]->panel->Left;
y = segments[last]->panel->Top;
last++;
if(last >= size){last=0;}
}
if(y2 == -1)
{
segments[last]->panel->Top = y + segments[last]->panel->Height + 2;
segments[last]->panel->Left = x;
x = segments[last]->panel->Left;
y = segments[last]->panel->Top;
last++;
if(last >= size){last=0;}
}
}
Would you be able to help with the code. It would be much aprecieated. Thanks.
|
|
|
|
|
I think the problem might be that you're not keeping track of which panel is at the head of the snake, since movement is referenced against the head panel.
The code might go something like this: ( I have not tested this code. It might need modification. )
if ( y2 == -1 )
{
segments[last]->panel->Top = y + segments[head]->panel->Top + 2;
segments[last]->panel->Left = segments[head]->panel->Left;
head = last;
last++;
if ( last >= size )
{
last = 0;
}
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You are correct, that's what the problem was. The snake is now moving in all directions. Thanks for helping me out.
|
|
|
|
|
One last thing. I got the collision function working 99% but there's a small glitch where if
the head collides with the tail the collision function doesn't catch it and the snake keeps moving.
The collision function.
void check_for_collision()
{
for(int Tail = 0; Tail <= (size-1); Tail++)
{
for(int I = 0;I <= (size-1); I++)
{
if(I != head){segments[I]->panel->BackColor= Color::Blue;} else
{
segments[head]->panel->BackColor= Color::Yellow;
}
if(head!= Tail && segments[head]->panel->Left == segments[Tail]->panel->Left && segments[head]->panel->Top == segments[Tail]->panel->Top)
{
segments[head]->panel->BackColor= Color::Red;
Timer1->Stop();
}
}
}
}
Entire code.
#include "stdafx.h"
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Collections::Generic;
public ref class snake_segment
{
public:
Panel^ panel;
snake_segment( Form ^ form )
{
panel = gcnew Panel();
panel->Width = 20; panel->Height = 20;
form->Controls->Add(panel);
}
};
public ref class Form1 : public Form
{
public:
List<snake_segment^>^ segments;
int l;
int size;
int tail;
int head;
int x, y;
int direction;
Timer^ Timer1;
bool game_started;
Form1()
{
segments = gcnew List<snake_segment^>();
Timer1 = gcnew Timer();
Timer1->Interval = 500;
Timer1->Start();
Timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form_KeyDown);
Make_Snake();
}
void Make_Snake()
{
for(int I = 0; I <= 5; I++)
{
snake_segment^ s = gcnew snake_segment(this);
s->panel->BackColor = Color::FromArgb(0,0,255);
segments->Add(s);
}
for each (snake_segment^ s in segments)
{
l += s->panel->Width + 2;
s->panel->Left = l;
}
get_size_of_snake();
segments[size-1]->panel->BackColor= Color::Yellow;
}
void get_size_of_snake()
{
size=0;
for each (snake_segment^ s in segments)
{
size++;
}
head=size-1;
}
void head_position()
{
x = segments[size-1]->panel->Left;
y = segments[size-1]->panel->Top;
}
void move_snake()
{
if(direction==1)
{
segments[tail]->panel->Location = Drawing::Point(x - 20 - 2,y);
head = tail;
x = segments[head]->panel->Left;
y = segments[head]->panel->Top;
tail++;
if(tail >= size){tail=0;}
}
if(direction==-1)
{
segments[tail]->panel->Location = Drawing::Point(x + 20 + 2,y);
head = tail;
x = segments[head]->panel->Left;
y = segments[head]->panel->Top;
tail++;
if(tail >= size){tail=0;}
}
if(direction==2)
{
segments[tail]->panel->Location = Drawing::Point(x,y - 20 - 2);
head = tail;
x = segments[head]->panel->Left;
y = segments[head]->panel->Top;
tail++;
if(tail >= size){tail=0;}
}
if(direction==-2)
{
segments[tail]->panel->Location = Drawing::Point(x,y + 20 + 2);
head = tail;
x = segments[head]->panel->Left;
y = segments[head]->panel->Top;
tail++;
if(tail >= size){tail=0;}
}
}
void check_for_collision()
{
for(int Tail = 0; Tail <= (size-1); Tail++)
{
for(int I = 0;I <= (size-1); I++)
{
if(I != head){segments[I]->panel->BackColor= Color::Blue;} else
{
segments[head]->panel->BackColor= Color::Yellow;
}
if(head!= Tail && segments[head]->panel->Left == segments[Tail]->panel->Left && segments[head]->panel->Top == segments[Tail]->panel->Top)
{
segments[head]->panel->BackColor= Color::Red;
Timer1->Stop();
}
}
}
}
System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
if(!game_started){head_position();game_started=true;}
move_snake();
check_for_collision();
}
System::Void Form_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
if(e->KeyCode == Keys::Left){direction=1;}
if(e->KeyCode == Keys::Right){direction=-1;}
if(e->KeyCode == Keys::Up){direction=2;}
if(e->KeyCode == Keys::Down){direction=-2;}
if(e->KeyCode == Keys::Space)
{
snake_segment^ s = gcnew snake_segment(this);
segments->Insert(tail,s);
head = tail;
segments[tail]->panel->Location = Drawing::Point(x + segments[head]->panel->Width + 2,y);
x = segments[head]->panel->Left;
y = segments[head]->panel->Top;
tail++;
get_size_of_snake();
if(tail >= size){tail=0;}
}
}
};
[STAThread]
int main()
{
Application::Run(gcnew Form1());
}
Thanks.
|
|
|
|
|
I think you should simplify the collision function. I don't think you need two loops.
If you want to check whether the head is colliding with any of the other segments, then just do:
for (int ThisSegment = 0; ThisSegment < (size-1); ThisSegment ++ )
{
if ( ThisSegment == head ) continue;
if ( segments[ThisSegment]->panel->Left == segments[head]->panel->Left &&
segments[ThisSegment]->panel->Top == segments[head]->panel->Top )
{
Timer->Stop();
}
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thanks. Thats much simpler code then what I had.
|
|
|
|
|
Hi Richard. I was wondering if you would be able to help me with a bit of code. I posted it here. Thank You.
[Algorthm][^]
|
|
|
|
|
I had MFC dll which exposes some clases. I would like to load this dll dynamically.
hResult = LoadLibrary(_T("c:\test.dll));
if (0 != hResult)
{
_InitSomeDLLFun = (InitSomeDLL)::GetProcAddress(hResult, "InitSomeDLL");
// always Undefind value is returned by GetProcAddress
if(_InitSomeDLL)
{
_InitSomeDLLFun();
}
err = GetLastError();
}
Please advice
|
|
|
|
|
What error is returned? Have you checked that InitSomeDLL is exported by your DLL and is not a mangled C++ name?
I must get a clever new signature for 2011.
|
|
|
|