|
I am not sure if i understood you. I made the followin in the second code but still same problem:
wchar_t DDData[14];
Dbt getKey, getData;
getKey.set_data(a);
getKey.set_size(HexSig->Length);
getData.set_data(DDData);
getData.set_ulen(HexSig->Length);
getData.set_flags(DB_DBT_USERMEM);
|
|
|
|
|
If the database data type is 'char', and has a size of 5 and you put 'x' in it then to query for that value you need to use 'x ' (x followed by 4 spaces is a size of 5.)
|
|
|
|
|
I tried to make the key size (In Query operation) dynamic with "for" loop as the code below.. this was without any benefit:
for (int i=1;i<90000000; i++){
getKey.set_size(i);
getData.set_data(DDData);
getData.set_ulen(28);
getData.set_flags(DB_DBT_USERMEM);
if(SigDb.get(NULL,&getKey,&getData,0)!=DB_NOTFOUND)
Console::WriteLine(" {0},,{1}",Marshal::PtrToStringUni((IntPtr)DDData),i);
}
Marshal::FreeHGlobal(IntPtr(a));
Console::WriteLine("Finish");
|
|
|
|
|
Anyone recommend best place to post boost:asio question?
Didn't think this forum is the right place but maybe it is.
|
|
|
|
|
Well there is one obvious place[^].
The best things in life are not things.
|
|
|
|
|
|
hello i'm trying to convert this piece of code from vb
Private Structure IconInfo
Public fIcon As Boolean
Public xHotspot As Int32
Public yHotspot As Int32
Public hbmMask As IntPtr
Public hbmColor As IntPtr
End Structure
<DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> _
Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
End Function
<DllImport("gdi32.dll")> _
Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
End Function
Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor
'Setup the Cursors IconInfo
Dim tmp As New IconInfo
tmp.xHotspot = _gHotSpotPt.X
tmp.yHotspot = _gHotSpotPt.Y
tmp.fIcon = False
If _gBlackBitBack Then
tmp.hbmMask = bmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0))
tmp.hbmColor = bmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0))
Else
tmp.hbmMask = bmp.GetHbitmap()
tmp.hbmColor = bmp.GetHbitmap()
End If
'Create the Pointer for the Cursor Icon
Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp))
Marshal.StructureToPtr(tmp, pnt, True)
Dim curPtr As IntPtr = CreateIconIndirect(pnt)
'Save the image of the cursor with the _gBlackBitBack effect
'Not really needed for normal use.
'I use it to create a screen shot with the gCursor included
_gCursorImage = Icon.FromHandle(curPtr).ToBitmap
'Clean Up
DestroyIcon(pnt)
DeleteObject(tmp.hbmMask)
DeleteObject(tmp.hbmColor)
Return New Cursor(curPtr)
End Function
By now i traslate the all thing into:
public struct IconInfo
{
bool fIcon;
int xHotspot;
int yHotspot;
System::IntPtr hbmMask;
System::IntPtr hbmColor;
};
[System::Runtime::InteropServices::DllImport("user32.dll, EntryPoint:=CreateIconIndirect")]
System::IntPtr CreateIconIndirect(System::IntPtr iconInfo);
[System::Runtime::InteropServices::DllImport("user32.dll, CharSet:=CharSet.Auto")]
bool DestroyIcon(System::IntPtr handle);
[System::Runtime::InteropServices::DllImport("gdi32.dll")]
bool DeleteObject(System::IntPtr handl);
System::Windows::Forms::Cursor ^CreateCursor(Bitmap ^bmp, int xHotSpot, int yHotSpot)
{
IconInfo tmp;
tmp.xHotspot = 3;
tmp.yHotspot = 3;
tmp.fIcon = false;
bool _gBlackBitBack=false;
if (_gBlackBitBack) {
tmp.hbmMask = bmp->GetHbitmap(Color::FromArgb(0, 0, 0, 0));
tmp.hbmColor = bmp->GetHbitmap(Color::FromArgb(0, 0, 0, 0));
}
else {
tmp.hbmMask = bmp->GetHbitmap();
tmp.hbmColor = bmp->GetHbitmap();
}
IntPtr pnt= Marshal::AllocHGlobal(Marshal::SizeOf(tmp));
Marshal::StructureToPtr(%tmp, pnt, true);
IntPtr curPtr = CreateIconIndirect(pnt);
DestroyIcon(pnt);
DeleteObject(tmp.hbmMask);
DeleteObject(tmp.hbmColor);
return gcnew System::Windows::Forms::Cursor(curPtr);
}
the problem is that i get the following error and i don't know how to get it solved:
error C2665: 'System::Runtime::InteropServices::Marshal::SizeOf' : none of the 2 overloads could convert all the argument types
1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll: could be 'int System::Runtime::InteropServices::Marshal::SizeOf(System::Object ^)'
1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll: or 'int System::Runtime::InteropServices::Marshal::SizeOf(System::Type ^)'
1> while trying to match the argument list '(test_cursor::IconInfo)'
error C2664: 'System::Runtime::InteropServices::Marshal::StructureToPtr' : cannot convert parameter 1 from 'test_cursor::IconInfo' to 'System::Object ^'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
|
|
|
|
|
ok i get it
if you wanna know
value class IconInfo
{
public:
bool fIcon;
Int32 xHotspot;
Int32 yHotspot;
IntPtr hbmMask;
IntPtr hbmColor;
};
|
|
|
|
|
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.
|
|
|
|