wininet/tests: Don't call GetLastError() twice.
[wine] / dlls / dpwsockx / dpwsockx_main.c
1 /* Internet TCP/IP and IPX Connection For DirectPlay
2  *
3  * Copyright 2008 Ismael Barros Barros
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winsock2.h"
27 #include "dpwsockx_dll.h"
28 #include "wine/debug.h"
29 #include "dplay.h"
30 #include "wine/dplaysp.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(dplay);
33
34
35 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
36 {
37     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
38
39     switch (fdwReason)
40     {
41     case DLL_WINE_PREATTACH:
42         return FALSE;    /* prefer native version */
43     case DLL_PROCESS_ATTACH:
44         /* TODO: Initialization */
45         DisableThreadLibraryCalls(hinstDLL);
46         break;
47     case DLL_PROCESS_DETACH:
48         break;
49     default:
50         break;
51     }
52
53     return TRUE;
54 }
55
56
57 static HRESULT WINAPI DPWSCB_EnumSessions( LPDPSP_ENUMSESSIONSDATA data )
58 {
59     FIXME( "(%p,%d,%p,%u) stub\n",
60            data->lpMessage, data->dwMessageSize,
61            data->lpISP, data->bReturnStatus );
62     return DPERR_UNSUPPORTED;
63 }
64
65 static HRESULT WINAPI DPWSCB_Reply( LPDPSP_REPLYDATA data )
66 {
67     FIXME( "(%p,%p,%d,%d,%p) stub\n",
68            data->lpSPMessageHeader, data->lpMessage, data->dwMessageSize,
69            data->idNameServer, data->lpISP );
70     return DPERR_UNSUPPORTED;
71 }
72
73 static HRESULT WINAPI DPWSCB_Send( LPDPSP_SENDDATA data )
74 {
75     FIXME( "(0x%08x,%d,%d,%p,%d,%u,%p) stub\n",
76            data->dwFlags, data->idPlayerTo, data->idPlayerFrom,
77            data->lpMessage, data->dwMessageSize,
78            data->bSystemMessage, data->lpISP );
79     return DPERR_UNSUPPORTED;
80 }
81
82 static HRESULT WINAPI DPWSCB_CreatePlayer( LPDPSP_CREATEPLAYERDATA data )
83 {
84     FIXME( "(%d,0x%08x,%p,%p) stub\n",
85            data->idPlayer, data->dwFlags,
86            data->lpSPMessageHeader, data->lpISP );
87     return DPERR_UNSUPPORTED;
88 }
89
90 static HRESULT WINAPI DPWSCB_DeletePlayer( LPDPSP_DELETEPLAYERDATA data )
91 {
92     FIXME( "(%d,0x%08x,%p) stub\n",
93            data->idPlayer, data->dwFlags, data->lpISP );
94     return DPERR_UNSUPPORTED;
95 }
96
97 static HRESULT WINAPI DPWSCB_GetAddress( LPDPSP_GETADDRESSDATA data )
98 {
99     FIXME( "(%d,0x%08x,%p,%p,%p) stub\n",
100            data->idPlayer, data->dwFlags, data->lpAddress,
101            data->lpdwAddressSize, data->lpISP );
102     return DPERR_UNSUPPORTED;
103 }
104
105 static HRESULT WINAPI DPWSCB_GetCaps( LPDPSP_GETCAPSDATA data )
106 {
107     FIXME( "(%d,%p,0x%08x,%p)\n",
108            data->idPlayer, data->lpCaps, data->dwFlags, data->lpISP );
109     return DPERR_UNSUPPORTED;
110 }
111
112 static HRESULT WINAPI DPWSCB_Open( LPDPSP_OPENDATA data )
113 {
114     FIXME( "(%u,%p,%p,%u,0x%08x,0x%08x) stub\n",
115            data->bCreate, data->lpSPMessageHeader, data->lpISP,
116            data->bReturnStatus, data->dwOpenFlags, data->dwSessionFlags );
117     return DPERR_UNSUPPORTED;
118 }
119
120 static HRESULT WINAPI DPWSCB_CloseEx( LPDPSP_CLOSEDATA data )
121 {
122     FIXME( "(%p) stub\n", data->lpISP );
123     return DPERR_UNSUPPORTED;
124 }
125
126 static HRESULT WINAPI DPWSCB_ShutdownEx( LPDPSP_SHUTDOWNDATA data )
127 {
128     FIXME( "(%p) stub\n", data->lpISP );
129     return DPERR_UNSUPPORTED;
130 }
131
132 static HRESULT WINAPI DPWSCB_GetAddressChoices( LPDPSP_GETADDRESSCHOICESDATA data )
133 {
134     FIXME( "(%p,%p,%p) stub\n",
135            data->lpAddress, data->lpdwAddressSize, data->lpISP );
136     return DPERR_UNSUPPORTED;
137 }
138
139 static HRESULT WINAPI DPWSCB_SendEx( LPDPSP_SENDEXDATA data )
140 {
141     FIXME( "(%p,0x%08x,%d,%d,%p,%d,%d,%d,%d,%p,%p,%u) stub\n",
142            data->lpISP, data->dwFlags, data->idPlayerTo, data->idPlayerFrom,
143            data->lpSendBuffers, data->cBuffers, data->dwMessageSize,
144            data->dwPriority, data->dwTimeout, data->lpDPContext,
145            data->lpdwSPMsgID, data->bSystemMessage );
146     return DPERR_UNSUPPORTED;
147 }
148
149 static HRESULT WINAPI DPWSCB_SendToGroupEx( LPDPSP_SENDTOGROUPEXDATA data )
150 {
151     FIXME( "(%p,0x%08x,%d,%d,%p,%d,%d,%d,%d,%p,%p) stub\n",
152            data->lpISP, data->dwFlags, data->idGroupTo, data->idPlayerFrom,
153            data->lpSendBuffers, data->cBuffers, data->dwMessageSize,
154            data->dwPriority, data->dwTimeout, data->lpDPContext,
155            data->lpdwSPMsgID );
156     return DPERR_UNSUPPORTED;
157 }
158
159 static HRESULT WINAPI DPWSCB_Cancel( LPDPSP_CANCELDATA data )
160 {
161     FIXME( "(%p,0x%08x,%p,%d,0x%08x,0x%08x) stub\n",
162            data->lpISP, data->dwFlags, data->lprglpvSPMsgID, data->cSPMsgID,
163            data->dwMinPriority, data->dwMaxPriority );
164     return DPERR_UNSUPPORTED;
165 }
166
167 static HRESULT WINAPI DPWSCB_GetMessageQueue( LPDPSP_GETMESSAGEQUEUEDATA data )
168 {
169     FIXME( "(%p,0x%08x,%d,%d,%p,%p) stub\n",
170            data->lpISP, data->dwFlags, data->idFrom, data->idTo,
171            data->lpdwNumMsgs, data->lpdwNumBytes );
172     return DPERR_UNSUPPORTED;
173 }
174
175 static void setup_callbacks( LPDPSP_SPCALLBACKS lpCB )
176 {
177     lpCB->EnumSessions           = DPWSCB_EnumSessions;
178     lpCB->Reply                  = DPWSCB_Reply;
179     lpCB->Send                   = DPWSCB_Send;
180     lpCB->CreatePlayer           = DPWSCB_CreatePlayer;
181     lpCB->DeletePlayer           = DPWSCB_DeletePlayer;
182     lpCB->GetAddress             = DPWSCB_GetAddress;
183     lpCB->GetCaps                = DPWSCB_GetCaps;
184     lpCB->Open                   = DPWSCB_Open;
185     lpCB->CloseEx                = DPWSCB_CloseEx;
186     lpCB->ShutdownEx             = DPWSCB_ShutdownEx;
187     lpCB->GetAddressChoices      = DPWSCB_GetAddressChoices;
188     lpCB->SendEx                 = DPWSCB_SendEx;
189     lpCB->SendToGroupEx          = DPWSCB_SendToGroupEx;
190     lpCB->Cancel                 = DPWSCB_Cancel;
191     lpCB->GetMessageQueue        = DPWSCB_GetMessageQueue;
192
193     lpCB->AddPlayerToGroup       = NULL;
194     lpCB->Close                  = NULL;
195     lpCB->CreateGroup            = NULL;
196     lpCB->DeleteGroup            = NULL;
197     lpCB->RemovePlayerFromGroup  = NULL;
198     lpCB->SendToGroup            = NULL;
199     lpCB->Shutdown               = NULL;
200 }
201
202
203
204 /******************************************************************
205  *              SPInit (DPWSOCKX.1)
206  */
207 HRESULT WINAPI SPInit( LPSPINITDATA lpspData )
208 {
209     WSADATA wsaData;
210     DPWS_DATA dpwsData;
211
212     TRACE( "Initializing library for %s (%s)\n",
213            wine_dbgstr_guid(lpspData->lpGuid), debugstr_w(lpspData->lpszName) );
214
215     /* We only support TCP/IP service */
216     if ( !IsEqualGUID(lpspData->lpGuid, &DPSPGUID_TCPIP) )
217     {
218         return DPERR_UNAVAILABLE;
219     }
220
221     /* Assign callback functions */
222     setup_callbacks( lpspData->lpCB );
223
224     /* Load Winsock 2.0 DLL */
225     if ( WSAStartup( MAKEWORD(2, 0), &wsaData ) != 0 )
226     {
227         ERR( "WSAStartup() failed\n" );
228         return DPERR_UNAVAILABLE;
229     }
230
231     /* Initialize internal data */
232     memset( &dpwsData, 0, sizeof(DPWS_DATA) );
233     dpwsData.lpISP = lpspData->lpISP;
234     IDirectPlaySP_SetSPData( lpspData->lpISP, &dpwsData, sizeof(DPWS_DATA),
235                              DPSET_LOCAL );
236
237     /* dplay needs to know the size of the header */
238     lpspData->dwSPHeaderSize = sizeof(DPSP_MSG_HEADER);
239
240     return DP_OK;
241 }