Valhalla Legends Forums Archive | Battle.net Bot Development | [C++] Questions

AuthorMessageTime
bethra
I'm trying to make a bot in VC++ 6 since I've successfully made one in VB6.  I'm running into a few problems.  I have some questions.

1.  Does VC++ Winsock v2 have Events, separate functions that are triggered when ___ happens lik in VB6 Winsock?  If so, can I get a simple example of using a VC++ Winsock Event?  I could not find anything in the MSDN Library or the C++ Winsock Tutorials to help.
2.  Can a typedef Structure be sent as a readable packet to a socket?
3.  When converting a null-terminating string to a non-null-terminating string, is this an efficient way of doing so?
[code]
strncpy(strDest, strSrc, strlen(strSrc) - 1)
[/code]
4.  Should I avoid using Windows API or MFC classes if I don't plan to use a Windows GUI, but a command line interface?
5.  What is the most efficient way of creating a dynamic string/array?
6.  When making a packet buffer/debuffer is it better to use a external cpp source file to define member functions and functions, or should I put them in the header file itself?
7.  Lastly, Do you dislike VB?  Now I do!  It is the Devil, VB666!


Thanks.
November 17, 2004, 9:22 PM
BaDDBLooD
1. You can add support for events i believe
2. no idea
3. That seems like a bad way of doing it in my opinion.
4. Yes
5. no idea
6. I would put them in the header file
7. I Like vb, c is alot better in my opinion.
November 17, 2004, 9:28 PM
UserLoser.
Winsock events:

