|
To use sockets in a single threaded application, you can use the
WSAAsyncSelect() function. This will cause messages to be sent
to a specified window when the socket events you select occur - particularly
useful for when an incoming connection request is received, when there's
data available to be read on a socket, and when a connection is closed.
The advantage of multiple threads is the same advantage as any multithread
application - the app can take advantage of multiple processors for better performance
with parallel processing.
I didn't mean to be harsh at all - just honest. Take the time to learn at least the very
basics of sockets and things will work much better for you in the long run - I know this from
experience
Some basic things to know inside and out -
1) The essential socket APIs (study these in the Winsock SDK):
socket()
bind()
listen()
accept()
connect()
WSAAsyncSelect() (or WSAEventSelect() to use asynchronous socket ops on a separate thread)
recv()
send()
shutdown()
closesocket()
2) A basic understanding of blocking (synchronous) and non-blocking (asynchronous)
socket modes, and how the mode is changed on a socket.
I wish I had some links but I don't. There's a few great articles here at Code Project
but the search isn't bringing them up at the moment grrr.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I wish there was a vote more than 5 thank you so very much. I really do appeciate.
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
hi everybody
I wanted to work on COM in vc++
But i donot have any resource of com
So anyone can pls give me some document on com so i can learn it
Thanks in Advance
|
|
|
|
|
i am no expert in com but try :
http://www.cs.umd.edu/~pugh/com/
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
Still i am no expert but as you check out the previous also try going to tech tutorials here:
http://www.techtutorials.info/pcom.html
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
tarak Desai wrote: I wanted to work on COM in vc++
Buy Developer workshop to ATL/COM 3.0 book, it will provide beginner to expert level information on com!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Hi,
I have noticed two strange when I used the Following Typdef
Typdef struct
{
char a;
int b;
}
looking in memory Using The Visual Studio to Build and Debug
the int "b" takes four bytes
and also seems both a and b start boundry divisible by 4
as there are three slack bytes between a's value and b
IS there maybe a compiler option /Noalign to prevent this
Thankx
|
|
|
|
|
#pragma pack(1)
struct Test {
int a;
char b;
};
#pragma pack()
Maxwell Chen
|
|
|
|
|
The #pargma pack(1) tell the compiler not to align ????
|
|
|
|
|
Have you tried putting #pragma into msdn? then following for pack?
Simple answer is pack(1) tells the compiler to pack on a 1 byte alignment. pop says "go back to what you were doing before".
Iain
Iain Clarke appearing in spite of being begged not to by CPallini.
|
|
|
|
|
|
Hello everyone!
I'm designing a OOP-based system in C++, and I'm having a little problem. Say I have this:
class Class1
{
virtual void Draw(Image *a_pImage);
};
class Class2 : public Class1
{
virtual void Draw(Image *a_pImage);
};
Class1::Draw takes care of ugly low-level stuff, and that's a lot of code. How can Class2::Draw call Class1::Draw so that I don't have to copy-paste all of the code in Class2? In C#, for example, you used base.Draw, but base doesn't exist in C++...
Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
void Class2::Draw(Image *a_pImage)
{
// add extra code for Class2 draw
Class1::Draw(a_pImage);
// add extra code for Class2 draw
}
modified on Friday, February 15, 2008 12:15 AM
|
|
|
|
|
Huh? That easy? I was expecting an extremely long message explaining how to delicately trick C++ into doing what I wanted... Thanks , Rajkumar!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Lord Kixdemp wrote: Huh? That easy?
"One of the difficulties people have with object-oriented design is that it's too simple to get from the beginning to the end. A mind trained to look for complex solutions is often stumped by this simplicity at first" - Bruce Eckel.
|
|
|
|
|
nice quote
|
|
|
|
|
Lord Kixdemp wrote: virtual void Draw(Image *a_pImage);
Class2::Draw() is virtual by default. The virtual keyword is unnecessary.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
I have three applications; A, B and C. A always stays in foreground and has focus. B an C run in background. B receives messages from A via socket. I need B to send Shift/Ctrl/Alt + key to C based on A's messages. I've tried CKeystrokeEngine, and it works some times but not all the time. Is there anything I can do to CKeystrokeEngine and change it's behavior so that it works all the time?
|
|
|
|
|
I just had a look into the CKeystrokeEngine class, it seems it depends on the keybd_event API and depends on the SetForegroundWindow and it is not sure that the window will be the active window to receive the keyboard event as CWindowEngine::FocusWindow() always return true without checking the return value of SetForegroundWindow API. if my assumption is correct B and C no longer be said as background app as it is brought to foreground every time a keystroke is to be send
As the A, B, C all r ur application and ur already communicating using sockets, i would suggest that u use ur own protocol in the same connection and interpret the key strokes, it doesnot require the window to be active foreground window.
|
|
|
|
|
I can't change A or C. B is the only app I am writing and have control over.
|
|
|
|
|
Have you tried PostMessage() with the WM_KEYDOWN message?
|
|
|
|
|
Sh*t/Alt/Ctrl keys can't be sent using postmessage.
|
|
|
|
|
njhy wrote: sh*t/Alt/Ctrl keys can't be sent using postmessage.
Wrong. Those keys can be sent by using PostMessage()
::PostMessage(myHwnd, WM_KEYDOWN, VK_SHIFT, 0);
::PostMessage(myHwnd, WM_KEYUP, VK_SHIFT, 0);
This code will send a shift key press and release event to the window with the handle myHwnd . And similarly you could send just any key press event, even multiple (simultaneous) key press events.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Try it your self. It does not work.
::PosMessage(myWnd, WM_KEYDOWN, VK_F13, 0); // VK_13 is SHIFT + F1
::PosMessage(myWnd, WM_KEYUP, VK_F13, 0);
or
::PosMessage(myWnd, WM_KEYDOWN, VK_SHIFT, 0);
::PosMessage(myWnd, WM_KEYDOWN, VK_F1, 0);
::PosMessage(myWnd, WM_KEYUP, VK_F1, 0);
::PosMessage(myWnd, WM_KEYUP, VK_SHIFT, 0);
|
|
|
|
|
Hmm... I've got it working by executing my code from within a DLL (a hook, to be precise). Neither do I have dev tools on this machine, so I can't test something right now.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|