|
Sockets aren't exactly implemented the same way across multiple platforms. To achieve a cross-platform program that uses sockets, you can either use compile time switches (#defines) to use the appropriate platform-specific calls and system libraries or use a third party library that already has this compile time switching internally.
A few cross-platform socket libraries:
0) http://zeromq.org/[^]
1) www.boost.org (asio library)[^]
2) Larger frameworks have this too (Qt[^], wxWidgets[^])
|
|
|
|
|
Hi
I am somewhat new to TCP/IP, I have been doing some reading on blocking vs non blocking sockets. So my question is when creating a CAsyncsocket object is constructed and created is there a option for what type of socket
Secondly when you get a notification from one of the callback on receive onsend etc
With an error say WSAEINPROGRESS
From the call backs I guess you should just return
|
|
|
|
|
|
Thanks I see there are also some other options with ioctl
|
|
|
|
|
Hi,
I have the following Code:
</#include "stdafx.h"
struct DB_FIELD{
const char* FieldName;
const char* DesignerComments;
const unsigned int FieldFlags;
const int FieldType;
const int FieldEltSize;
const int FieldEltCount;
const int FieldOffset;
const unsigned char PaddingChar;
};
struct DB_FIELD TestFieldItem={
"Key", NULL, 0X00000000, 13, 8, 1, 0, 0 };
This refuses to compile with the following error message:
"error C2552: 'TestFieldItem' : non-aggregates cannot be initialized with initializer list".
I must be doing something stupid, that I cannot see. Initialising Static Structures is the Cut and Trust of CPP!
Can anyone see the Obvious?
Bram van Kampen
|
|
|
|
|
I just tried that and it compiled fine. Maybe there is something more that you are not showing us.
|
|
|
|
|
No, Not much more to show, just an Old Compiler!
It Cannot handle these things, but I found a workaround.
Was frightening at the time!
Thanks,
Bram van Kampen
|
|
|
|
|
As a side note, why declare each member as const?
You could instead write ...
const struct DB_FIELD TestFieldItem =
{
"Key", NULL, 0X00000000, 13, 8, 1, 0, 0 };
|
|
|
|
|
Point taken, and since discovered.
There seems to be a C(PP) language ambiguity here, relating to aggregates. There is never a problem with:
const int Var=512;
Thanks for your reply,
Bram van Kampen
|
|
|
|
|
Hi Guys!,
I have been working on Finite state machine based on a well documented tutorial in code project
Generic Finite State Machine (FSM)[^]
I tried compiling the sample project available with this but can't proceed because of few errors. The project is develped with VS 2010 but I'm using 2012.
I'll give the code excerpt where the error points..
struct StateHandlerBase
{
SharedData data;
States state;
Transitions *m_interfaces[static_cast<size_t>(Size)];
StateHandlerBase()
: data(SharedData()),
state(static_cast<States>(InitState))
{
}
};
typedef int DummyExplicitSpecialization;
template <States stateParam, class Dummy=DummyExplicitSpecialization>
struct StateHandler
: StateHandler<static_cast<States>(static_cast<size_t>(stateParam)-1)>
{
TransitionImplement<StateMachineComponents, static_cast<States>(stateParam)> m_interface;
StateHandler() : m_interface(StateHandlerBase::state, StateHandlerBase::data)
{
StateHandlerBase::m_interfaces[static_cast<size_t>(stateParam)] = &m_interface;
}
};
template <class DummyExplicitSpecialization>
struct StateHandler<static_cast<States>(0), DummyExplicitSpecialization>
: StateHandlerBase
{
TransitionImplement<StateMachineComponents, static_cast<States>(0)> m_interface;
StateHandler() : m_interface(StateHandlerBase::state, StateHandlerBase::data)
{
StateHandlerBase::m_interfaces[0] = &m_interface;
}
};
typedef StateHandler<static_cast<States>(TerminateState), DummyExplicitSpecialization> StateHanlderType;
StateHanlderType StateHanlderInstance;
These are the errors:
error C2976: 'Fsm<statemachinecomponents>::StateHandler' : too few template arguments
error C3855: 'Fsm<statemachinecomponents>::StateHandler': template parameter 'stateParam' is incompatible with the declaration
I'm totally stuck!!. I have no idea what is happening
Greatly appreciate possible suggestions to get out of this
|
|
|
|
|
Member 9350237 wrote: Greatly appreciate possible suggestions to get out of this How about showing the line(s) that the compiler is complaining about.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
 Well, It's 4th line from last.
