|
oh,my God,it is so great!
I see now,the port is really different with the SOCKET member of the Socket!
Thanks.
But when I test the guide of you given,the SockAddrStr always be fill with "0.0.0.0"!why?
Thanks.
Best Wishes!
GOOD LUCK
|
|
|
|
|
kcynic wrote: when I test the guide of you given,the SockAddrStr always be fill with "0.0.0.0"!why?
Because you haven't specifically bound the socket to one adapter - there's no specific
IP address.
If you want the IP address(es) of the machine, you can use the sockets APIs gethostname()
and gehostbyname() (or the newer getaddrinfo()). Note that you can only get a local LAN IP
address if you're on a LAN, not the public IP needed by peers outside the LAN.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I see,Thanks.
It is very helpful of your guide,if not,I remain conside the m_hSocket member as the port of a CSocket or CAsyncSocket object.
Thanks very much.
And if you would like to have a look at my new posted message "Problem about DCOM on Windows2003 Server"? My database project come up a problem when it run on Windows2003 Server.If the server was run on Windows2003,no matter where the client is,the query speed is very slow.Thanks.
Best Wishes.
GOOD LUCK
|
|
|
|
|
Hi guys
I’ve written a program to detect SPAM in VoIP calls. There are two state machines which control the state of the operation. One for clients and one for server. Anyway, the class for the client is ClientStateMachine which is declared below:
(The program have been written in Microsoft Visual Studio 2005 C++)
#ifndef CLIENTSTATEMACHINE_H<br />
#define CLIENTSTATEMACHINE_H<br />
<br />
#include "clientmsg.h"<br />
#include "sndrcvsockc.h"<br />
#include "blacklist.h"<br />
#include "whitelist.h"<br />
<br />
using namespace SPIT;<br />
<br />
namespace SPIT {<br />
<br />
class ClientMsg;<br />
<br />
class ClientStateMachine {<br />
public:<br />
ClientStateMachine(char = 'S');<br />
<br />
class AllState{<br />
public:<br />
virtual void onAbsZero(ClientStateMachine &u);<br />
virtual void onInvite(ClientStateMachine &u);<br />
virtual void onInviteRcv(ClientStateMachine &u);<br />
virtual void onInviteWl(ClientStateMachine &u);<br />
virtual void onInviteBl(ClientStateMachine &u);<br />
virtual void onInviteWait(ClientStateMachine &u);<br />
virtual void onInviteCh(ClientStateMachine &u);<br />
virtual void onCh(ClientStateMachine &u);<br />
virtual void onOk(ClientStateMachine &u);<br />
virtual void onEnd(ClientStateMachine &u);<br />
virtual void onBye(ClientStateMachine &u);<br />
};<br />
friend AllState;<br />
<br />
class AbsoluteZero : public AllState{<br />
public:<br />
void onAbsZero(ClientStateMachine &u);<br />
};<br />
friend AbsoluteZero;<br />
<br />
class Idle : public AllState{<br />
public:<br />
void onInvite(ClientStateMachine &u);<br />
void onInviteRcv(ClientStateMachine &u);<br />
void onInviteWl(ClientStateMachine &u);<br />
void onInviteBl(ClientStateMachine &u);<br />
void onInviteCh(ClientStateMachine &u);<br />
};<br />
friend Idle;<br />
<br />
class Waiting : public AllState{<br />
public:<br />
void onInviteWait(ClientStateMachine &u);<br />
void onCh(ClientStateMachine &u);<br />
void onOk(ClientStateMachine &u);<br />
void onEnd(ClientStateMachine &u);<br />
};<br />
friend Waiting;<br />
<br />
class Established : public AllState{<br />
public:<br />
void onBye(ClientStateMachine &u); <br />
};<br />
friend Established;<br />
<br />
private:<br />
static AbsoluteZero ABSOLUTE_ZERO_STATE;<br />
static Idle IDLE_STATE;<br />
static Waiting WAITING_STATE;<br />
static Established ESTABLISHED_STATE;<br />
<br />
void nextState( AllState &mState);<br />
<br />
AllState *mCurrentState;<br />
<br />
void getUserInformationAndSetBuffer(ClientStateMachine &u); void setNextStateAndMsg(ClientStateMachine &u); <br />
void setMsgHeaderAndBudy(ClientStateMachine &u);<br />
<br />
void socketInitialize(ClientStateMachine &u);<br />
void socketFinalize(ClientStateMachine &u);<br />
<br />
SndRcvC mClientSocket;<br />
BList mBlackList;<br />
WList mWhiteList;<br />
ClientMsg mMsg;<br />
char * mMsgHeader;<br />
char * mMsgBudy;<br />
bool mFirst;<br />
char mSenderReceiver;<br />
<br />
public:<br />
void onMsg();<br />
};<br />
}<br />
<br />
#endif
During dubuging there are some errors in linking state. the error log file is mentioned below:
1>------ Build started: Project: SERVER_STATE_MACHINE, Configuration: Debug Win32 ------
1>Compiling...
1>serverstatemachine.cpp
1>c:\shared project\server_state_machine\server_state_machine\sndrcvsock.h(8) : warning C4081: expected 'newline'; found ';'
1>.\serverstatemachine.cpp(143) : warning C4996: 'strcpy' was declared deprecated
1> c:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>.\serverstatemachine.cpp(153) : warning C4996: 'strncpy' was declared deprecated
1> c:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(156) : see declaration of 'strncpy'
1> Message: 'This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>.\serverstatemachine.cpp(156) : warning C4996: 'strncpy' was declared deprecated
1> c:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(156) : see declaration of 'strncpy'
1> Message: 'This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>.\serverstatemachine.cpp(183) : warning C4996: 'strcpy' was declared deprecated
1> c:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>.\serverstatemachine.cpp(188) : warning C4996: 'strcpy' was declared deprecated
1> c:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>.\serverstatemachine.cpp(189) : warning C4996: 'strcpy' was declared deprecated
1> c:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>.\serverstatemachine.cpp(190) : warning C4996: 'strcat' was declared deprecated
1> c:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(78) : see declaration of 'strcat'
1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>Linking...
1>serverstatemachine.obj : error LNK2019: unresolved external symbol "private: static class SPIT::ServerStateMachine::AbsoluteZero SPIT::ServerStateMachine::ABSOLUTE_ZERO_STATE" (?ABSOLUTE_ZERO_STATE@ServerStateMachine@SPIT@@0VAbsoluteZero@12@A) referenced in function "private: __thiscall SPIT::ServerStateMachine::ServerStateMachine(void)" (??0ServerStateMachine@SPIT@@AAE@XZ)
1>serverstatemachine.obj : error LNK2019: unresolved external symbol "private: static class SPIT::ServerStateMachine::Idle SPIT::ServerStateMachine::IDLE_STATE" (?IDLE_STATE@ServerStateMachine@SPIT@@0VIdle@12@A) referenced in function "public: virtual void __thiscall SPIT::ServerStateMachine::AbsoluteZero::onAbsZero(class SPIT::ServerStateMachine &)" (?onAbsZero@AbsoluteZero@ServerStateMachine@SPIT@@UAEXAAV23@@Z)
1>serverstatemachine.obj : error LNK2019: unresolved external symbol "private: static class SPIT::ServerStateMachine::Waiting SPIT::ServerStateMachine::WAITING_STATE" (?WAITING_STATE@ServerStateMachine@SPIT@@0VWaiting@12@A) referenced in function "public: virtual void __thiscall SPIT::ServerStateMachine::Idle::onInviteOk(class SPIT::ServerStateMachine &)" (?onInviteOk@Idle@ServerStateMachine@SPIT@@UAEXAAV23@@Z)
1>serverstatemachine.obj : error LNK2019: unresolved external symbol "private: static class SPIT::ServerStateMachine::Established SPIT::ServerStateMachine::ESTABLISHED_STATE" (?ESTABLISHED_STATE@ServerStateMachine@SPIT@@0VEstablished@12@A) referenced in function "public: virtual void __thiscall SPIT::ServerStateMachine::Waiting::onOk(class SPIT::ServerStateMachine &)" (?onOk@Waiting@ServerStateMachine@SPIT@@UAEXAAV23@@Z)
1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Shared Project\SERVER_STATE_MACHINE\Debug\SERVER_STATE_MACHINE.exe : fatal error LNK1120: 5 unresolved externals
1>Build log was saved at "file://c:\Shared Project\SERVER_STATE_MACHINE\SERVER_STATE_MACHINE\Debug\BuildLog.htm"
1>SERVER_STATE_MACHINE - 6 error(s), 8 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How can I amend the program not to have these errors?
|
|
|
|
|
static members have to be inialised in cpp file.
try:
AbsoluteZero Established::ABSOLUTE_ZERO_STATE = AbsoluteZero();
Idle Established::IDLE_STATE = Idle();
Waiting Established::WAITING_STATE = Waiting();
Established Established::ESTABLISHED_STATE = Established();
|
|
|
|
|
Hi,
I'm working on a gui automation project, and ran into some difficulties.
I have code to retrieve the window handle (HWND) to the window I want to send mouseclicks to, and I have code to send clicks to specific coordinates within that window. I can also retrieve all subwindows, thus giving me access to all standard buttons in the window, and their caption. However, the window I'm concerned with only contains custom painted graphics, and it handles its mouse messages low-level.
However, there is an area inside the windows panel containing static textual data. I have to click on a specific line within that area to achieve what I want to do. But... I have no means of determining what the static text says.
I can only come up with two approaches, both to cumbersome to include in my app:
1/ Capture the graphics of that specific text area, and reverse engineer it into text
2/ Install some sort of DLL hook to capture DrawText calls, and get the strings position from there...
Is there another, more straightforward way to retrieve static text positions for a foreign window? (I know its complex but I've seen some complex code on this site, so I gave it a try...)
Wouter
|
|
|
|
|
Have you used any spy programs on the window you are attempting to get text from?
Can you determine if the text sits on a control? Or if it's drawn directly on the panel?
I hate to say this, but it really seems to me that you are trying to reinvent the wheel here. There's pretty darn good commercial software out there that does the same thing. It'll save you time and money in the long run -- NOT to invent your own app automation...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Hi, first of all thanks for your thoughts!
To reply to your message, it's partially out of interest into the windows inner workings I try to write this project. I've used the freeware AutoHotKey program to script several pieces of automation code, which were very useful in the past.
However, using the "Window Spy" program that accompanies the AHK software, no visible nor hidden text is shown for the particular window.
The program is a piece of gaming software, giving an overview of tournaments currently playing. However, the list is constantly updated, and I want to auto-join several tournaments of a specific type. However, as up till now, I have no clue how to determine which line in the overview window relates to which kind of tournament.
So the main part of my question is: Can this be done (in a straightforward way), or am i trying to do something impossible?
And to respond to the last reply, can automation software achieve this?
Wouter
|
|
|
|
|
Please help with the following problem.
My problem is a dialog based code.
I have created a new dialog window with a simple tree control and added a new member variable 'm_tree'
I created a new class for this new dialog called 'CExportDlg'
I am trying to access the tree control in the new dialog from the parent(root) dialog program.
In the parent code I execute the following code:
CExportDlg Dlg ;
Dlg.m_editbox.Format( "TEST" ) ; <--- Yet this works fine (Edit Box)
Dlg.m_tree.DeleteAllItems() ; <------- this faults every time (Tree control) !!!!!!!!
Dlg.DoModal() ;
Anybody help ???
|
|
|
|
|
|
Hello - thanks for the reply.
Yes the error comes up as
X Debug Assertion Fault
file: afxcmn.inl
By putting the code inside the new dialog class - I have solved the problem.
But even so - I would like to know if it is possible to work as I stated above.
|
|
|
|
|
Are you sure m_tree is valid?
|
|
|
|
|
sofa_2006au wrote: I am trying to access the tree control in the new dialog from the parent(root) dialog program.
Why are you wanting to do that? The child dialog should communicate with its parent via messages.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DeleteAllItems won't work because the dialog window doesn't exist yet. Your assertion is probably something about a window handle being invalid?
Controls do not go active until OnInitDialog() is called -- which doesn't happen until DoModal() is called.
The reason the other one works -- is that xxx.Format is only acting on a CString which is bound to the edit control.
Why do you need to DeleteAllItems() anyhow -- trees default to empty.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Wow
Thank you - for the reply and detailed information.
Very much appreciated
( Shows how little I know about c++ )
I kind of accidently figured this out and fixed the problem indirectly then.
Question then is:
--------------------
Can the parent setup or add/change the tree control of the child dialog.
Seems like the answer is no ?
I needed to do that as I wanted the parent to feed the tree with data.
But I think that is the wrong way to do it now?
Should the child merely be able to access some public member variable of the parent's class to access the data?
|
|
|
|
|
You know, it all depends what you want it to do.
If you just want to populate it with data, then you can pass in that data to the dialog's constructor. And then in your OnInitDialog() method, populate the controls with data.
If you want to update the dialog with "live data", then something fancier is needed.
I am no MFC whiz! I've muddled through this MFC experience with the rest of the world... I am good at answering the questions, because I have made the same mistakes... and learned a lot along the way.
Just take your time.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Hi,
I want to close the dialog in a certain time interval automatically after displaying it. Any ideas? Please excuse me if the question is very basic..
With Regards,
Sangeetha.
|
|
|
|
|
You can use of WM_TIMER and after a time send WM_CLOSE to your program.
|
|
|
|
|
Hi Whitesky,
Its working.. Thank you very much..
With Regards,
Sangeetha.
|
|
|
|
|
|
In Windows' Drawing Tool,there is a funtion that is we can select the discretioal part of the image.How can it realize?
Have I make a clear expression?;P
I appreciate your hint.
|
|
|
|
|
Do you want to select sections of an image and cut or other actions on the it?
|
|
|
|
|
Yes,I want to cut the section I select from the image.
|
|
|
|
|
Check this code:
BOOL CDialogDlg::OnInitDialog()
{
m_Image.Load("c:\\123.jpg");
}
void CDialogDlg::OnPaint()
{
CPaintDC dc(this);
m_Image.BitBlt(dc.m_hDC,0,0,800,600,0,0);
CDialog::OnPaint();
}
void CDialogDlg::OnBnClickedOk()
{
int x,y;
x=200;
y=200;
HDC dc;
HBITMAP hbit;
dc=CreateCompatibleDC(GetDC()->m_hDC);
hbit=CreateCompatibleBitmap(GetDC()->m_hDC,x,y);
SelectObject(dc,hbit);
BitBlt(dc,0,0,x,y,GetDC()->m_hDC,100,100,SRCCOPY);
CImage m_Image33;
m_Image33.Attach(hbit);
m_Image33.Save("d:\\22.bmp");
m_Image33.Detach();
DeleteDC(dc);
DeleteObject(hbit);
}
|
|
|
|
|
But the section was selected by the mouse,so the section is not a rect.
|
|
|
|