|
Turns out that it wasn't my code. It was an issue with the Detours injection utility. I used a freeware DLL injector from the web, and it worked just fine.
|
|
|
|
|
My srever software:-
#include<windows.h>
#include<iostream>
#include<winsock2.h>
#include<conio.h>
int main()
{
WSAData wsadata;
if (WSAStartup(MAKEWORD(2,0),&wsadata)!=0)
{std::cout<<"winsock startup failed\n"<<WSAGetLastError();
WSACleanup();
return -1;
}
std::cout<<"winsock startup is succes\n";
SOCKET servsock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(servsock ==INVALID_SOCKET)
{std::cout<<"socket init failed\n";
WSACleanup();
return -1;
}
std::cout<<"socket init\n";
sockaddr_in sin;
sin.sin_port=htons(80);
sin.sin_addr.s_addr=INADDR_ANY;
sin.sin_family=AF_INET;
if (bind(servsock,(sockaddr*)&sin,sizeof(sin))==SOCKET_ERROR)
{std::cout<<"FAILED TO BIND"<<WSAGetLastError();
WSACleanup();
return -1;
}
std::cout<<"Bind successful!\n";
//WSACleanup();
//while (listen(servsock,1)==SOCKET_ERROR);
SOCKET b=listen(servsock,1);
if (b==SOCKET_ERROR)
{
std::cout<<"error"<<WSAGetLastError();
getch();
return 0;
}
else
//int client;
{int len = sizeof(sin);
SOCKET client=accept( servsock,(sockaddr*)&sin,&len);
if (client==SOCKET_ERROR)
{
std::cout<<"error"<<WSAGetLastError();
}
//SOCKET client;
// while(client=accept( servsock,(sockaddr*)&sin,&len)==SOCKET_ERROR)
std::cout<<"Connection established!\n";
closesocket(client);
closesocket(servsock);
WSACleanup();
getch();
return 0;
}
}
One of my IRC friend said that my server software is terminating the accept() function quickly so my client software was giving socket init failed inspite of the fact that server software was giving "connection established ".What i am interpreting from this is that the accept() function of the server software is not returning SOCKET_ERROR
otherwise it would not have given "connection established " because my accept function is in "if" statement.But if i keep my Accept function within the while statement (lines 48 and 49)my server software gives bind successful and stops and seems as if goes into an infinite loop or something
.
My client softeware :-
#include<windows.h>
#include<iostream>
#include<winsock2.h>
#include<conio.h>
//#include<stdio.h>
int main()
{
WSAData wsadata;
if(WSAStartup(MAKEWORD(2,0),&wsadata)!=0)
{
std::cout<<"1:(startup failed\n"<<WSAGetLastError();
WSACleanup();
return -1;
}
else
{
std::cout<<"2 Socket Init Success\n";
}
SOCKET mysock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(mysock==INVALID_SOCKET )
{
std::cout<<"3:(Socket Init Failed\n";
WSACleanup();
return -1;
}
else
{
std::cout<<"4 Socket Init Success\n";
sockaddr_in sin;
sin.sin_port=htons(80);
sin.sin_addr.s_addr=inet_addr("127.0.0.1");
sin.sin_family=AF_INET;
// if (connect(mysock,(sockaddr*)&sin,sizeof(sin))==SOCKET_ERROR)
//{std::cout<<"5:(Socket Init FAiled\n"<<WSAGetLastError();
// getch();
//WSACleanup();
// getch();
//return -1;
//}
int a=connect(mysock,(sockaddr*)&sin,sizeof(sin));
if(a=SOCKET_ERROR)
{std::cout<<"5 Socket Init FAiled\n"<<WSAGetLastError();
//getch();
WSACleanup();
//return -1;
getch();
//return 0;
}
else
std::cout<<"connection sucessful";
closesocket(mysock);
getch();
return 0;
}
}
<b>My client software is giving an output of "Socket Init FAiled"
and in place of WSAGetLastError() it is giving error "0".i reffered to msdn there is no such thing as error 0</b>
|
|
|
|
|
if(a=SOCKET_ERROR)
should be
if(a==SOCKET_ERROR)
That's why it's a good idea to put constants first when comparing - then the compiler
will surely catch the error:
if(SOCKET_ERROR==a)
Also...
listen() returns an int, not a SOCKET.
accept() returns INVALID_SOCKET on an error, not SOCKET_ERROR.
Yes they may be the same binary value, but little errors like
that can multiply into problems
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am currently using Visual Studio .NET 2003. I am doing 3d drawing and I have encountered a problem with rotating the object using a rotation matrix. Once it is drawn in the canvas the object is deformed because the command dc.MoveTo and dc.LineTo converts the double and float values computed from the trigonometric functions into integer values. Is there a way to remedy this problem?
|
|
|
|
|
Hi, I little bit understood ur problem
Maybe you can generate some intermediate poits between original points in matrix by taking avg of two original pts etc connect them also.
I'm sorry if its not helpful..
--
"Programming is an art that fights back!"
|
|
|
|
|
Are you trying to use DirectX to do this within a MFC application? Is your object a Mesh, or what? And, finally, how did you generate this rotation matrix?
To really have control over 3D object display and movement, you should do this with DirectX. It takes awhile to set everything up, but, offers a highly evolved set of APIs to display graphics, offers incredible control over all aspects of display, and looks fabulous.
I also have Visual C++ NET 2003. Read through the available DirectX 8 documentation. There are many code examples that are included with the DirectX SDK. Also, you can use both managed and unmanaged versions of DirectX 9.
As a final note, this type of operation can be done without using DirectX, but, you should have a good understanding of all the trigonometry involved. And, you will be implementing alot of functions that already exist and are thoroughly tested and reliable.
This is: The MSDN Direct3D 9 Reference[^]. With DirectX you begin with, IDirect3DDevice9[^] instead of a MFC canvas.
This is: The Getting Started with DirectX 9[^] documentation at MSDN.
|
|
|
|
|
Thanks for the advice. I am using the MFC canvas, I didn't know I could use directX. I'll try using that. My object is a 3d figure drawn through the use of the CDC paint commands of MFC. The rotation matrix is just a formula , a matrix multiplied to the coordinates of the object in order to change the necessary coordinates when rotated at a certain angle. My problem lies with the dc.LineTo command because it only accepts integer values and the trigonometric computations are done using float values in order to preserve the accurate angle computations. The dc.LineTo command converts the float values to integer values hence rounding off the values into whole number. This is what deforms the figure when drawn because the coordinates are rounded off. Anyway, I'll try studying directx and I would be able to animate it using that tool. Thanks for the useful advice.
|
|
|
|
|
I have made a program that acts a little stranger:
- if the interface of Windows is the originally one installed:
(Left click on My Computer, Properties, Advanced, Performance, "Let Windows choose ...") the program crushes in Windows "style", the error been C0000005
- if I change the interface (Left click on My Computer, Properties, Advanced, Performance, Adjust for best performance) everything goes fine
Debugging the program I found some bad things that I have corrected.
The question is: why in second case the errors are not present?
The program is written in VC++6, w.SP5
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Maybe running in debug mode and stepping will help to find which line cause exception?
--
"Programming is an art that fights back!"
|
|
|
|
|
I fixed the problem using the other reply. Thanks for your attention.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi, I think that Keith Rule's Debugging Release Mode Problems[^] article could help you. Please have a look into it. You maybe trying to access an unallocated pointer.
Regards,
Mihai Moga
|
|
|
|
|
Thanks a lot !!!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
As you know there is no API to get thread current working state (Suspended, running, etc)
I need to check a thread working state. I have ThreadId and ThreadHandle.
I know there is a way to get thread state, but i don't know what it is!
Can anybody help?
http://www.softprojects.org/
modified on Sunday, June 29, 2008 12:45 AM
|
|
|
|
|
|
GetExitCodeThread() will check if the thread is active or not.
You shouldn't be suspending threads so that shouldn't be an issue,
unless you're writing a debugger.
There's no reliable way to get the suspended state - that state
can change at any time. You could use SuspenfThread() and check the
return value. If it returns >= 1 then the thread was already suspended.
Don't forget to call ResumeThread().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: GetExitCodeThread() will check if the thread is active or not.
Thanks, this can help.
Mark Salsbery wrote: There's no reliable way to get the suspended state - that state
can change at any time. You could use SuspenfThread() and check the
return value. If it returns >= 1 then the thread was already suspended.
Don't forget to call ResumeThread().
Good idea , but I don't want to change thread state, and the thread shouldn't suspend even a millisecond.
http://www.softprojects.org/
|
|
|
|
|
If found how to check thread suspended state.
With ResumeThread.
Here MSDN help:
The ResumeThread function checks the suspend count of the subject thread. If the suspend count is zero, the thread is not currently suspended. Otherwise, the subject thread's suspend count is decremented. If the resulting value is zero, then the execution of the subject thread is resumed.
If the return value is zero, the specified thread was not suspended. If the return value is 1, the specified thread was suspended but was restarted. If the return value is greater than 1, the specified thread is still suspended.
|
|
|
|
|
I am having a conceptual problem with a program I want to create. The application will be a galactic simulator. The user will be able to edit and create some number of stars giving them arbitrary values for mass, position, and velocity. The application will calculate how the stars orbit each other and display them on the screen in a 3D format.
The number of stars can vary. I plan to use a linked list to hold all the stars. In this manner, each star object can traverse the entire list and calculate how each other star affects it. Then each star object can calculate where it will be at the end of each simulation step.
I start off by creating a basic dialog driven application using Visual Studio, C++, and static linked MFC. (I am open to suggestions) Then I need to have a place to anchor the linked list of stars. I envision a class whose entire purpose is just to provide the linked list. It will contain the methods to link items into the list and remove them. I can use STL, but the exact implementation is not important.
My problem is: Where and how should I declare and instantiate the object of that list?
Windows applications does not have a main() that sticks around for the life of the application.
For ease of discussion, let us say the list class is named:
CLinkedList
and the object instantiated will be:
ListAnchor.
The objects contained in the list will be of class:
CStar
and will be created thusly:
CStar new_star = new( CStar );
To put the new star in the list I envision writing a line of code that looks something like:
ListAnchor.LinkNewStar( new_star );
Or maybe
ListAnchor->LinkNewStar( new_star );
When I create my new Windows dialog application the name will be StarSimulator and Windows will create StarSimulator.h, StarSimulator.cpp, StarSimulatorDlg.h, StarSimulatorDlg.cpp and a host of other support files. I don't think anyone wants me to post any of those files. Assume the standard environment for Visual Studio 2008 running on Windows XP and using C++.
Where and how should I declare and instantiate this object ListAnchor?
If my entire approach is wrong, please advise.
Thanks for your time
|
|
|
|
|
Hint, see MFC 's theApp variable of your application.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello Pallini,
I think I am working now.
I went into the .h file and just below theApp added:
extern Ctest1App theApp;
extern CGalacticEndPoints ListAnchor;
Note: I am on another version trying to get things working and changed some names)
Then in the .cpp file, again just under theApp I added:
Ctest1App theApp;
CGalacticEndPoints ListAnchor;
And finally, in the class that creates the new star objects I added:
CGalacticBody *new_body = new( CGalacticBody);
ListAnchor.Link_New_Body( new_body );
And to my joy, it not only compiled, it linked, then when I stepped through the debugger, it put my new object in the list.
That just did not strike me as the right place.
Thank you for your help.
Thanks for your time
|
|
|
|
|
That's two global variables.
I personally prefer to only have the one app global variable.
Any other object that is application-wide ("global") can be added to the
app class and accessed through the one global app object instead of adding
another global variable.
Just a thought
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark said: That's two global variables.
I am not understanding that.
If I comment out the line in the .h file, then the functions that reference this object don’t know about it and compile with an undeclared identifier.
If I comment out the line in the cpp file, the link fails with unresolved external symbol.
If the code in my previous post generates two global variables, what is the full name of each? What lines of code would you write?
Thanks for your time
|
|
|
|
|
bkelly13 wrote: If the code in my previous post generates two global variables, what is the full name of each?
theApp and ListAnchor.
bkelly13 wrote: What lines of code would you write?
I meant something like the following - one global variable (theApp):
#pragme once
#include "GalacticEndPoints.h"
class Ctest1App : public CWinApp
{
protected:
CGalacticEndPoints ListAnchor;
public:
CGalacticEndPoints &GetListAnchor() {return ListAnchor;}
};
extern Ctest1App theApp;
#include "stdafx.h"
#include "test1App.h"
Ctest1App theApp;
...
#include "stdafx.h"
#include "somemodule.h"
#include "test1App.h"
...
CGalacticBody *new_body = new( CGalacticBody);
theApp.GetListAnchor().Link_New_Body( new_body );
...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello friends~
I have some questions about MFC.
During I wrote the code, the error was occuring about this.
I use Visual studio 2005. I found many imformation. It's not occur at Visual studio 6.0.
And I use UNICODE.
Plz, help me. I didn't resolve this for 1 hour.
I found MSDN, and Search many sites, but I didn't resolve.
It doesn't not work.
fp = fopen(pDlg.GetPathName(), _T("r"));
fp = fopen(pDlg.GetPathName(), _T("rb"));
//////////////////////////////////////////
FILE *fp;
fp = fopen(pDlg.GetPathName(), "r");
//////////////////////////////////////////
FILE *fp;
fp = fopen(pDlg.GetPathName(), "w");
//////////////////////////////////////////
------ Build started: Project: MFC_4_2, Configuration: Debug Win32 ------
Compiling...
MFC_4_2Dlg.cpp
d:\data\programing\c++\sc\mfc\mfc_4_2\mfc_4_2dlg.cpp(238) : error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
d:\data\programing\c++\sc\mfc\mfc_4_2\mfc_4_2dlg.cpp(261) : error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Build log was saved at "file://d:\Data\Programing\C++\sc\MFC\MFC_4_2\Debug\BuildLog.htm"
MFC_4_2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
Use _tfopen , for instance:
FILE *fp;
fp = _tfopen(pDlg.GetPathName(), _T("r"));
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|