struct StateHandlerBase
{
SharedData data;
States state;
Transitions *m_interfaces[static_cast<size_t>(Size)];
StateHandlerBase()
: data(SharedData()),
state(static_cast<States>(InitState))
{
}
<pre>
};
typedef int DummyExplicitSpecialization;
template <States stateParam, class Dummy=DummyExplicitSpecialization>
struct StateHandler
: StateHandler<static_cast<States>(static_cast<size_t>(stateParam)-1)>
{
TransitionImplement<StateMachineComponents, static_cast<States>(stateParam)> m_interface;
StateHandler() : m_interface(StateHandlerBase::state, StateHandlerBase::data)
{
StateHandlerBase::m_interfaces[static_cast<size_t>(stateParam)] = &m_interface;
}
};
template <class DummyExplicitSpecialization>
struct StateHandler<static_cast<States>(0), DummyExplicitSpecialization>
: StateHandlerBase
{
TransitionImplement<StateMachineComponents, static_cast<States>(0)> m_interface;
StateHandler() : m_interface(StateHandlerBase::state, StateHandlerBase::data)
{
StateHandlerBase::m_interfaces[0] = &m_interface;
}
It's here---> };
typedef StateHandler<static_cast<States>(TerminateState), DummyExplicitSpecialization> StateHanlderType;
StateHanlderType StateHanlderInstance;
|
|
|
|
|
Member 9350237 wrote: StateHandlerBase::m_interfaces[static_cast<size_t>(stateParam)] = &m_interface;
Do you mean to have that m_interface; at the end of the line?
Never mind. The HTML got in the way of what I was looking at.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Sorry I think the format got changed.
Basically compiler pointing at forth line from last
end of this structure
struct StateHandler<static_cast<States>(0), DummyExplicitSpecialization>
: StateHandlerBase
struct StateHandlerBase
{
SharedData data;
States state;
Transitions *m_interfaces[static_cast<size_t>(Size)];
StateHandlerBase()
: data(SharedData()),
state(static_cast<States>(InitState))
{
}
};
typedef int DummyExplicitSpecialization;
template <States stateParam, class Dummy=DummyExplicitSpecialization>
struct StateHandler
: StateHandler<static_cast<States>(static_cast<size_t>(stateParam)-1)>
{
TransitionImplement<StateMachineComponents, static_cast<States>(stateParam)> m_interface;
StateHandler() : m_interface(StateHandlerBase::state, StateHandlerBase::data)
{
StateHandlerBase::m_interfaces[static_cast<size_t>(stateParam)] = &m_interface;
}
};
template <class DummyExplicitSpecialization>
struct StateHandler<static_cast<States>(0), DummyExplicitSpecialization>
: StateHandlerBase
{
TransitionImplement<StateMachineComponents, static_cast<States>(0)> m_interface;
StateHandler() : m_interface(StateHandlerBase::state, StateHandlerBase::data)
{
StateHandlerBase::m_interfaces[0] = &m_interface;
}
};
typedef StateHandler<static_cast<States>(TerminateState), DummyExplicitSpecialization> StateHanlderType;
StateHanlderType StateHanlderInstance;
|
|
|
|
|
have you tried commenting out the typedef s and struct s to see which one is "bugging" the compiler? That might help to narrow it down.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Member 9350237 wrote: Well, It's 4th line from last. Depending on what you are considering a line, the fourth line from the last is:
StateHandler() : m_interface(StateHandlerBase::state, StateHandlerBase::data)
Member 9350237 wrote: It's here---> }; Not sure which }; instance you are referring to, but I do see a misplaced <pre> tag. Why is that there?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
A glitch in the Matrix.
(Markdown bug)
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
You should really use the forum at the end of the article, so the person who wrote the code can help you.
|
|
|
|
|
I create a sample dialog application which has a circle drawn. Also on mouse move the circle will be re-drawn. I am providing my code below. Its also compilable.
I tried using double buffering and erasebackground, i was not getting the flickering issue, but i observed that the drawining is not erased properly. So to erase, in OnPaint i wrote the erasing code. Again i am facing the flickering issue.
CPaintDC dc(this);
GetClientRect(&clientRect);
circle = clientRect;
circle.DeflateRect(100,100);
dc.SelectStockObject(NULL_BRUSH);
dc.SelectStockObject(NULL_PEN);
dc.FillSolidRect(circle, ::GetSysColor(COLOR_BTNFACE));
Bitmap buffer(circle.right, circle.bottom);
Graphics graphicsbuf(&buffer);
Graphics graphics(dc.m_hDC);
graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality);
SolidBrush brush(Color(255,71,71,71));
Pen bluePen(Color(255, 0, 0, 255),1);
graphicsbuf.DrawEllipse(&bluePen,Rect(circle.left,circle.top,circle.Width(),circle.Height()));
graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality);
graphics.DrawImage(&buffer, 0, 0);
}
void CPOCDlg::OnMouseMove(UINT nFlags, CPoint point)
{
m_point = point;
InvalidateRect(circle,FALSE);
CDialogEx::OnMouseMove(nFlags, point);
}
BOOL CPOCDlg::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
Please let me know if i am doing any mistake.
|
|
|
|
|
I would imagine that since OnMouseMove() is called A BUNCH, your drawing code is not able to keep up. Just a guess, though.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
I modified my dialog to a polygon region dialog. Then i am trying to frame/draw the border.Using device context the CRgn::FrameRgn, i am bale to draw the border around the dialog. But i want to achieve this using Gdi+. I did as below, but the border is appearing only on left and top of the dialog. Can someone please help on this.
CPoint vertex[4];
BOOL CPolygonDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
ModifyStyle(WS_CAPTION,0);
ModifyStyle(WS_BORDER,0);
CRect rect(400,200,900,700);
CRect wr = rect;
AdjustWindowRect( wr, 0, FALSE );
MoveWindow(wr);
GetClientRect( rect );
CRect csr = rect;
ClientToScreen( csr );
vertex[0] = CPoint(rect.left,rect.top);
vertex[1] = CPoint(rect.right,rect.top);
vertex[2] = CPoint(rect.right,rect.bottom);
vertex[3] = CPoint(rect.left,rect.bottom);
m_rgnShape.CreatePolygonRgn( vertex, 4, ALTERNATE );
m_rgnShape.OffsetRgn( CPoint( csr.TopLeft() - wr.TopLeft() ) );
SetWindowRgn( (HRGN)m_rgnShape.Detach(), TRUE );
m_rgnShape.CreatePolygonRgn( vertex, 4, ALTERNATE );
return TRUE;
}
void CPolygonDlg::OnPaint()
{
Graphics graphics(dc.m_hDC);
CRect rect;
GetClientRect(rect);
GraphicsPath gp;
Point point[4];
point[0] = Point(rect.left,rect.top);
point[1] = Point(rect.right,rect.top);
point[2] = Point(rect.right,rect.bottom);
point[3] = Point(rect.left,rect.bottom);
gp.AddPolygon(point,4);
Pen pen(Color(255, 255, 0, 0));
graphics.DrawPath(&pen, &gp);
}
|
|
|
|
|
|
Hi,
Thanks for your solution.
I used AddLine and the same vertex. Still it was not working.
Then i decreased 1 from right and bottom, now its working.
Is it something like i need to use offset or something. I dont want to hardcode.
GraphicsPath gp;
Point point[5];
point[0] = Point(vertex[0].x,vertex[0].y);
point[1] = Point(vertex[1].x-1,vertex[1].y);
point[2] = Point(vertex[2].x-1,vertex[2].y-1);
point[3] = Point(vertex[3].x,vertex[3].y-1);
point[4] = Point(vertex[0].x,vertex[0].y);
gp.AddLines(point,5);
Pen pen(Color(255, 255, 0, 0));
graphics.DrawPath(&pen, &gp);
|
|
|
|
|
It's a peculiarity of the way that closed shape points are defined. The right and bottom are actually outside the shape. If you check the MSDN documentation it is described there.
|
|
|
|
|