http call from directx application

Started by
6 comments, last by zoomcrypt 22 years, 10 months ago
ok we''re trying to set up an internet High Score table for our directx 2D shooter and would like our application to simply make an HTTP call to our webserver once the user has entered in their INITIALS. We''re trying to use the MFC Wininet classes but am having trouble once we compile. These implementations require multithreading and once we put Visual to compile in multithread mode everything goes to hell... Sprites are no longer blitted correctly. shot doesn''t move, etc..... Any ideas on what we are doin wrong? Any suggestions on a differnt method or set of libraries to use instead of the MFC classes? Skullone http://www.geocities.com/emersivemedia
SkullOne - Hero Interactivehttp://www.hero-interactive.com
Advertisement
I''m not sure about such stuff. But from the problems you have described, you might try to see if there are any variables that are uninitialised.

Since you''re compiling in Multithreaded mode, I guess that, it''s similar to Release mode in that, errors coccur when there are uninitialised variables.
You''re probably trying to pass data from one thread to another. When you do that, 90% of the time your data gets completely garbled, unless you use the proper multithreaded memory-management stuff (GlobalAlloc etc. I believe).

For instance, passing a CString from one thread to another, will lead to the CString containing garbage in the receiving function, while it was perfectly valid in the calling function.


People might not remember what you said, or what you did, but they will always remember how you made them feel.
Mad Keith the V.
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
I would suggest using straight Winsock over WinInet. You can find several examples of how to do this on the net. If not, drop me an email and I will help you out.

<Dak>
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
I am a little confused by your question. Are you just trying to do a HTTP post to your web-server? If so, you can use the following code to get/post to a web-server:

      // Make sure ws2_32.lib is in your project space!#include <iostream.h>#include <winsock.h>#include <stdio.h>void main(void){	SOCKET		skSocket;	sockaddr_in     saServerAddress;	int		iPort = 80,iStatus;	WSADATA		wsaData;	WORD		wVersionRequested;	LPHOSTENT	lpHost;	char		szHost[128];	char		szSendBuffer[256];	char		szRecvBuffer[32768];	int		iBytesSent;	int		iBytesReceived;	// Init the host value, change this IP to whatever valid IP you wish	sprintf(szHost,"www.lostlogic.com");	// Tell WinSock we want version 2	wVersionRequested = MAKEWORD( 2, 0 );	// Initialize the socket handle	skSocket = INVALID_SOCKET;	// Startup WinSock	iStatus = WSAStartup( wVersionRequested, &wsaData );	// Create the socket	skSocket = socket( AF_INET, SOCK_STREAM, 0 );		// Check if there was an error	if( skSocket == INVALID_SOCKET ) {		cout << "**ERROR** Could Not Create Socket" << endl;		// Clean up WinSock		WSACleanup();		exit(1);	}	cout << "<-- SOCKET CREATED -->" << endl;	// Initialize the server address data structure	memset(&saServerAddress,0,sizeof(sockaddr_in));	// Set this by default	saServerAddress.sin_family = AF_INET;	// Load the IP Address	saServerAddress.sin_addr.s_addr = inet_addr(szHost);	// If the host specified is not an IP Address we must look up the value	if( saServerAddress.sin_addr.s_addr == INADDR_NONE )	{		cout << "<-- LOOKING UP HOST IP -->" << endl;		// Get the host name		lpHost = gethostbyname(szHost);		// Check if we got something back		if (lpHost != NULL) {			// Load the server address with the host information			saServerAddress.sin_addr.s_addr = ((LPIN_ADDR)lpHost->h_addr)->s_addr;		}		else {			cout << "**ERROR** Could Not Locate Host" << endl;			// Clean up WinSock			WSACleanup();			exit(1);		}	}	// Set the Server Port	saServerAddress.sin_port = htons(iPort);	// Attempt to connect to the server	iStatus = connect(skSocket, (struct sockaddr*)&saServerAddress,sizeof(sockaddr));		// Check if there was an error	if( iStatus == SOCKET_ERROR ) {		cout << "**ERROR** Could Not Connect To Server" << endl;		// Clean up WinSock		WSACleanup();		exit(1);	}	cout << "<-- CONNECTED TO SERVER -->" << endl;	// Load the data to send	sprintf(szSendBuffer,"GET / HTTP/1.0\n\n");	// Send the HTTP Request	iBytesSent = send(skSocket,szSendBuffer,256,0);	cout << "<-- SENT " << iBytesSent << " BYTES -->" << endl;		// Wait for incoming data	iBytesReceived = recv(skSocket,szRecvBuffer,32768,0);	cout << "<-- RECEIVED " << iBytesReceived << " BYTES -->" << endl;	// Output the data received	cout << szRecvBuffer << endl;	// Close the socket	closesocket(skSocket);	// Clean up WinSock	WSACleanup();}      


The above source comes from my book(Multiplayer Game Programming) which is Copyright 2001, Prima Publishing.

Let me know if that helps!

LostLogic
www.lostlogic.com
Author, Multiplayer Game Programming


Edited by - LostLogic on June 22, 2001 6:35:48 PM

Edited by - LostLogic on June 22, 2001 6:36:27 PM

LostLogicwww.GamerOutfit.comXBox 360 Community Games Reviews and NewsExisled - 2D/3D Shooter for XBox 360

Hey thanks for all the replies. Seems like no one is too keen on the wininet libraries NOt surprised. i''m gonna go ahead and try a winsock implementation and see if that takes care of it. But yeah basically all i''m doing it HTTP Posting the following fields to a script running on my webserver:

username User supplied initals
hiscore Score for the game
ver protocol version number
quote use supplied trash talking quote
signature encrypted signature of the previous fields that
ensures that it came from my game client.


These will then be used to generate a high score table to be displayed on my website.

Thanks again everyone!!!

SkullOne
http://www.gamedev.net/community/gds/projects/default.asp?projectID=229

SkullOne - Hero Interactivehttp://www.hero-interactive.com
Sounds like the trouble is with your graphics code, not with using WinInet??? What if later on down the road you want to use multithreading for something else? Then you''ll be in the same boat...

I recommend sticking with the WinInet API as it does most of the work for you, and fixing the other issues with your code. Where does MFC come into this? WinInet is not dependent on MFC. The functions you need are:

InternetOpen()
InternetConnect()
HttpOpenRequest()
HttpSendRequest()

I''m not sure why they make it so difficult (four different function calls), but it''s less work than the code for raw sockets and has the advantage of automatically using proxies and handling headers for you.
Got it working! Thanks for the help everyone, look for a release with internet Hi Score Table by tomorrow nite!
SkullOne - Hero Interactivehttp://www.hero-interactive.com

This topic is closed to new replies.

Advertisement