Changeset - r2183:34cce39e9f47
[Not reviewed]
master
0 2 1
tron - 19 years ago 2005-07-24 06:09:54
tron@openttd.org
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
3 files changed with 27 insertions and 20 deletions:
sdl.c
2
2
win32.c
18
18
0 comments (0 inline, 0 general)
sdl.c
Show inline comments
 
@@ -14,13 +14,13 @@
 
#endif
 

	
 
static int _sdl_usage;
 

	
 
#ifdef DYNAMICALLY_LOADED_SDL
 

	
 
bool LoadLibraryList(void **proc, const char *dll);
 
#include "win32.h"
 

	
 
#define M(x) x "\0"
 
static const char sdl_files[] =
 
	M("sdl.dll")
 
	M("SDL_Init")
 
	M("SDL_InitSubSystem")
 
@@ -56,13 +56,13 @@ static const char sdl_files[] =
 
SDLProcs sdl_proc;
 

	
 
static const char *LoadSdlDLL(void)
 
{
 
	if (sdl_proc.SDL_Init != NULL)
 
		return NULL;
 
	if (!LoadLibraryList((void**)&sdl_proc, sdl_files))
 
	if (!LoadLibraryList((Function*)&sdl_proc, sdl_files))
 
		return "Unable to load sdl.dll";
 
	return NULL;
 
}
 

	
 
#endif // DYNAMICALLY_LOADED_SDL
 

	
win32.c
Show inline comments
 
@@ -11,51 +11,51 @@
 
#include <windows.h>
 
#include <winnt.h>
 
#include <wininet.h>
 
#include <io.h>
 
#include <fcntl.h>
 
#include "variables.h"
 
#include "win32.h"
 

	
 
#include "driver.h"
 

	
 
#include "music/dmusic.h"
 
#include "music/null_m.h"
 
#include "music/win32_m.h"
 

	
 
#include "sound/null_s.h"
 
#include "sound/sdl_s.h"
 
#include "sound/win32_s.h"
 

	
 
#include "video/dedicated_v.h"
 
#include "video/null_v.h"
 
#include "video/sdl_v.h"
 
#include "video/win32_v.h"
 

	
 
static bool _has_console;
 

	
 
#if defined(__MINGW32__) || defined(__CYGWIN__)
 
	#define __TIMESTAMP__   __DATE__ __TIME__
 
#endif
 

	
 

	
 
// Helper function needed by dynamically loading SDL
 
bool LoadLibraryList(void **proc, const char *dll)
 
bool LoadLibraryList(Function proc[], const char* dll)
 
{
 
	HMODULE lib;
 
	void *p;
 

	
 
	while (*dll != '\0') {
 
		lib = LoadLibrary(dll);
 
		if (lib == NULL)
 
			return false;
 
		HMODULE lib = LoadLibrary(dll);
 

	
 
		if (lib == NULL) return false;
 
		while (true) {
 
			while(*dll++ != '\0');
 
			if (*dll == '\0')
 
				break;
 
		  	FARPROC p;
 

	
 
			while (*dll++ != '\0');
 
			if (*dll == '\0') break;
 
			p = GetProcAddress(lib, dll);
 
			if (p == NULL)
 
				return false;
 
			*proc++ = p;
 
			if (p == NULL) return false;
 
			*proc++ = (Function)p;
 
		}
 
		dll++;
 
	}
 
	return true;
 
}
 

	
 
@@ -178,13 +178,13 @@ static char *PrintModuleList(char *outpu
 
	HANDLE proc;
 
	HMODULE modules[100];
 
	DWORD needed;
 
	BOOL res;
 
	int count,i;
 

	
 
	if (LoadLibraryList((void*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0")) {
 
	if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0")) {
 
		proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
 
		if (proc) {
 
			res = EnumProcessModules(proc, modules, sizeof(modules), &needed);
 
			CloseHandle(proc);
 
			if (res) {
 
				count =
 
@@ -238,21 +238,21 @@ static const char wininet_files[] =
 
	M("");
 
#undef M
 

	
 
static WinInetProcs _wininet;
 

	
 

	
 
static char *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const char *arg)
 
static const char *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const char *arg)
 
{
 
	HINTERNET inet, conn, http;
 
	char *err = NULL;
 
	const char *err = NULL;
 
	DWORD code, len;
 
	static char buf[100];
 
	char buff[100];
 

	
 
	if (_wininet.InternetOpen == NULL && !LoadLibraryList((void**)&_wininet, wininet_files)) return "can't load wininet.dll";
 
	if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return "can't load wininet.dll";
 

	
 
	inet = _wininet.InternetOpen("OTTD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
 
	if (inet == NULL) { err = "internetopen failed"; goto error1; }
 

	
 
	conn = _wininet.InternetConnect(inet, "openttd.com", INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);
 
	if (conn == NULL) { err = "internetconnect failed"; goto error2; }
 
@@ -365,13 +365,13 @@ static BOOL CALLBACK CrashDialogFunc(HWN
 
				MessageBoxA(wnd, _save_succeeded, "Save successful", MB_ICONINFORMATION);
 
			else
 
				MessageBoxA(wnd, "Save failed", "Save failed", MB_ICONINFORMATION);
 
			break;
 
		}
 
		case 14: { // Submit crash report
 
			char *s;
 
			const char *s;
 

	
 
			SetCursor(LoadCursor(NULL, IDC_WAIT));
 

	
 
			s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), "");
 
			if (s) {
 
				MessageBoxA(wnd, s, "Error", MB_ICONSTOP);
win32.h
Show inline comments
 
new file 100644
 
#ifndef WIN32_H
 
#define WIN32_H
 

	
 
typedef void (*Function)(int);
 
bool LoadLibraryList(Function proc[], const char* dll);
 

	
 
#endif
0 comments (0 inline, 0 general)