This topic is now archived and is closed to further replies.


http call from directx application

Recommended Posts

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.


Share this post

Link to post
Share on other sites
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;
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


// Tell WinSock we want version 2

wVersionRequested = MAKEWORD( 2, 0 );

// Initialize the socket handle


// 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


cout << "<-- SOCKET CREATED -->" << endl;

// Initialize the server address data structure

// 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


// 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


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

// Clean up WinSock


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

Let me know if that helps!

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

Share this post

Link to post
Share on other sites
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!!!


Share this post

Link to post
Share on other sites
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:


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.

Share this post

Link to post
Share on other sites