2001-12-17 14:31:42 +00:00
|
|
|
/** DLL entry routine
|
1997-09-13 17:52:31 +00:00
|
|
|
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Original Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Created: 1996
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1997-09-13 17:52:31 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "gnustep/base/preface.h"
|
|
|
|
#include "Foundation/NSObjCRuntime.h"
|
|
|
|
#include "Foundation/NSString.h"
|
1997-09-13 17:52:31 +00:00
|
|
|
|
|
|
|
/* Only if using Microsoft's tools and libraries */
|
|
|
|
#ifdef __MS_WIN32__
|
|
|
|
#include <stdio.h>
|
|
|
|
WINBOOL WINAPI _CRT_INIT( HINSTANCE hinstDLL, DWORD fdwReason,
|
|
|
|
LPVOID lpReserved );
|
|
|
|
|
|
|
|
// Global errno isn't defined in Microsoft's thread safe C library
|
|
|
|
void errno()
|
|
|
|
{}
|
|
|
|
|
|
|
|
int _MB_init_runtime()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* __MS_WIN32__ */
|
|
|
|
|
2000-10-11 18:49:32 +00:00
|
|
|
void
|
|
|
|
gnustep_base_socket_init()
|
|
|
|
{
|
|
|
|
/* Start of sockets so we can get host name and other info */
|
|
|
|
static WSADATA wsaData;
|
|
|
|
if (WSAStartup(MAKEWORD(2,0), &wsaData))
|
|
|
|
NSLog(@"Error: Could not startup Windows Sockets.\n");
|
|
|
|
}
|
|
|
|
|
1997-09-13 17:52:31 +00:00
|
|
|
LONG APIENTRY
|
|
|
|
gnustep_base_socket_handler(HWND hWnd, UINT message,
|
|
|
|
UINT wParam, LONG lParam);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Global variables for socket handler
|
|
|
|
//
|
|
|
|
HWND gnustep_base_wnd;
|
|
|
|
|
|
|
|
//
|
|
|
|
// DLL entry function for GNUstep Base Library
|
|
|
|
// This function gets called everytime a process/thread attaches to DLL
|
|
|
|
//
|
|
|
|
WINBOOL WINAPI
|
|
|
|
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
switch(ul_reason_for_call)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
{
|
|
|
|
WNDCLASS wc;
|
|
|
|
|
|
|
|
#ifdef __MS_WIN32__
|
|
|
|
/* Initialize the Microsoft C stdio DLL */
|
|
|
|
_CRT_INIT(hInst, ul_reason_for_call, lpReserved);
|
|
|
|
|
|
|
|
#endif /* __MS_WIN32__ */
|
|
|
|
|
|
|
|
// Initialize Windows Sockets
|
2000-10-11 18:49:32 +00:00
|
|
|
gnustep_base_socket_init();
|
1997-09-13 17:52:31 +00:00
|
|
|
|
|
|
|
// Register a window class for the socket handler
|
|
|
|
wc.lpszClassName = "GnustepBaseSocketHandler";
|
|
|
|
wc.lpfnWndProc = gnustep_base_socket_handler;
|
|
|
|
wc.hInstance = hInst;
|
|
|
|
wc.hCursor = NULL;
|
|
|
|
wc.hIcon = NULL;
|
|
|
|
wc.hbrBackground = NULL;
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.style = 0;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
|
|
|
|
if (!RegisterClass(&wc))
|
|
|
|
NSLog(@"Error: Could not register WIN32 socket handler class.\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
{
|
|
|
|
DestroyWindow(gnustep_base_wnd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
{
|
|
|
|
#ifdef __MS_WIN32__
|
|
|
|
/* Initialize C stdio DLL */
|
|
|
|
_CRT_INIT(hInst, ul_reason_for_call, lpReserved);
|
|
|
|
#endif /* __MS_WIN32__ */
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// The window procedure for handling sockets
|
|
|
|
//
|
|
|
|
LONG APIENTRY
|
|
|
|
gnustep_base_socket_handler(HWND hWnd, UINT message,
|
|
|
|
UINT wParam, LONG lParam)
|
|
|
|
{
|
|
|
|
WORD wEvent, wError;
|
|
|
|
|
|
|
|
// If not a socket message then call the default window procedure
|
|
|
|
if (message != GNUSTEP_BASE_SOCKET_MESSAGE)
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
|
|
|
|
// Check for an error code
|
|
|
|
wError = WSAGETSELECTERROR(lParam);
|
|
|
|
if (wError != 0)
|
|
|
|
{
|
|
|
|
NSLog(@"Error: received socket error code %d\n", wError);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the event
|
|
|
|
wEvent = WSAGETSELECTEVENT(lParam);
|
|
|
|
switch (wEvent)
|
|
|
|
{
|
|
|
|
case FD_READ:
|
|
|
|
NSLog(@"Got an FD_READ\n");
|
|
|
|
break;
|
|
|
|
case FD_WRITE:
|
|
|
|
NSLog(@"Got an FD_WRITE\n");
|
|
|
|
break;
|
|
|
|
case FD_OOB:
|
|
|
|
NSLog(@"Got an FD_OOB\n");
|
|
|
|
break;
|
|
|
|
case FD_ACCEPT:
|
|
|
|
NSLog(@"Got an FD_ACCEPT\n");
|
|
|
|
break;
|
|
|
|
case FD_CONNECT:
|
|
|
|
NSLog(@"Got an FD_CONNECT\n");
|
|
|
|
break;
|
|
|
|
case FD_CLOSE:
|
|
|
|
NSLog(@"Got an FD_CLOSE\n");
|
|
|
|
break;
|
|
|
|
default:
|
2003-07-21 12:04:43 +00:00
|
|
|
break;
|
1997-09-13 17:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-11 18:49:32 +00:00
|
|
|
/*
|
|
|
|
This section terminates the list of imports under GCC. If you do not
|
|
|
|
include this then you will have problems when linking with DLLs.
|
|
|
|
*/
|
|
|
|
asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");
|