I get a strange error complaining about stack corruption I'm assuming, and I have debugged it a bit but I haven't found out the issue. I also can't seem to implement nothrow in Visual Studio 2010!
XYZ::XYZ(char * d)
{
hostname = new char[HOSTNAME_LENGTH];
ip = new char[IP_ADDR_LENGTH];
/*Dynamic Memory*/
memset(hostname, 0, HOSTNAME_LENGTH);
memset(ip, 0, IP_ADDR_LENGTH);
//strncpy(hostname, d, HOSTNAME_LENGTH);
if(dWSAStartup(MAKEWORD(2,2), &wsd) == 0) //Crashes Here!
//And so on..
dWSAStartup is dynamically linked from ws2_32.dll and has correct function parameters typecasted:
typedef int (*WSAS)(WORD, LPWSADATA); //WSAStartup
And no, th开发者_如何学Pythone FreeLibrary function hasn't been called -- so the function pointer IS valid!
This bug is the only thing stopping me! Would anyone throw me a pointer?
typedef int (*WSAS)(WORD, LPWSADATA); //WSAStartup
That's wrong, the calling convention is missing. It defaults to __cdecl which is not the way it is declared in winsock2.h. Which is why you are getting the runtime diagnostic, after the call it pops the arguments off the stack, something that was already done by WSAStartup(). An imbalanced stack is the result. Fix:
typedef int (__stdcall * WSAS)(WORD, LPWSADATA); //WSAStartup
The actual declarator used is FAR PASCAL, networking apis are strongly preserved from the previous century. Give your compiler a bit of love for warning you about this, imbalanced stacks are extremely hard to diagnose without the auto-generated debugging code.
精彩评论