WSAEventSelect
WSAAsyncSelect
__WSAFDIsSet
November 17, 2004, 9:35 PM
bethra
[quote author=UserLoser link=topic=9586.msg89141#msg89141 date=1100727330]
Winsock events:

WSAEventSelect
WSAAsyncSelect
__WSAFDIsSet
[/quote]

ok

Here is the exampe that was given for the WSAEventSelect.
[quote]
//-------------------------
// Declare and initialize variables
SOCKET ListenSocket;
WSAEVENT NewEvent;
sockaddr_in InetAddr;

//-------------------------
// Initialize listening socket
ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

//-------------------------
// Bind listening socket
InetAddr.sin_family = AF_INET;
InetAddr.sin_addr.s_addr = htonl(INADDR_ANY);
InetAddr.sin_port = htons(27015);

bind (ListenSocket, (SOCKADDR *) &InetAddr, sizeof(InetAddr));

//-------------------------
// Create new event
NewEvent = WSACreateEvent();

//-------------------------
// Associate event types FD_ACCEPT and FD_CLOSE
// with the listening socket and NewEvent
WSAEventSelect( ListenSocket, NewEvent, FD_ACCEPT | FD_CLOSE);
[/quote]

I think I understand what its doing.  However in this example it doesn't show the actual "NewEvent" as its own function thingy where the code that is suppose to be executed when it is fired.

hmmm how is the Event's code that is to be executed defined or coded?  You have to make a function to do so?  I know that in VB you can make an Event's function by taking the object's name and then add _ and the event name.
this would be in VB:
[code]
Sub TheObject_TheEventName(Args)
'code to be executed
End Sub
[/code]

but C++?
November 17, 2004, 10:04 PM
UserLoser.
[quote author=bethra link=topic=9586.msg89148#msg89148 date=1100729065]
I think I understand what its doing.  However in this example it doesn't show the actual "NewEvent" as its own function thingy where the code that is suppose to be executed when it is fired.

hmmm how is the Event's code that is to be executed defined or coded?  You have to make a function to do so?
[/quote]

Using Events

Note: This is much more complex than using mswinsck.ocx in VB6
November 17, 2004, 10:22 PM
Kp
[quote author=BaDDBLooD link=topic=9586.msg89140#msg89140 date=1100726937]2. no idea
3. That seems like a bad way of doing it in my opinion, however it does work.[/quote]

2. Yes, it's completely possible.  A structure is just a way of laying out data in memory, and you can send any readable memory over a socket.  Whether it achieves your goal is an entirely different question, of course.
3. That is not only a bad way of doing it, it doesn't work.  In fact, it accomplishes absolutely nothing since it copies the string onto itself.
November 17, 2004, 11:17 PM
BaDDBLooD
[quote author=Kp link=topic=9586.msg89172#msg89172 date=1100733444]
[quote author=BaDDBLooD link=topic=9586.msg89140#msg89140 date=1100726937]2. no idea
3. That seems like a bad way of doing it in my opinion, however it does work.[/quote]

2. Yes, it's completely possible.  A structure is just a way of laying out data in memory, and you can send any readable memory over a socket.  Whether it achieves your goal is an entirely different question, of course.
3. That is not only a bad way of doing it, it doesn't work.  In fact, it accomplishes absolutely nothing since it copies the string onto itself.
[/quote]

Thanks, for correcting my answer.  I did not know that.  I am new to c  :-\
November 18, 2004, 12:41 AM
Myndfyr
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
1.  Does VC++ Winsock v2 have Events, separate functions that are triggered when ___ happens lik in VB6 Winsock?  If so, can I get a simple example of using a VC++ Winsock Event?  I could not find anything in the MSDN Library or the C++ Winsock Tutorials to help.
[/quote]
What you'll find is that you'll have to get function pointer callbacks yourself to pass for functions, not like in VB.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
3.  When converting a null-terminating string to a non-null-terminating string, is this an efficient way of doing so?
[code]
strncpy(strDest, strSrc, strlen(strSrc) - 1)
[/code]
[/quote]
Most every use for non-null-terminating strings in Battle.net communication are those four-byte DWORDs.  You can define them instead as:
[code]
// assumed typedef long int DWORD;
DWORD myProductId = 'STAR';
[/code]
Note the single quotes.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
4.  Should I avoid using Windows API or MFC classes if I don't plan to use a Windows GUI, but a command line interface?
[/quote]
You don't need to avoid the API unless you want to be able to compile it cross-platform.  As for MFC, if you want your bot to be bloated and contain loads of meaningless nothings, don't use it.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
5.  What is the most efficient way of creating a dynamic string/array?
[/quote]
This would be a question better suited to others.  :)  Sorry.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
6.  When making a packet buffer/debuffer is it better to use a external cpp source file to define member functions and functions, or should I put them in the header file itself?
[/quote]
This seems to miss the point of header files and external files.  When making *any* class it is good practice to define function interfaces in the header and make the actual functions in the code CPP files.
November 18, 2004, 12:50 AM
Mephisto
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
I'm trying to make a bot in VC++ 6 since I've successfully made one in VB6.  I'm running into a few problems.  I have some questions.

1.  Does VC++ Winsock v2 have Events, separate functions that are triggered when ___ happens lik in VB6 Winsock?  If so, can I get a simple example of using a VC++ Winsock Event?  I could not find anything in the MSDN Library or the C++ Winsock Tutorials to help.
2.  Can a typedef Structure be sent as a readable packet to a socket?
3.  When converting a null-terminating string to a non-null-terminating string, is this an efficient way of doing so?
[code]
strncpy(strDest, strSrc, strlen(strSrc) - 1)
[/code]
4.  Should I avoid using Windows API or MFC classes if I don't plan to use a Windows GUI, but a command line interface?
5.  What is the most efficient way of creating a dynamic string/array?
6.  When making a packet buffer/debuffer is it better to use a external cpp source file to define member functions and functions, or should I put them in the header file itself?
7.  Lastly, Do you dislike VB?  Now I do!  It is the Devil, VB666!


Thanks.
[/quote]

Hello, and welcome to the vast world of C++.  You'll be introduced to plenty of headaches, frustrations, and annoyances as you program your bot, but in the end with good design quality, your application will be superior to your VB application and you will feel a great sense of accomplishment.  :)

Let's answer your questions:

Question: Does Winsock2 support events in C++?
Answer: Yes; with WSAEventSelect (Or WSAsyncSelect [note: not truely asynchronous]) you can create socket events.  You can use these events in a number of functions you may want to look into using when you begin your network programming such as WSAEnumNetworkEvents & WaitForMultipleObjectsEx.  Keeping in mind socket events are somewhat more complicated and differ in complexity to VB6's implementation through mswinsck.ocx.

Question: Can you insert a typedef structure into your packet buffer and send it to a server as a valid/readable packet?
Answer: Yes; you can send any valid data to a server.  However, it'll be up to you to determine whether the data is valid for that particular packet and how much space the structure is going to take up.

Question: Is this code an efficient way of transforming a NULL terminated string to a non-NULL terminated string? strncpy(strDest, strSrc, strlen(strSrc) - 1)?
Answer: No; you should look at your code over again.  What you are doing (providing char *strSrc = strDest) is copying strSrc to strDest which is the same thing subtracting 1 from the strlen.  So you are essentially copying the first three letters of the string over the first three letters of the string, leaving elements 3 & 4 ('whatever' and '\0') remaining how they were; thus you have accomplished nothing.  There is also no logical reason I can think of as to why you would want to eliminiate the NULL terminator from a string.

Question: Should using MFC or the Win32 API be avoided if I'm going to use this bot as a moderation bot from the command-line or console?
Answer: Yes and no; you won't be needing MFC if you're going to be using it as a console as MFC is a wrapper for the GUI functions of the Win32 API.  However, you should definitely use the Win32 API to benefit your program if it's going to run as an application on Windows.  In fact, if you're going to use winsock2.h you'll likely be using windows.h for some thing (for instance, if you're goind to use socket events, and you'll be waiting on them for activity, you'll be using WaitForMultipleObjects which is in windows.h).

Question: What is the most efficient way of dynamically allocating an array of string?
Answer: char *buf = new char[SOME_SIZE];  And of course, when you're finished with it: delete [] buf;  That's about as efficient of a way as I can think of (really, the only way as malloc is called from new anyhow).

Question: When creating a packetbuffer, should I put the definitions in a seperate source file and the declarations in a header file or all of them in one?
Answer: Typically, you'll want to create a generic class packet buffer where you can use it in other applications without changing anything.  You can then derive from that class to implement a Battle.net specific packet buffer with little work as most of it is done in the generic base class.  You'll declare/create the class in a header file, and define the member functions/methods in a source file.  The exception to this would be inline functions, which usually always go in the header file.

Question: VB sucks, C++ owns, what do you think?
Answer: VB6 is fine as long as you use it for what it was meant for.  C++ the same; though obviously C++'s boundries are quite limitless.  :)

And as always before you ask a question here: Go to google.com (or search.msn.com) and type in the name of the function you want to know about and it should come up on the top 1-10 search a link to MSDN about the function.  Unless of course the function is like 'copy' where hundreds of thousands of other Websites will come up; in those cases you'll have to narrow your search to something like "C++ copy()."  If you have any questions you can message me on MSN at mephisto@zodiaclegends.com or AIM at SoR Mephisto zL.
November 18, 2004, 4:38 AM
Zakath
[quote author=Mephisto link=topic=9586.msg89216#msg89216 date=1100752724]char *buf = new char[SOME_SIZE];  And of course, when you're finished with it: delete buf;  That's about as efficient of a way as I can think of (really, the only way as malloc is called from new anyhow).
[/quote]

Note the one glaring problem with that: it should be [code]delete [] buf;[/code]Using operator delete and not operator delete [] on an array will cause a memory leak.

[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
I'm trying to make a bot in VC++ 6 since I've successfully made one in VB6.  I'm running into a few problems.  I have some questions.

1.  Does VC++ Winsock v2 have Events, separate functions that are triggered when ___ happens lik in VB6 Winsock?  If so, can I get a simple example of using a VC++ Winsock Event?  I could not find anything in the MSDN Library or the C++ Winsock Tutorials to help.[/quote]
People have already mentioned WSAEventSelect() and WSAAsyncSelect(), but there is also the method of polling the socket regularly via the select() function.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
2.  Can a typedef Structure be sent as a readable packet to a socket?[/quote]
The send() function expects the data in the form of a const char *. It might be interesting to create a class with an overloaded operator char * that assembles the pertinent data into such a buffer.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
3.  When converting a null-terminating string to a non-null-terminating string, is this an efficient way of doing so?
[code]
strncpy(strDest, strSrc, strlen(strSrc) - 1)
[/code][/quote]
As has been mentioned, in C/C++ there is really no such thing as a non-null-terminated string.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
4.  Should I avoid using Windows API or MFC classes if I don't plan to use a Windows GUI, but a command line interface?[/quote]
If you're using a command line, the API won't be much use even if you WANT to use it somehow...there are some functions in Windows.h that probably will come in handy, though.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
5.  What is the most efficient way of creating a dynamic string/array?[/quote]
See above.
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
6.  When making a packet buffer/debuffer is it better to use a external cpp source file to define member functions and functions, or should I put them in the header file itself?[/quote]
It comes down to programming standards and readability. If you wanted, you could put an entire bot into one source file...but would you want to?
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
7.  Lastly, Do you dislike VB?  Now I do!  It is the Devil, VB666![/quote]
I've never been a fan of VB.
November 18, 2004, 5:24 AM
Sargera
Ah, didn't even think about it when I was typing it to delete [] buf;  Thanks for pointing that out Zakath.  :)
November 18, 2004, 6:07 AM
bethra
bleh

Yeah, the winsock .ocx in VB6 is soooo much easier!  Atleast the Event aspects of it

I still can't seem to figure out how to make events.  I look at all the stuff I find in google and none of it really doesn't help.

I'm just probably stupid.

doh.
November 19, 2004, 8:54 PM
Kp
[quote author=bethra link=topic=9586.msg89396#msg89396 date=1100897678]I'm just probably stupid.[/quote]

It'd be more efficient to use overlapped I/O.  See GetQueuedCompletionStatus, CreateIoCompletionPort, WriteFile, and ReadFile.  Not necessarily in that order.
November 20, 2004, 12:05 AM
Mephisto
[quote author=Kp link=topic=9586.msg89420#msg89420 date=1100909104]
[quote author=bethra link=topic=9586.msg89396#msg89396 date=1100897678]I'm just probably stupid.[/quote]

It'd be more efficient to use overlapped I/O.  See GetQueuedCompletionStatus, CreateIoCompletionPort, WriteFile, and ReadFile.  Not necessarily in that order.
[/quote]

Also WSARecv & WSASend & WSABUF structure.

HANDLE SocketEvent = CreateEvent(0, 0, 0, 0); // the parameters are generally not necessary in most cases
WSAEventSelect(YourSocket, SocketEvent, FD_CONNECT|FD_CLOSE); // you can look up the flags in the last parameter on MSDN
You now have a socket event bound to your socket.  You can use it how you need to.
November 20, 2004, 12:07 AM
Kp
[quote author=Mephisto link=topic=9586.msg89421#msg89421 date=1100909260]Also WSARecv & WSASend & WSABUF structure.

HANDLE SocketEvent = CreateEvent(0, 0, 0, 0); // the parameters are generally not necessary in most cases
WSAEventSelect(YourSocket, SocketEvent, FD_CONNECT|FD_CLOSE); // you can look up the flags in the last parameter on MSDN
You now have a socket event bound to your socket.  You can use it how you need to[/quote]

No, don't look at those.  Using those isn't as efficient or convenient as overlapped I/O.
November 20, 2004, 5:58 AM
Eibro
Speaking from experience, the easiest (or as Kp put it, most convenient) way to deal with async sockets is overlapped I/O. Specifically, overlapped completion routines. If you're building a server application you may want to go with overlapped completion ports.

If you want a minimal example of how to use completion routines, see http://cs.smu.ca/~e_brooks/overlapped.cpp
November 20, 2004, 6:29 AM
OnlyMeat
MyndFyre i suggest you stick to your interpreted languages as you clearly dont understand c++.

[quote author=MyndFyre link=topic=9586.msg89188#msg89188 date=1100739050]
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
1.  Does VC++ Winsock v2 have Events, separate functions that are triggered when ___ happens lik in VB6 Winsock?  If so, can I get a simple example of using a VC++ Winsock Event?  I could not find anything in the MSDN Library or the C++ Winsock Tutorials to help.
[/quote]
What you'll find is that you'll have to get function pointer callbacks yourself to pass for functions, not like in VB.
[/quote]

That is complete non-sense you dont need function pointers to use winsock, the easiest way would be to use windows messaging.

Use WSAAsyncSelect to first select which winsock events you wish to be notified about i.e FD_READ. Then just call the standard berkley implementation functions i.e recv(). This will then call your main winproc message handling function with your custom message that you passed to WSAAsyncSelect.

Another way would be to use WSAEventSelect which is more suitable for UI less applications and possibly if you wish to handle events using additional threads.

WSAEventSelect  works by using kernel events in conjunction with WSAWaitForMultipleEvents and WSAEnumNetworkEvents, generally you would fire off a separate thread polling the WSAWaitForMultipleEvents API function which enters an efficient wait state until the timeout elapses. Then you handle the specific event and possibly notify your main thread.

[quote author=MyndFyre link=topic=9586.msg89188#msg89188 date=1100739050]
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
3.  When converting a null-terminating string to a non-null-terminating string, is this an efficient way of doing so?
[code]
strncpy(strDest, strSrc, strlen(strSrc) - 1)
[/code]
[/quote]
Most every use for non-null-terminating strings in Battle.net communication are those four-byte DWORDs.  You can define them instead as:
[code]
// assumed typedef long int DWORD;
DWORD myProductId = 'STAR';
[/code]
Note the single quotes.
[/quote]

That declaration is not required you can store them in char consts and simply call

[code]
memcpy( szDestBuf+nBufOffset,szSourceBuf,strlen(szSourceBuf) );
[/code]

When you need to copy it to your winsock outgoing buffer (Packet).

Note strlen provides the actual string byte sequence length minus the trailing terminator.

[quote author=MyndFyre link=topic=9586.msg89188#msg89188 date=1100739050]
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
4.  Should I avoid using Windows API or MFC classes if I don't plan to use a Windows GUI, but a command line interface?
[/quote]
You don't need to avoid the API unless you want to be able to compile it cross-platform.  As for MFC, if you want your bot to be bloated and contain loads of meaningless nothings, don't use it.
[/quote]

The windows API has it's uses, but it can be tedious and most times you end up writing wrapper classes to implement common functionality across multiple applications.

This is where the MFC library helps out, i use it quite often it saves alot of time, in someways it simplifies programming in c++ like a 4th generation language. The people who say it's bloated like mindfyre probably have never even used it and simply jump on the purist bandwagon because other people say thats the way it is. I can tell you now MFC is very usefull it outperforms java .net  dephi vb 6.0 etc thats why the actually c++ environment is written using MFC. And thats not really an issue anyways because like i said it simply saves you from having to write API wrapper classes anyways.

The wrappers are usually quite light and provide a good infrastructure, of course you dont need to make your application pure MFC it can mix and match the best features from any of the supporting frameworks depending on your goals - STL ATL MFC etc.

MFC really comes into it's own with it's windows message routing system which makes handling/overloading windows events incredibly simplistic. The UI support is MFC's more powerfull feature so if you dont use a UI then you have to weigh up the other cons/pros of using it, like i said it's just a framework and it wont be suitable for all scenarios and like every framework or language it's not perfect so dont pay any attention to these sheep who jump on the bandwagon and try it yourself and make your own decision.

Note CString class in MFC is just like programming in vb with strings really if that helps.

[quote author=MyndFyre link=topic=9586.msg89188#msg89188 date=1100739050]
[quote author=bethra link=topic=9586.msg89138#msg89138 date=1100726557]
5.  What is the most efficient way of creating a dynamic string/array?
[/quote]
This would be a question better suited to others.  :)  Sorry.
[/quote]

You should have applied that same logic to all your answers myndfyre.

In pure c++ to create a dynamic char ( string ) array  you could do this:-

[code]
char* pszBuf = new char[1024];
[/code]

Where the new operator allocates a character array of 1024 bytes. Any structure, class, primative//defined type can be allocated this way.

You could then initialize the buffer with a string value.

[code]
memset( pszBuf ,0,1024);
memcpy( pszBuf ,szMyString, strlen(szMyString));
[/code]

And to deallocate the memory you call the delete operator.

[code]
delete [] pszBuf;
[/code]

Note the [] tells the delete operator that the memory is an array, this is important to ensure the memory is cleaned up properly.

You can use the c runtime library allocation functions ( malloc//free ) as well instead of the c++ specific new operator but in debug mode ( and release if configured correctly ) the new operator can track memory allocations etc which makes it easier to find memory leaks.
November 20, 2004, 6:37 AM
Myndfyr
[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
MyndFyre i suggest you stick to your interpreted languages as you clearly dont understand c++.
[/quote]
Wow.  Way to go flamer.  Not only did two respected vL members post after me and not argue with anything that I'd said, but then you also specifically called me out when I have done nothing to deserve it. 

[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
That is complete non-sense you dont need function pointers to use winsock, the easiest way would be to use windows messaging.

Use WSAAsyncSelect to first select which winsock events you wish to be notified about i.e FD_READ. Then just call the standard berkley implementation functions i.e recv(). This will then call your main winproc message handling function with your custom message that you passed to WSAAsyncSelect.

Another way would be to use WSAEventSelect which is more suitable for UI less applications and possibly if you wish to handle events using additional threads.

WSAEventSelect  works by using kernel events in conjunction with WSAWaitForMultipleEvents and WSAEnumNetworkEvents, generally you would fire off a separate thread polling the WSAWaitForMultipleEvents API function which enters an efficient wait state until the timeout elapses. Then you handle the specific event and possibly notify your main thread.
[/quote]
Note that he asked for events.  The only way to generate any kind of event-style methodology in C programming similar to VB is to use a callback at one level or another.  Even if you're looking at messages, guess what -- your message loop is a callback!  That's beside the point anyway. 

[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
That declaration is not required you can store them in char consts and simply call
[code]
memcpy( szDestBuf+nBufOffset,szSourceBuf,strlen(szSourceBuf) );
[/code]
When you need to copy it to your winsock outgoing buffer (Packet).
[/quote]
Why would you do that?  Why incur a memory-copying operation when you can just use them as integral constants?  Let's say you have a four-character string; the C compiler will generate a 5-byte result (4 characters plus NULL), and pad an extra 3 NULLs for proper offset, for a total usage of twice the memory.  Then you have to incur a memory copying operation to use them for their intended purpose, where it would just be easier to use a constant anyway.

[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
The windows API has it's uses, but it can be tedious and most times you end up writing wrapper classes to implement common functionality across multiple applications.

This is where the MFC library helps out, i use it quite often it saves alot of time, in someways it simplifies programming in c++ like a 4th generation language. The people who say it's bloated like mindfyre probably have never even used it and simply jump on the purist bandwagon because other people say thats the way it is. I can tell you now MFC is very usefull it outperforms java .net  dephi vb 6.0 etc thats why the actually c++ environment is written using MFC. And thats not really an issue anyways because like i said it simply saves you from having to write API wrapper classes anyways.

The wrappers are usually quite light and provide a good infrastructure, of course you dont need to make your application pure MFC it can mix and match the best features from any of the supporting frameworks depending on your goals - STL ATL MFC etc.

MFC really comes into it's own with it's windows message routing system which makes handling/overloading windows events incredibly simplistic. The UI support is MFC's more powerfull feature so if you dont use a UI then you have to weigh up the other cons/pros of using it, like i said it's just a framework and it wont be suitable for all scenarios and like every framework or language it's not perfect so dont pay any attention to these sheep who jump on the bandwagon and try it yourself and make your own decision.

Note CString class in MFC is just like programming in vb with strings really if that helps.
[/quote]
I like the object-oriented features of MFC.  But in comparing MFC to the Windows API, I've found that in most cases, MFC objects contain member methods that mirror those of the Windows API with one or two parameters difference.  CString is obviously a very handly utility class, but if that or even a couple other classes are all you end up using from MFC, is it really worth linking in the entire MFC library?

[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
You should have applied that same logic to all your answers myndfyre.
[/quote]
Way to flame, retard.

[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
In pure c++ to create a dynamic char ( string ) array  you could do this:-

[code]
char* pszBuf = new char[1024];
[/code]

Where the new operator allocates a character array of 1024 bytes. Any structure, class, primative//defined type can be allocated this way.
[/quote]
Why 1024?  What if you know your strings are never going to exceed, say, 256 bytes in length?  Is there a reason you chose an arbitrarily large number?
November 20, 2004, 8:55 AM
OnlyMeat
[quote author=MyndFyre link=topic=9586.msg89476#msg89476 date=1100940951]
[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
That is complete non-sense you dont need function pointers to use winsock, the easiest way would be to use windows messaging.

Use WSAAsyncSelect to first select which winsock events you wish to be notified about i.e FD_READ. Then just call the standard berkley implementation functions i.e recv(). This will then call your main winproc message handling function with your custom message that you passed to WSAAsyncSelect.

Another way would be to use WSAEventSelect which is more suitable for UI less applications and possibly if you wish to handle events using additional threads.

WSAEventSelect  works by using kernel events in conjunction with WSAWaitForMultipleEvents and WSAEnumNetworkEvents, generally you would fire off a separate thread polling the WSAWaitForMultipleEvents API function which enters an efficient wait state until the timeout elapses. Then you handle the specific event and possibly notify your main thread.
[/quote]
Note that he asked for events.  The only way to generate any kind of event-style methodology in C programming similar to VB is to use a callback at one level or another.  Even if you're looking at messages, guess what -- your message loop is a callback!  That's beside the point anyway. 
[/quote]

First of all he asked about winsock events which have specific ways of calling back into an application none of which include manually passing pointers to functions.

Second there are other ways of generating vb style events in c++ apart from manually passing pointers to functions. Polymorphism and COM interfaces can be used to implement this without the need to specificially pass function pointers in your application. Of course anyone who knows about the implementation of polymorphism in c++ knows it uses virtual function pointers but this is intrinsic to c++ and does not require any manual coding.

Also to note you cant use function pointers manually to call into multiple instances of a class unless it's a static ( which means it cant use member data ) or it;s a singleton, in any case it's not the best way to do it which again proves your knowlege on the subject is limited ( im not flaming im pointing out facts if you dont like it then dont print false comments ) .

[quote author=MyndFyre link=topic=9586.msg89476#msg89476 date=1100940951]
[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
That declaration is not required you can store them in char consts and simply call
[code]
memcpy( szDestBuf+nBufOffset,szSourceBuf,strlen(szSourceBuf) );
[/code]
When you need to copy it to your winsock outgoing buffer (Packet).
[/quote]
Why would you do that?  Why incur a memory-copying operation when you can just use them as integral constants?  Let's say you have a four-character string; the C compiler will generate a 5-byte result (4 characters plus NULL), and pad an extra 3 NULLs for proper offset, for a total usage of twice the memory.  Then you have to incur a memory copying operation to use them for their intended purpose, where it would just be easier to use a constant anyway.
[/quote]

If you actually read what i said then you would see that the example code was for copying to the packet buffer, which is required unless you have another way of copying a string to the packet buffer without calling memcpy?, Read first then write a response please.

[quote author=MyndFyre link=topic=9586.msg89476#msg89476 date=1100940951]
I like the object-oriented features of MFC.  But in comparing MFC to the Windows API, I've found that in most cases, MFC objects contain member methods that mirror those of the Windows API with one or two parameters difference.  CString is obviously a very handly utility class, but if that or even a couple other classes are all you end up using from MFC, is it really worth linking in the entire MFC library?
[/quote]

Firstly no one can compare MFC to the API because it's not the same thing for a start, MFC is a framework to be used in conjunction with the MS C++ implementation and the API is the offical operating system programming interface.

Secondly do you know what a wrapper is?, a wrapper is usually a thin implementation that simplifies the programming interface and thats exactly what MFC does. It provides simplified object orientated and uniform interfaces to the windows API.

If you had actually used MFC which i highly doubt you have past the use of CString then you would know it has many helper classes/wrappers that include:-

(1) Generic object serialization.
(2) Doc/view paradigm ( which is extremely powerfull and object orientated )

(3) Control subclassing
(4) Very simplistic File IO classes which implement some nice features.

And many more, really to many to mention and just proves that you have used little or none of it and are therefore not qualified to judge it.

[quote author=MyndFyre link=topic=9586.msg89476#msg89476 date=1100940951]
[quote author=OnlyMeat link=topic=9586.msg89467#msg89467 date=1100932677]
In pure c++ to create a dynamic char ( string ) array  you could do this:-

[code]
char* pszBuf = new char[1024];
[/code]
[/quote]

Why 1024?  What if you know your strings are never going to exceed, say, 256 bytes in length?  Is there a reason you chose an arbitrarily large number?
[/quote]

You are really clutching at straws are'nt you 1024 has no meaning it's called an example.

In pure c++ to create a dynamic char ( string ) array  you could do this:-

Another reason you dont understand c++, a char array in c++ is the same as a byte array except that it's signed therefore it can be used to contain not only ascii codes but other data. An example for a large buffer would be a winsock packet buffer for incoming data ( for example in game d2 clients receive amounts of data greater than 256 bytes which must be stored in a buffer. Also there is no limit on string lengths in c++, you can have a 10,000 byte char array if you so wish.
November 20, 2004, 11:55 AM
Arta
WSAAsyncSelect isn't very nice. IIRC it just creates a thread which waits on the socket and then SendMessage()s you. It's also completely unsuitable for many server applocations, which run as services. Either way, it's an extra thread for no good reason.

Overlapped IO is really quite nice: have you ever used it?
November 20, 2004, 3:03 PM
OnlyMeat
[quote author=Arta[vL] link=topic=9586.msg89497#msg89497 date=1100963009]
WSAAsyncSelect isn't very nice. IIRC it just creates a thread which waits on the socket and then SendMessage()s you. It's also completely unsuitable for many server applocations, which run as services. Either way, it's an extra thread for no good reason.

Overlapped IO is really quite nice: have you ever used it?
[/quote]

I Agree WSAAsyncSelect  is quick and dirty, completely unsuitable for server apps. I think for a single connection bot it might be ok though or a simple client http app of some sort.

I have'nt done a full implementation of overlapped IO in a project as of yet, but it does look interesting hopefully i will get a chance to try it properly soon, Iv heard alot about the scalability of it whats your take on that?
November 20, 2004, 3:35 PM
bethra
[quote author=Eibro[yL] link=topic=9586.msg89465#msg89465 date=1100932170]
Speaking from experience, the easiest (or as Kp put it, most convenient) way to deal with async sockets is overlapped I/O. Specifically, overlapped completion routines. If you're building a server application you may want to go with overlapped completion ports.

If you want a minimal example of how to use completion routines, see http://cs.smu.ca/~e_brooks/overlapped.cpp
[/quote]

Nice!  Although I copied the .cpp file and can't compile it.  I believe it has to with the library that assert() uses.  I've tried linking the libraries that MSDN Library says to use link for assert() but it doesn't seem to want to compile.
[quote]
Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
[/quote]

I tried linking each one by the Project\Settings\Link menu and it doesn't work.
I've also tried to use a pragma. No luck

that source looks awesome, I want to see if I can compile/run it and then make my own.


Damn, flaming = nothx
help + love = thxly
November 20, 2004, 6:32 PM
Zakath
You can remove the asserts. All assert does is kill the running program if the condition that follows it is false. You can use an if/else to exit(0) if you want to simulate that.
November 20, 2004, 6:53 PM
Eibro
You can complile/link it on the VC++ command line by doing the following:

cl overlapped.cpp
link overlapped.obj user32

Then to run it just type

overlapped

You can typically get to the VC++ command prompt by following Start->Programs->VC->Tools->VC Command Prompt

November 20, 2004, 7:20 PM
Arta
[quote author=OnlyMeat link=topic=9586.msg89499#msg89499 date=1100964923]
I Agree WSAAsyncSelect  is quick and dirty, completely unsuitable for server apps. I think for a single connection bot it might be ok though or a simple client http app of some sort.

I have'nt done a full implementation of overlapped IO in a project as of yet, but it does look interesting hopefully i will get a chance to try it properly soon, Iv heard alot about the scalability of it whats your take on that?
[/quote]

Good, although apparently not as good as using IO completion ports. I've not read much about that yet though. I've been using a combination of WSAEventSelect and APCs.
November 20, 2004, 11:12 PM
Mephisto
[quote author=Kp link=topic=9586.msg89462#msg89462 date=1100930334]
[quote author=Mephisto link=topic=9586.msg89421#msg89421 date=1100909260]Also WSARecv & WSASend & WSABUF structure.

HANDLE SocketEvent = CreateEvent(0, 0, 0, 0); // the parameters are generally not necessary in most cases
WSAEventSelect(YourSocket, SocketEvent, FD_CONNECT|FD_CLOSE); // you can look up the flags in the last parameter on MSDN
You now have a socket event bound to your socket.  You can use it how you need to[/quote]

No, don't look at those.  Using those isn't as efficient or convenient as overlapped I/O.
[/quote]

Isn't it overlapped I/O if you use an OVERLAPPED structure and CALLBACK procedure for a Recv complete and a Send complete?  I know it's ano an I/O completion port, but it's overlapped I/O, unless I'm mistaken.
November 20, 2004, 11:26 PM
Zakath
You are correct. Overlapped i/o is not necessarily the same thing as i/o completion ports. Such ports are one way of achieving overlapped i/o.
November 20, 2004, 11:43 PM
Mephisto
Thank you for clarifying.  Additionally, overlapped I/O ports are better used for a server application than a client application, yes?
November 21, 2004, 12:00 AM
bethra
[quote author=Eibro[yL] link=topic=9586.msg89529#msg89529 date=1100978437]
You can complile/link it on the VC++ command line by doing the following:

cl overlapped.cpp
link overlapped.obj user32

Then to run it just type

overlapped

You can typically get to the VC++ command prompt by following Start->Programs->VC->Tools->VC Command Prompt
[/quote]

Sorry, but I don't understand this.  I've have tried, but I must be doing something wrong.

VC Command Prompt? wtf?  I don't have w/e that is.  I'm using VC6++ so...
November 21, 2004, 12:29 AM
Skywing
[quote author=Mephisto link=topic=9586.msg89552#msg89552 date=1100995254]
Thank you for clarifying.  Additionally, overlapped I/O ports are better used for a server application than a client application, yes?
[/quote]
I use them for both.  It requires you to split network processing and UI/windows message processing into seperate threads, but this isn't such a bad idea as it stands because network operations don't have to wait on slow UI operations to complete like they would if you did both in the same thread.
November 22, 2004, 10:36 PM
Minux
[quote author=bethra link=topic=9586.msg89557#msg89557 date=1100996984]
[quote author=Eibro[yL] link=topic=9586.msg89529#msg89529 date=1100978437]
You can complile/link it on the VC++ command line by doing the following:

cl overlapped.cpp
link overlapped.obj user32

Then to run it just type

overlapped

You can typically get to the VC++ command prompt by following Start->Programs->VC->Tools->VC Command Prompt
[/quote]

Sorry, but I don't understand this.  I've have tried, but I must be doing something wrong.

VC Command Prompt? wtf?  I don't have w/e that is.  I'm using VC6++ so...
[/quote]

They are referring to a Console Application. You clearly need to learn more about the language and the compiler before you tackle such a task like a bot. It's nowhere like VB6 where you just get use to things and they 9/10 work. I suggest getting a book, because again you don't seem to understand the language yet.
November 23, 2004, 12:22 AM
Myndfyr
[quote author=Minus link=topic=9586.msg89761#msg89761 date=1101169322]
[quote author=bethra link=topic=9586.msg89557#msg89557 date=1100996984]
[quote author=Eibro[yL] link=topic=9586.msg89529#msg89529 date=1100978437]
You can complile/link it on the VC++ command line by doing the following:

cl overlapped.cpp
link overlapped.obj user32

Then to run it just type

overlapped

You can typically get to the VC++ command prompt by following Start->Programs->VC->Tools->VC Command Prompt
[/quote]

Sorry, but I don't understand this.  I've have tried, but I must be doing something wrong.

VC Command Prompt? wtf?  I don't have w/e that is.  I'm using VC6++ so...
[/quote]

They are referring to a Console Application. You clearly need to learn more about the language and the compiler before you tackle such a task like a bot. It's nowhere like VB6 where you just get use to things and they 9/10 work. I suggest getting a book, because again you don't seem to understand the language yet.
[/quote]

Actually, they are referring to going to the command line (i.e., running cmd.exe or command.com, depending on your environment) and using the C compiler and linker.  You need to learn more about what people are talking about before you try and flame someone who is trying to learn.
November 23, 2004, 2:00 AM
Eibro
[quote author=bethra link=topic=9586.msg89557#msg89557 date=1100996984]
[quote author=Eibro[yL] link=topic=9586.msg89529#msg89529 date=1100978437]
You can complile/link it on the VC++ command line by doing the following:

cl overlapped.cpp
link overlapped.obj user32

Then to run it just type

overlapped

You can typically get to the VC++ command prompt by following Start->Programs->VC->Tools->VC Command Prompt
[/quote]

Sorry, but I don't understand this.  I've have tried, but I must be doing something wrong.

VC Command Prompt? wtf?  I don't have w/e that is.  I'm using VC6++ so...
[/quote]Yes you do. Search for vcvars32.bat. Once you find this, open a console and run it. Then you can compile/link the application in the manner I described above.
November 23, 2004, 3:11 AM

Search