source: docker/msys/pywin32.patch@ 945:90f458a3bc2d

python3
Last change on this file since 945:90f458a3bc2d was 920:42b14124051b, checked in by István Váradi <ivaradi@…>, 6 years ago

Win 10 Docker image for building the new Python3-based distribution

File size: 98.6 KB
RevLine 
[920]1diff --git a/com/win32com/src/ErrorUtils.cpp b/com/win32com/src/ErrorUtils.cpp
2index 1186cd1..314aff8 100644
3--- a/com/win32com/src/ErrorUtils.cpp
4+++ b/com/win32com/src/ErrorUtils.cpp
5@@ -1118,9 +1118,15 @@ LPCTSTR GetScodeRangeString(HRESULT hr)
6 HRESULT hrLast;
7 LPCTSTR lpszName;
8 };
9+#if defined(__MINGW32__)
10+ #define MAKE_RANGE_ENTRY(hrRange) \
11+ { static_cast<HRESULT>(hrRange##_FIRST), static_cast<HRESULT>(hrRange##_LAST), \
12+ _T(#hrRange) _T("_FIRST...") _T(#hrRange) _T("_LAST") }
13+#else
14 #define MAKE_RANGE_ENTRY(hrRange) \
15 { hrRange##_FIRST, hrRange##_LAST, \
16 _T(#hrRange) _T("_FIRST...") _T(#hrRange) _T("_LAST") }
17+#endif
18
19 static const RANGE_ENTRY hrRangeTable[] =
20 {
21diff --git a/com/win32com/src/PyGatewayBase.cpp b/com/win32com/src/PyGatewayBase.cpp
22index fc091cb..2ed9acc 100644
23--- a/com/win32com/src/PyGatewayBase.cpp
24+++ b/com/win32com/src/PyGatewayBase.cpp
25@@ -7,6 +7,10 @@
26
27 #include "PythonCOMServer.h"
28
29+#if defined(__MINGW32__)
30+#include <algorithm>
31+#endif
32+
33 // {25D29CD0-9B98-11d0-AE79-4CF1CF000000}
34 extern const GUID IID_IInternalUnwrapPythonObject =
35 { 0x25d29cd0, 0x9b98, 0x11d0, { 0xae, 0x79, 0x4c, 0xf1, 0xcf, 0x0, 0x0, 0x0 } };
36@@ -437,7 +441,11 @@ static HRESULT invoke_setup(
37 // make sure its not a special DISPID we don't understand.
38 if (params->rgdispidNamedArgs[i] < 0)
39 return DISP_E_PARAMNOTFOUND;
40+#if defined(__MINGW32__)
41+ numArgs = std::max(numArgs, (UINT)params->rgdispidNamedArgs[i]+1);
42+#else
43 numArgs = max(numArgs, (UINT)params->rgdispidNamedArgs[i]+1);
44+#endif
45 }
46
47 PyObject *argList = PyTuple_New(numArgs);
48@@ -658,7 +666,11 @@ static HRESULT invoke_finish(
49 ob = NULL;
50 firstByRef = 1;
51 }
52+#if defined(__MINGW32__)
53+ UINT max_args = std::min(cUserResult-firstByRef, pDispParams->cArgs);
54+#else
55 UINT max_args = min(cUserResult-firstByRef, pDispParams->cArgs);
56+#endif
57 UINT *offsets = (UINT *)_malloca(sizeof(UINT) * max_args);
58 // Get the offsets into our params of all BYREF args, in order.
59 fill_byref_offsets(pDispParams, offsets, max_args);
60diff --git a/com/win32com/src/PythonCOM.cpp b/com/win32com/src/PythonCOM.cpp
61index da00839..67983a4 100644
62--- a/com/win32com/src/PythonCOM.cpp
63+++ b/com/win32com/src/PythonCOM.cpp
64@@ -342,11 +342,13 @@ static PyObject *pythoncom_CoInitializeSecurity(PyObject *self, PyObject *args)
65 pSD = (PSECURITY_DESCRIPTOR)&appid;
66 }
67 }
68+#if !defined(__MINGW32__)
69 else if (dwCapabilities & EOAC_ACCESS_CONTROL){
70 if (!PyCom_InterfaceFromPyObject(obSD, IID_IAccessControl, (void **)&pIAC, FALSE))
71 return NULL;
72 pSD = (PSECURITY_DESCRIPTOR)pIAC;
73 }
74+#endif
75 else{
76 if (!PyWinObject_AsSECURITY_DESCRIPTOR(obSD, &pSD, /*BOOL bNoneOK = */TRUE))
77 return NULL;
78diff --git a/com/win32com/src/PythonCOM.def b/com/win32com/src/PythonCOM.def
79index 58d030f..6d2a54b 100644
80--- a/com/win32com/src/PythonCOM.def
81+++ b/com/win32com/src/PythonCOM.def
82@@ -1,15 +1,15 @@
83 EXPORTS
84- DllCanUnloadNow @1 PRIVATE
85- DllGetClassObject @2 PRIVATE
86+ DllCanUnloadNow
87+ DllGetClassObject
88
89 ; Some exports for clients who may "LoadLibrary"...
90- PyCom_VariantFromPyObject
91- PyCom_PyObjectFromVariant
92- PyCom_InterfaceFromPyObject
93- PyCom_PyObjectFromIUnknown
94- PyCom_MakeOlePythonCall
95+ _PyCom_VariantFromPyObject
96+ _PyCom_PyObjectFromVariant
97+ _PyCom_InterfaceFromPyObject
98+ _PyCom_PyObjectFromIUnknown
99+ _PyCom_MakeOlePythonCall
100
101- PyCom_CoInitializeEx
102- PyCom_CoInitialize
103- PyCom_CoUninitialize
104+ _PyCom_CoInitializeEx
105+ _PyCom_CoInitialize
106+ _PyCom_CoUninitialize
107
108diff --git a/com/win32com/src/Register.cpp b/com/win32com/src/Register.cpp
109index 0b24ee2..d259aff 100644
110--- a/com/win32com/src/Register.cpp
111+++ b/com/win32com/src/Register.cpp
112@@ -322,7 +322,9 @@ static const PyCom_InterfaceSupportInfo g_interfaceSupportData[] =
113 PYCOM_INTERFACE_FULL ( CancelMethodCalls),
114 // No wrapper for IAccessControl yet, but you can still get the system implementation
115 // by calling pythoncom.CoCreateInstance with IID_IUnknown as the returned interface
116+#if !defined(__MINGW32__)
117 PYCOM_INTERFACE_CLSID_ONLY (DCOMAccessControl),
118+#endif
119
120 // NULL, Unknown and dispatch special cases.
121 { &IID_NULL, "Null", "IID_NULL", NULL, NULL},
122diff --git a/com/win32com/src/dllmain.cpp b/com/win32com/src/dllmain.cpp
123index fb81ddb..abf074c 100644
124--- a/com/win32com/src/dllmain.cpp
125+++ b/com/win32com/src/dllmain.cpp
126@@ -175,6 +175,9 @@ typedef HRESULT (WINAPI *PFNCoInitializeEx)(LPVOID pvReserved, DWORD dwCoInit);
127 // the Init for Term function explicitely, and the framework will detect
128 // it no longer needs doing.
129 // XXX - Needs more thought about threading implications.
130+#if defined(__MINGW32__)
131+extern "C"
132+#endif
133 HRESULT PyCom_CoInitializeEx(LPVOID reserved, DWORD dwInit)
134 {
135 // Must be thread-safe, although doesnt need the Python lock.
136diff --git a/com/win32com/src/include/PythonCOM.h b/com/win32com/src/include/PythonCOM.h
137index 9e422e4..f3b1063 100644
138--- a/com/win32com/src/include/PythonCOM.h
139+++ b/com/win32com/src/include/PythonCOM.h
140@@ -111,10 +111,8 @@
141 #ifdef __MINGW32__
142 // Special Mingw32 considerations.
143 #define NO_PYCOM_IDISPATCHEX
144-#define NO_PYCOM_IPROVIDECLASSINFO
145 #define NO_PYCOM_ISERVICEPROVIDER
146 #define NO_PYCOM_ENUMSTATPROPSTG
147-#define NO_PYCOM_IPROPERTYSTORAGE
148 #define __try try
149 #define __except catch
150 #include <olectl.h>
151@@ -305,6 +303,9 @@ PYCOM_EXPORT PyObject *PyObject_FromOLEMENUGROUPWIDTHS(const OLEMENUGROUPWIDTHS
152
153 /* Functions for Initializing COM, and also letting the core know about it!
154 */
155+#if defined(__MINGW32__)
156+extern "C"
157+#endif
158 PYCOM_EXPORT HRESULT PyCom_CoInitializeEx(LPVOID reserved, DWORD dwInit);
159 PYCOM_EXPORT HRESULT PyCom_CoInitialize(LPVOID reserved);
160 PYCOM_EXPORT void PyCom_CoUninitialize();
161diff --git a/com/win32com/src/initguid.cpp b/com/win32com/src/initguid.cpp
162new file mode 100644
163index 0000000..33d5923
164--- /dev/null
165+++ b/com/win32com/src/initguid.cpp
166@@ -0,0 +1,7 @@
167+#define INITGUID
168+#undef _OBJIDLBASE_
169+#define CINTERFACE
170+#define USE_COM_CONTEXT_DEF
171+#include <objidl.h>
172+#include <ksguid.h>
173+#include <ks.h>
174diff --git a/com/win32comext/axcontrol/src/PyIOleCommandTarget.cpp b/com/win32comext/axcontrol/src/PyIOleCommandTarget.cpp
175index 61bd706..e7908e9 100644
176--- a/com/win32comext/axcontrol/src/PyIOleCommandTarget.cpp
177+++ b/com/win32comext/axcontrol/src/PyIOleCommandTarget.cpp
178@@ -4,6 +4,10 @@
179 #include "axcontrol_pch.h"
180 #include "PyIOleCommandTarget.h"
181
182+#if defined(__MINGW32__)
183+#include <algorithm>
184+#endif
185+
186 static BOOL FillOLECMDsWithSequence(OLECMD *pCmds, UINT ncmds, PyObject *obCmds)
187 {
188 for (UINT i=0;i<ncmds;i++) {
189@@ -211,7 +215,11 @@ STDMETHODIMP PyGOleCommandTarget::QueryStatus(
190 ok = PyWinObject_AsAutoFreeBstr(obText, &tempString);
191 if (ok) {
192 UINT strLen = SysStringLen(tempString);
193+#if defined(__MINGW32__)
194+ UINT nwrite = std::min((ULONG)strLen, pCmdText->cwBuf);
195+#else
196 UINT nwrite = min(strLen, pCmdText->cwBuf);
197+#endif
198 wcsncpy(pCmdText->rgwz, (WCHAR *)(BSTR)tempString,
199 nwrite);
200 pCmdText->cwActual = nwrite;
201diff --git a/com/win32comext/axcontrol/src/initguid.cpp b/com/win32comext/axcontrol/src/initguid.cpp
202new file mode 100644
203index 0000000..329e211
204--- /dev/null
205+++ b/com/win32comext/axcontrol/src/initguid.cpp
206@@ -0,0 +1,8 @@
207+#define INITGUID
208+#undef _OBJIDLBASE_
209+#define CINTERFACE
210+#define USE_COM_CONTEXT_DEF
211+#include <objidl.h>
212+#include <ksguid.h>
213+#include <ks.h>
214+#include <docobj.h>
215diff --git a/com/win32comext/axscript/src/initguid.cpp b/com/win32comext/axscript/src/initguid.cpp
216new file mode 100644
217index 0000000..ba6baa3
218--- /dev/null
219+++ b/com/win32comext/axscript/src/initguid.cpp
220@@ -0,0 +1,8 @@
221+#define INITGUID
222+#undef _OBJIDLBASE_
223+#define CINTERFACE
224+#define USE_COM_CONTEXT_DEF
225+#include <objidl.h>
226+#include <ksguid.h>
227+#include <ks.h>
228+#include <objsafe.h>
229diff --git a/com/win32comext/internet/src/PyIInternetProtocol.cpp b/com/win32comext/internet/src/PyIInternetProtocol.cpp
230index 43c25a8..b910c85 100644
231--- a/com/win32comext/internet/src/PyIInternetProtocol.cpp
232+++ b/com/win32comext/internet/src/PyIInternetProtocol.cpp
233@@ -5,6 +5,10 @@
234 #include "PyIInternetProtocolRoot.h"
235 #include "PyIInternetProtocol.h"
236
237+#if defined(__MINGW32__)
238+#include <algorithm>
239+#endif
240+
241 // @doc - This file contains autoduck documentation
242 // ---------------------------------------------------
243 //
244@@ -181,7 +185,11 @@ STDMETHODIMP PyGInternetProtocol::Read(
245 hr = PyCom_HandlePythonFailureToCOM();
246 } else {
247 char *buf = PyString_AsString(result);
248+#if defined(__MINGW32__)
249+ *pcbRead = std::min(cb, (ULONG)PyString_Size(result));
250+#else
251 *pcbRead = min(cb, (ULONG)PyString_Size(result));
252+#endif
253 memcpy( pv, buf, *pcbRead);
254 }
255 return hr;
256diff --git a/com/win32comext/internet/src/PyIInternetProtocolInfo.cpp b/com/win32comext/internet/src/PyIInternetProtocolInfo.cpp
257index c00e43e..ef894ca 100644
258--- a/com/win32comext/internet/src/PyIInternetProtocolInfo.cpp
259+++ b/com/win32comext/internet/src/PyIInternetProtocolInfo.cpp
260@@ -4,6 +4,10 @@
261 #include "internet_pch.h"
262 #include "PyIInternetProtocolInfo.h"
263
264+#if defined(__MINGW32__)
265+#include <algorithm>
266+#endif
267+
268 // @doc - This file contains autoduck documentation
269 // ---------------------------------------------------
270 //
271@@ -226,7 +230,11 @@ STDMETHODIMP PyGInternetProtocolInfo::ParseUrl(
272 if (!PyWinObject_AsBstr(result, &bstrTemp, FALSE, pcchResult)) bPythonIsHappy = FALSE;
273 if (!bPythonIsHappy) return PyCom_HandlePythonFailureToCOM(/*pexcepinfo*/);
274 ++(*pcchResult); // Null terminator
275+#if defined(__MINGW32__)
276+ *pcchResult = std::min(*pcchResult, cchResult);
277+#else
278 *pcchResult = min(*pcchResult, cchResult);
279+#endif
280 memcpy(pwzResult, bstrTemp, *pcchResult * sizeof(WCHAR));
281 SysFreeString(bstrTemp);
282 Py_DECREF(result);
283@@ -258,7 +266,11 @@ STDMETHODIMP PyGInternetProtocolInfo::CombineUrl(
284 if (!PyWinObject_AsBstr(result, &bstrTemp, FALSE, pcchResult)) bPythonIsHappy = FALSE;
285 if (!bPythonIsHappy) hr = PyCom_HandlePythonFailureToCOM(/*pexcepinfo*/);
286 ++(*pcchResult); // Null terminator
287+#if defined(__MINGW32__)
288+ *pcchResult = std::min(*pcchResult, cchResult);
289+#else
290 *pcchResult = min(*pcchResult, cchResult);
291+#endif
292 memcpy(pwzResult, bstrTemp, *pcchResult * sizeof(WCHAR));
293 SysFreeString(bstrTemp);
294 Py_DECREF(result);
295@@ -312,7 +324,11 @@ STDMETHODIMP PyGInternetProtocolInfo::QueryInfo(
296 return PyCom_HandlePythonFailureToCOM();
297 }
298 } else {
299+#if defined(__MINGW32__)
300+ *pcbBuf = std::min(cbBuffer, (ULONG)PyString_Size(result));
301+#else
302 *pcbBuf = min(cbBuffer, (ULONG)PyString_Size(result));
303+#endif
304 memcpy(pBuffer, PyString_AsString(result), *pcbBuf);
305 }
306 Py_DECREF(result);
307diff --git a/com/win32comext/internet/src/PyIInternetSecurityManager.cpp b/com/win32comext/internet/src/PyIInternetSecurityManager.cpp
308index 81439fc..a4cb106 100644
309--- a/com/win32comext/internet/src/PyIInternetSecurityManager.cpp
310+++ b/com/win32comext/internet/src/PyIInternetSecurityManager.cpp
311@@ -4,6 +4,10 @@
312 #include "internet_pch.h"
313 #include "PyIInternetSecurityManager.h"
314
315+#if defined(__MINGW32__)
316+#include <algorithm>
317+#endif
318+
319 // @doc - This file contains autoduck documentation
320 // ---------------------------------------------------
321 //
322@@ -338,7 +342,11 @@ STDMETHODIMP PyGInternetSecurityManager::GetSecurityId(
323 Py_DECREF(result);
324 return MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetSecurityId");
325 }
326+#if defined(__MINGW32__)
327+ *pcbSecurityId = std::min(buf_len, *pcbSecurityId);
328+#else
329 *pcbSecurityId = min(buf_len, *pcbSecurityId);
330+#endif
331 memcpy(pbSecurityId, buf, *pcbSecurityId);
332 Py_DECREF(result);
333 return hr;
334diff --git a/com/win32comext/internet/src/initguid.cpp b/com/win32comext/internet/src/initguid.cpp
335new file mode 100644
336index 0000000..1003585
337--- /dev/null
338+++ b/com/win32comext/internet/src/initguid.cpp
339@@ -0,0 +1,9 @@
340+#define INITGUID
341+#undef _OBJIDLBASE_
342+#define CINTERFACE
343+#define USE_COM_CONTEXT_DEF
344+#include <objidl.h>
345+#include <ksguid.h>
346+#include <ks.h>
347+#include <urlmon.h>
348+#include <mshtmhst.h>
349diff --git a/com/win32comext/propsys/src/PyPROPVARIANT.cpp b/com/win32comext/propsys/src/PyPROPVARIANT.cpp
350index b330129..694703f 100644
351--- a/com/win32comext/propsys/src/PyPROPVARIANT.cpp
352+++ b/com/win32comext/propsys/src/PyPROPVARIANT.cpp
353@@ -3,7 +3,13 @@
354
355 #include "PythonCOM.h"
356 #include "PyPROPVARIANT.h"
357+#if defined(__MINGW32__)
358+extern "C" {
359+#endif
360 #include "propvarutil.h"
361+#if defined(__MINGW32__)
362+}
363+#endif
364 #include "float.h"
365
366 // @doc - This file contains autoduck documentation
367diff --git a/com/win32comext/propsys/src/propsys.cpp b/com/win32comext/propsys/src/propsys.cpp
368index ef0a2f4..69ff21f 100644
369--- a/com/win32comext/propsys/src/propsys.cpp
370+++ b/com/win32comext/propsys/src/propsys.cpp
371@@ -279,6 +279,7 @@ static PyObject *PyPSGetItemPropertyHandler(PyObject *self, PyObject *args)
372 return PyCom_PyObjectFromIUnknown((IUnknown *)propertystore, riid, FALSE);
373 }
374
375+#if !defined(__MINGW32__)
376 // @pymethod bytes|propsys|StgSerializePropVariant|Serializes a <o PyPROPVARIANT>
377 static PyObject *PyStgSerializePropVariant(PyObject *self, PyObject *args)
378 {
379@@ -319,6 +320,7 @@ static PyObject *PyStgDeserializePropVariant(PyObject *self, PyObject *args)
380 return PyCom_BuildPyException(hr);
381 return PyWinObject_FromPROPVARIANT(&pv);
382 };
383+#endif
384
385 // @pymethod <o PyIPropertyStore>|propsys|PSCreateMemoryPropertyStore|Creates a temporary property store that is not connected to any backing storage
386 // @comm May also be used to create <o PyINamedPropertyStore>, <o PyIPropertyStoreCache>, <o PyIPersistStream>, or <o PyIPropertyBag>
387@@ -566,8 +568,10 @@ static struct PyMethodDef propsys_methods[]=
388 { "PSRegisterPropertySchema", PyPSRegisterPropertySchema, 1 }, // @pymeth PSRegisterPropertySchema|Registers a group of properties described in a schema file
389 { "PSUnregisterPropertySchema", PyPSUnregisterPropertySchema, 1 }, // @pymeth PSUnregisterPropertySchema|Removes a property schema definition
390 { "SHGetPropertyStoreFromParsingName", PySHGetPropertyStoreFromParsingName, 1 }, // @pymeth SHGetPropertyStoreFromParsingName|Retrieves the property store for an item by path
391+#if !defined(__MINGW32__)
392 { "StgSerializePropVariant", PyStgSerializePropVariant, 1 }, // @pymeth StgSerializePropVariant|Serializes a <o PyPROPVARIANT>
393 { "StgDeserializePropVariant", PyStgDeserializePropVariant, 1 }, // @pymeth StgDeserializePropVariant|Creates a <o PyPROPVARIANT> from a serialized buffer
394+#endif
395 { "PSCreateMemoryPropertyStore", PyPSCreateMemoryPropertyStore, 1 }, // @pymeth PSCreateMemoryPropertyStore|Creates a temporary property store that is not connected to any backing storage
396 { "PSCreatePropertyStoreFromPropertySetStorage", PyPSCreatePropertyStoreFromPropertySetStorage, 1 }, // @pymeth PSCreatePropertyStoreFromPropertySetStorage|Wraps a <o PyIPropertySetStorage> interface in a <o PyIPropertyStore> object
397 { "PSLookupPropertyHandlerCLSID", PyPSLookupPropertyHandlerCLSID, 1 }, // @pymeth PSLookupPropertyHandlerCLSID|Returns the GUID of the property handler for a file
398@@ -583,7 +587,7 @@ static struct PyMethodDef propsys_methods[]=
399 // MSDN says CLSID_PropertyChangeArray can be used to create IPropertyChangeArray, but
400 // I get "Class not registered". Plus, it doesn't appear in any headers, although
401 // it's contained in uuid.lib.
402-#ifndef CLSID_PropertyChangeArray
403+#if !defined(CLSID_PropertyChangeArray) && !defined(__MINGW32__)
404 EXTERN_C const CLSID CLSID_PropertyChangeArray;
405 #endif
406
407@@ -606,7 +610,9 @@ static const PyCom_InterfaceSupportInfo g_interfaceSupportData[] =
408 PYCOM_INTERFACE_CLIENT_ONLY (ObjectWithPropertyKey),
409 PYCOM_INTERFACE_CLIENT_ONLY (PropertyChange),
410 PYCOM_INTERFACE_CLIENT_ONLY (PropertyChangeArray),
411+#if !defined(__MINGW32__)
412 PYCOM_INTERFACE_CLSID_ONLY (PropertyChangeArray),
413+#endif
414 };
415
416 /* Module initialisation */
417diff --git a/com/win32comext/shell/src/PyICategoryProvider.cpp b/com/win32comext/shell/src/PyICategoryProvider.cpp
418index e2f2ea8..0ecf0cf 100644
419--- a/com/win32comext/shell/src/PyICategoryProvider.cpp
420+++ b/com/win32comext/shell/src/PyICategoryProvider.cpp
421@@ -9,6 +9,10 @@
422 //
423 // Interface Implementation
424
425+#if defined(__MINGW32__)
426+__CRT_UUID_DECL(int, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
427+#endif
428+
429 PyICategoryProvider::PyICategoryProvider(IUnknown *pdisp):
430 PyIUnknown(pdisp)
431 {
432diff --git a/com/win32comext/shell/src/initguid.cpp b/com/win32comext/shell/src/initguid.cpp
433new file mode 100644
434index 0000000..8da5c87
435--- /dev/null
436+++ b/com/win32comext/shell/src/initguid.cpp
437@@ -0,0 +1,11 @@
438+#define INITGUID
439+#undef _OBJIDLBASE_
440+#define CINTERFACE
441+#define USE_COM_CONTEXT_DEF
442+#include <objidl.h>
443+#include <ksguid.h>
444+#include <ks.h>
445+#include <shlguid.h>
446+#include <shobjidl.h>
447+#include <emptyvc.h>
448+#include <_mingw.h>
449diff --git a/com/win32comext/shell/src/shell.cpp b/com/win32comext/shell/src/shell.cpp
450index 8b6e78c..f19a021 100644
451--- a/com/win32comext/shell/src/shell.cpp
452+++ b/com/win32comext/shell/src/shell.cpp
453@@ -29,8 +29,10 @@ generates Windows .hlp files.
454 #include "PyIShellExtInit.h"
455 #include "PyIShellFolder.h"
456 #include "PyIShellFolder2.h"
457+#if !defined(__MINGW32__)
458 #include "PyIEmptyVolumeCache.h"
459 #include "PyIEmptyVolumeCacheCallBack.h"
460+#endif
461 #include "PyIEnumExplorerCommand.h"
462 #include "PyIEnumIDList.h"
463 #include "PyICopyHook.h"
464@@ -3606,12 +3608,16 @@ static const PyCom_InterfaceSupportInfo g_interfaceSupportData[] =
465 PYCOM_INTERFACE_FULL(ColumnProvider),
466 PYCOM_INTERFACE_CLIENT_ONLY(DefaultExtractIconInit),
467 PYCOM_INTERFACE_FULL(DropTargetHelper),
468+#if !defined(__MINGW32__)
469 PYCOM_INTERFACE_CLIENT_ONLY(EmptyVolumeCacheCallBack),
470+#endif
471 PYCOM_INTERFACE_CLIENT_ONLY(QueryAssociations),
472 PYCOM_INTERFACE_SERVER_ONLY(DeskBand),
473 PYCOM_INTERFACE_SERVER_ONLY(DockingWindow),
474+#if !defined(__MINGW32__)
475 PYCOM_INTERFACE_SERVER_ONLY(EmptyVolumeCache),
476 PYCOM_INTERFACE_SERVER_ONLY(EmptyVolumeCache2),
477+#endif
478 PYCOM_INTERFACE_CLIENT_ONLY(ExplorerBrowser),
479 PYCOM_INTERFACE_FULL(ExplorerBrowserEvents),
480 PYCOM_INTERFACE_FULL(ExplorerCommand),
481@@ -3850,12 +3856,16 @@ PYWIN_MODULE_INIT_FUNC(shell)
482 ADD_IID(FMTID_Briefcase);
483 ADD_IID(FMTID_Misc);
484 ADD_IID(FMTID_WebView);
485+#if !defined(__MINGW32__)
486 ADD_IID(FMTID_AudioSummaryInformation);
487+#endif
488 ADD_IID(FMTID_Volume);
489 ADD_IID(FMTID_Query);
490+#if !defined(__MINGW32__)
491 ADD_IID(FMTID_SummaryInformation);
492 ADD_IID(FMTID_MediaFileSummaryInformation);
493 ADD_IID(FMTID_ImageSummaryInformation);
494+#endif
495 ADD_IID(IID_CDefView);
496
497 ADD_IID(EP_NavPane);
498diff --git a/com/win32comext/taskscheduler/src/initguid.cpp b/com/win32comext/taskscheduler/src/initguid.cpp
499new file mode 100644
500index 0000000..d588502
501--- /dev/null
502+++ b/com/win32comext/taskscheduler/src/initguid.cpp
503@@ -0,0 +1,8 @@
504+#define INITGUID
505+#undef _OBJIDLBASE_
506+#define CINTERFACE
507+#define USE_COM_CONTEXT_DEF
508+#include <objidl.h>
509+#include <ksguid.h>
510+#include <ks.h>
511+#include <mstask.h>
512diff --git a/isapi/src/Utils.cpp b/isapi/src/Utils.cpp
513index 8f278f2..b8976ae 100644
514--- a/isapi/src/Utils.cpp
515+++ b/isapi/src/Utils.cpp
516@@ -127,7 +127,11 @@ static void CheckRegisterEventSourceFile()
517 return;
518
519 GetModuleFileNameW(g_hInstance, mod_name,
520+#if defined(__MINGW32__)
521+ sizeof(mod_name)/sizeof(WCHAR));
522+#else
523 sizeof mod_name/sizeof WCHAR);
524+#endif
525 if (!mod_name[0]) {
526 OutputDebugString(_T("GetModuleFileNameW failed!"));
527 return;
528@@ -160,6 +164,9 @@ static void CheckRegisterEventSourceFile()
529 }
530
531 // Write stuff to the event log.
532+#if defined(__MINGW32__)
533+extern "C"
534+#endif
535 BOOL WriteEventLogMessage(WORD eventType, DWORD eventID, WORD num_inserts,
536 const char **inserts)
537 {
538diff --git a/isapi/src/Utils.h b/isapi/src/Utils.h
539index 3779ca9..f076826 100644
540--- a/isapi/src/Utils.h
541+++ b/isapi/src/Utils.h
542@@ -58,6 +58,9 @@ char *HTMLErrorResp(const char *msg);
543 TCHAR *GetModulePath(void);
544
545 // Write entry to the event log
546+#if defined(__MINGW32__)
547+extern "C"
548+#endif
549 BOOL WriteEventLogMessage(WORD eventType, DWORD eventID, WORD num_inserts,
550 const char **inserts);
551
552diff --git a/isapi/src/pyISAPI.cpp b/isapi/src/pyISAPI.cpp
553index 439d3ca..2c94610 100644
554--- a/isapi/src/pyISAPI.cpp
555+++ b/isapi/src/pyISAPI.cpp
556@@ -52,6 +52,9 @@ char g_CallbackModuleName[_MAX_PATH + _MAX_FNAME] = "";
557 #define TRACE(x) OutputDebugString(_T(x))
558
559 // This is an entry point for py2exe.
560+#if defined(__MINGW32__)
561+extern "C"
562+#endif
563 void WINAPI PyISAPISetOptions(const char *modname, BOOL is_frozen)
564 {
565 strncpy(g_CallbackModuleName, modname,
566diff --git a/setup.py b/setup.py
567index 7c35d90..5872968 100644
568--- a/setup.py
569+++ b/setup.py
570@@ -72,6 +72,8 @@ import shutil
571
572 is_py3k = sys.version_info > (3,) # get this out of the way early on...
573
574+build_mingw32=True
575+
576 try:
577 import winreg # py3k
578 except ImportError:
579@@ -140,6 +142,10 @@ dll_base_address = 0x1e200000
580 def find_platform_sdk_dir():
581 # The user might have their current environment setup for the
582 # SDK, in which case "MSSDK_INCLUDE" and "MSSDK_LIB" vars must be set.
583+ if build_mingw32:
584+ return { "include": ["c:/msys64/mingw32/include", "c:/msys64/mingw32/i686-w64-mingw32/include"],
585+ "lib": ["c:/msys64/mingw32/lib", "c:/msys64//mingw32/i686-w64-mingw32/lib"] }
586+
587 if "MSSDK_INCLUDE" in os.environ and "MSSDK_LIB" in os.environ:
588 print("Using SDK as specified in the environment")
589 return {
590@@ -173,9 +179,10 @@ def find_platform_sdk_dir():
591 # to prevent the extension from loading. For more details, see
592 # http://bugs.python.org/issue7833 (which has landed for Python 2.7 and on 3.2
593 # and later, which are all we care about currently)
594-from distutils.msvc9compiler import MSVCCompiler
595-MSVCCompiler._orig_spawn = MSVCCompiler.spawn
596-MSVCCompiler._orig_link = MSVCCompiler.link
597+if not build_mingw32:
598+ from distutils.msvc9compiler import MSVCCompiler
599+ MSVCCompiler._orig_spawn = MSVCCompiler.spawn
600+ MSVCCompiler._orig_link = MSVCCompiler.link
601
602 # We need to override this method for versions where issue7833 *has* landed
603 # (ie, 2.7 and 3.2+)
604@@ -195,7 +202,8 @@ def manifest_get_embed_info(self, target_desc, ld_args):
605
606 # always monkeypatch it in even though it will only be called in 2.7
607 # and 3.2+.
608-MSVCCompiler.manifest_get_embed_info = manifest_get_embed_info
609+if not build_mingw32:
610+ MSVCCompiler.manifest_get_embed_info = manifest_get_embed_info
611
612 def monkeypatched_spawn(self, cmd):
613 is_link = cmd[0].endswith("link.exe") or cmd[0].endswith('"link.exe"')
614@@ -239,8 +247,9 @@ def monkeypatched_link(self, target_desc, objects, output_filename, *args, **kw)
615 return self._orig_link(target_desc, objects, output_filename, *args, **kw)
616 finally:
617 delattr(self, '_want_assembly_kept')
618-MSVCCompiler.spawn = monkeypatched_spawn
619-MSVCCompiler.link = monkeypatched_link
620+if not build_mingw32:
621+ MSVCCompiler.spawn = monkeypatched_spawn
622+ MSVCCompiler.link = monkeypatched_link
623
624
625 sdk_info = find_platform_sdk_dir()
626@@ -449,6 +458,18 @@ class WinExt (Extension):
627 # Unicode, Windows executables seem to need this magic:
628 if "/SUBSYSTEM:WINDOWS" in self.extra_link_args:
629 self.extra_link_args.append("/ENTRY:wWinMainCRTStartup")
630+ else:
631+ self.extra_compile_args.append("-fpermissive")
632+ unicode_mode = self.unicode_mode
633+ if unicode_mode is None:
634+ unicode_mode = is_py3k
635+ if unicode_mode:
636+ self.extra_compile_args.append("-DUNICODE")
637+ self.extra_compile_args.append("-D_UNICODE")
638+ self.extra_compile_args.append("-DWINNT")
639+ # Unicode, Windows executables seem to need this magic:
640+ #if "/SUBSYSTEM:WINDOWS" in self.extra_link_args:
641+ # self.extra_link_args.append("/ENTRY:wWinMainCRTStartup")
642
643 class WinExt_pythonwin(WinExt):
644 def __init__ (self, name, **kw):
645@@ -641,7 +662,7 @@ class my_build_ext(build_ext):
646 # The pywintypes library is created in the build_temp
647 # directory, so we need to add this to library_dirs
648 self.library_dirs.append(self.build_temp)
649- self.mingw32 = (self.compiler == "mingw32")
650+ self.mingw32 = build_mingw32
651 if self.mingw32:
652 self.libraries.append("stdc++")
653
654@@ -698,7 +719,8 @@ class my_build_ext(build_ext):
655 self.compiler.add_include_dir(extra)
656 # and again for lib dirs.
657 for extra in sdk_info["lib"]:
658- extra = os.path.join(extra, 'x64' if is_64bit else 'x86')
659+ if not build_mingw32:
660+ extra = os.path.join(extra, 'x64' if is_64bit else 'x86')
661 assert os.path.isdir(extra), extra
662 assert extra not in self.library_dirs # see above
663 assert os.path.isdir(extra), "%s doesn't exist!" % (extra,)
664@@ -714,7 +736,7 @@ class my_build_ext(build_ext):
665 # includes interfaces for 64-bit builds.
666 if self.plat_name == 'win-amd64' and ext.name == 'exchdapi':
667 return "No 64-bit library for utility functions available."
668- if get_build_version() >=14:
669+ if not build_mingw32 and get_build_version() >=14:
670 if ext.name == 'exchange':
671 ext.libraries.append('legacy_stdio_definitions')
672 elif ext.name == 'exchdapi':
673@@ -758,7 +780,8 @@ class my_build_ext(build_ext):
674
675 # We update the .libraries list with the resolved library name.
676 # This is really only so "_d" works.
677- ext.libraries = patched_libs
678+ if not build_mingw32:
679+ ext.libraries = patched_libs
680 return None # no reason - it can be built!
681
682 def _build_scintilla(self):
683@@ -972,11 +995,16 @@ class my_build_ext(build_ext):
684 if sys.version_info > (2, 7) and sys.version_info < (3, 3):
685 # only stuff built with msvc9 needs this loader.
686 self._build_pycom_loader()
687- self._build_scintilla()
688+ if not build_mingw32:
689+ self._build_scintilla()
690 # Copy cpp lib files needed to create Python COM extensions
691- clib_files = (['win32', 'pywintypes%s.lib'],
692- ['win32com', 'pythoncom%s.lib'],
693- ['win32com', 'axscript%s.lib'])
694+ if build_mingw32:
695+ clib_files = (['win32', 'libpywintypes%s.a'],
696+ ['win32com', 'libpythoncom%s.a'])
697+ else:
698+ clib_files = (['win32', 'pywintypes%s.lib'],
699+ ['win32com', 'pythoncom%s.lib'],
700+ ['win32com', 'axscript%s.lib'])
701 for clib_file in clib_files:
702 target_dir = os.path.join(self.build_lib, clib_file[0], "libs")
703 if not os.path.exists(target_dir):
704@@ -988,6 +1016,8 @@ class my_build_ext(build_ext):
705 self.copy_file(os.path.join(self.build_temp, fname),
706 target_dir
707 )
708+ if build_mingw32:
709+ return
710 # The MFC DLLs.
711 target_dir = os.path.join(self.build_lib, "pythonwin")
712
713@@ -1081,9 +1111,13 @@ class my_build_ext(build_ext):
714 # this, distutils gets confused, as they both try and use the same
715 # .obj.
716 output_dir = os.path.join(self.build_temp, ext.name)
717+ if build_mingw32:
718+ include_dirs = [output_dir, os.path.join(output_dir, "win32", "src")] + ext.include_dirs
719+ else:
720+ include_dirs = ext.include_dirs
721 kw = {'output_dir': output_dir,
722 'macros': macros,
723- 'include_dirs': ext.include_dirs,
724+ 'include_dirs': include_dirs,
725 'debug': self.debug,
726 'extra_postargs': extra_args,
727 'depends': ext.depends,
728@@ -1115,6 +1149,7 @@ class my_build_ext(build_ext):
729 'extra_postargs': extra_args,
730 'debug': self.debug,
731 'build_temp': self.build_temp,
732+ 'extra_preargs': []
733 }
734
735 # Detect target language, if not provided
736@@ -1162,22 +1197,37 @@ class my_build_ext(build_ext):
737 old_build_temp = self.build_temp
738 want_static_crt = sys.version_info > (2,6) and ext.name in static_crt_modules
739 if want_static_crt:
740- self.compiler.compile_options.remove('/MD')
741- self.compiler.compile_options.append('/MT')
742- self.compiler.compile_options_debug.remove('/MDd')
743- self.compiler.compile_options_debug.append('/MTd')
744+ if not build_mingw32:
745+ self.compiler.compile_options.remove('/MD')
746+ self.compiler.compile_options.append('/MT')
747+ self.compiler.compile_options_debug.remove('/MDd')
748+ self.compiler.compile_options_debug.append('/MTd')
749
750 try:
751+ if build_mingw32:
752+ incs = set()
753+ for source in ext.sources:
754+ output_dir = os.path.join(self.build_temp, os.path.dirname(source))
755+ if output_dir not in incs:
756+ ext.include_dirs.append(output_dir)
757+ incs.add(output_dir)
758 build_ext.build_extension(self, ext)
759 # XXX This has to be changed for mingw32
760 # Get the .lib files we need. This is limited to pywintypes,
761 # pythoncom and win32ui - but the first 2 have special names
762- extra = self.debug and "_d.lib" or ".lib"
763+ if build_mingw32:
764+ extra = self.debug and "_d.a" or ".a"
765+ else:
766+ extra = self.debug and "_d.lib" or ".lib"
767 if ext.name in ("pywintypes", "pythoncom"):
768 # The import libraries are created as PyWinTypes23.lib, but
769 # are expected to be pywintypes.lib.
770- name1 = "%s%d%d%s" % (ext.name, sys.version_info[0], sys.version_info[1], extra)
771- name2 = "%s%s" % (ext.name, extra)
772+ if build_mingw32:
773+ name1 = "lib%s%d%d%s" % (ext.name, sys.version_info[0], sys.version_info[1], extra)
774+ name2 = "lib%s%s" % (ext.name, extra)
775+ else:
776+ name1 = "%s%d%d%s" % (ext.name, sys.version_info[0], sys.version_info[1], extra)
777+ name2 = "%s%s" % (ext.name, extra)
778 elif ext.name in ("win32ui",):
779 name1 = name2 = ext.name + extra
780 else:
781@@ -1199,10 +1249,11 @@ class my_build_ext(build_ext):
782 finally:
783 self.build_temp = old_build_temp
784 if want_static_crt:
785- self.compiler.compile_options.remove('/MT')
786- self.compiler.compile_options.append('/MD')
787- self.compiler.compile_options_debug.remove('/MTd')
788- self.compiler.compile_options_debug.append('/MDd')
789+ if not build_mingw32:
790+ self.compiler.compile_options.remove('/MT')
791+ self.compiler.compile_options.append('/MD')
792+ self.compiler.compile_options_debug.remove('/MTd')
793+ self.compiler.compile_options_debug.append('/MDd')
794
795 def get_ext_filename(self, name):
796 # The pywintypes and pythoncom extensions have special names
797@@ -1298,6 +1349,8 @@ class my_build_ext(build_ext):
798 for source in swig_sources:
799 swig_cmd = [swig, "-python", "-c++"]
800 swig_cmd.append("-dnone",) # we never use the .doc files.
801+ if not build_mingw32:
802+ swig_cmd.append("-I" + os.path.abspath("swig/swig_lib/python"))
803 swig_cmd.extend(self.current_extension.extra_swig_commands)
804 if not is_py3k:
805 swig_cmd.append("-DSWIG_PY2K")
806@@ -1368,7 +1421,10 @@ class my_install(install):
807 if not self.dry_run and not self.root:
808 # We must run the script we just installed into Scripts, as it
809 # may have had 2to3 run over it.
810- filename = os.path.join(self.prefix, "Scripts", "pywin32_postinstall.py")
811+ if build_mingw32:
812+ filename = os.path.join(self.prefix, "bin", "pywin32_postinstall.py")
813+ else:
814+ filename = os.path.join(self.prefix, "Scripts", "pywin32_postinstall.py")
815 if not os.path.isfile(filename):
816 raise RuntimeError("Can't find '%s'" % (filename,))
817 print("Executing post install script...")
818@@ -1388,18 +1444,25 @@ def my_new_compiler(**kw):
819 return orig_new_compiler(**kw)
820
821 # No way to cleanly wedge our compiler sub-class in.
822-from distutils import ccompiler, msvccompiler
823+from distutils import ccompiler
824 orig_new_compiler = ccompiler.new_compiler
825 ccompiler.new_compiler = my_new_compiler
826
827-base_compiler = msvccompiler.MSVCCompiler
828+if build_mingw32:
829+ from distutils import cygwinccompiler
830+ base_compiler = cygwinccompiler.Mingw32CCompiler
831+else:
832+ from distutils import msvccompiler
833+ base_compiler = msvccompiler.MSVCCompiler
834+
835
836 class my_compiler(base_compiler):
837 # Just one GUIDS.CPP and it gives trouble on mainwin too. Maybe I
838 # should just rename the file, but a case-only rename is likely to be
839 # worse! This can probably go away once we kill the VS project files
840 # though, as we can just specify the lowercase name in the module def.
841- _cpp_extensions = base_compiler._cpp_extensions + [".CPP"]
842+ if not build_mingw32:
843+ _cpp_extensions = base_compiler._cpp_extensions + [".CPP"]
844 src_extensions = base_compiler.src_extensions + [".CPP"]
845
846 def link(self,
847@@ -1411,17 +1474,41 @@ class my_compiler(base_compiler):
848 library_dirs=None,
849 runtime_library_dirs=None,
850 export_symbols=None,
851- debug=0, *args, **kw):
852- msvccompiler.MSVCCompiler.link( self,
853- target_desc,
854- objects,
855- output_filename,
856- output_dir,
857- libraries,
858- library_dirs,
859- runtime_library_dirs,
860- export_symbols,
861- debug, *args, **kw)
862+ debug=0, extra_preargs = None, *args, **kw):
863+ if build_mingw32:
864+ temp_dir = os.path.dirname(objects[0])
865+ dll_name = os.path.splitext(os.path.basename(output_filename))[0]
866+ lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
867+ implib_arg="-Wl,--out-implib,%s" % lib_file
868+
869+ if extra_preargs:
870+ extra_preargs.extend(implib_arg)
871+ else:
872+ extra_preargs = [implib_arg]
873+
874+ cygwinccompiler.Mingw32CCompiler.link( self,
875+ target_desc,
876+ objects,
877+ output_filename,
878+ output_dir,
879+ libraries,
880+ library_dirs,
881+ runtime_library_dirs,
882+ export_symbols,
883+ debug, extra_preargs,
884+ *args, **kw)
885+ else:
886+ msvccompiler.MSVCCompiler.link( self,
887+ target_desc,
888+ objects,
889+ output_filename,
890+ output_dir,
891+ libraries,
892+ library_dirs,
893+ runtime_library_dirs,
894+ export_symbols,
895+ debug, *args, **kw)
896+
897 # Here seems a good place to stamp the version of the built
898 # target. Do this externally to avoid suddenly dragging in the
899 # modules needed by this process, and which we will soon try and
900@@ -1457,6 +1544,45 @@ class my_compiler(base_compiler):
901 if not ok:
902 log.info('Unable to import verstamp, no version info will be added')
903
904+ if build_mingw32:
905+ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
906+ if ext == ".mc":
907+ try:
908+ basename=os.path.basename(src)[:-3]
909+ outdir=os.path.dirname(obj)
910+ self.spawn(["windmc", "-h", outdir, "-r", outdir, src])
911+ self.spawn(["windres", "-i",
912+ os.path.join(outdir, basename + ".rc"),
913+ "-o", obj])
914+ except DistutilsExecError as msg:
915+ raise CompileError(msg)
916+ else:
917+ cygwinccompiler.Mingw32CCompiler._compile(self,
918+ obj, src, ext, cc_args,
919+ extra_postargs, pp_opts)
920+
921+ def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
922+ unproc_src_names = []
923+ obj_names = []
924+ for src_name in source_filenames:
925+ base, ext = os.path.splitext(src_name)
926+ if ext==".mc":
927+ if unproc_src_names:
928+ obj_names.extend(cygwinccompiler.Mingw32CCompiler.\
929+ object_filenames(self, unproc_src_names,
930+ strip_dir = strip_dir,
931+ output_dir = output_dir))
932+ unproc_src_names = []
933+ obj_names.append (os.path.join(output_dir,
934+ base + ext + self.obj_extension))
935+ else:
936+ unproc_src_names.append(src_name)
937+ if unproc_src_names:
938+ obj_names.extend(cygwinccompiler.Mingw32CCompiler.\
939+ object_filenames(self, unproc_src_names, strip_dir = strip_dir,
940+ output_dir = output_dir))
941+ return obj_names
942+
943
944 ################################################################
945
946@@ -1550,7 +1676,7 @@ for info in (
947 win32/src/win32crypt/PyCRYPTPROV.cpp
948 win32/src/win32crypt/PyCTL_CONTEXT.cpp
949 """),
950- ("win32file", "", None, 0x0500, """
951+ ("win32file", "wsock32 ws2_32" if build_mingw32 else "", None, 0x0500, """
952 win32/src/win32file.i
953 win32/src/win32file_comm.cpp
954 """),
955@@ -1607,7 +1733,7 @@ for info in (
956 sources = info[4].split()
957 extra_compile_args = []
958 ext = WinExt_win32(name,
959- libraries=lib_names,
960+ libraries=lib_names + (" pywintypes" if build_mingw32 else ""),
961 extra_compile_args = extra_compile_args,
962 windows_h_version = windows_h_ver,
963 sources = sources,
964@@ -1620,7 +1746,7 @@ win32_extensions += [
965 sources = """
966 win32\\src\\win32evtlog_messages.mc win32\\src\\win32evtlog.i
967 """.split(),
968- libraries="advapi32 oleaut32",
969+ libraries="advapi32 oleaut32" + (" pywintypes" if build_mingw32 else ""),
970 delay_load_libraries="wevtapi",
971 windows_h_version=0x0600
972 ),
973@@ -1628,7 +1754,7 @@ win32_extensions += [
974 sources = """
975 win32/src/win32apimodule.cpp win32/src/win32api_display.cpp
976 """.split(),
977- libraries="user32 advapi32 shell32 version",
978+ libraries="user32 advapi32 shell32 version" + (" pywintypes" if build_mingw32 else ""),
979 delay_load_libraries="powrprof",
980 windows_h_version=0x0500,
981 ),
982@@ -1638,7 +1764,7 @@ win32_extensions += [
983 win32/src/win32gui.i
984 """.split(),
985 windows_h_version=0x0500,
986- libraries="gdi32 user32 comdlg32 comctl32 shell32",
987+ libraries="gdi32 user32 comdlg32 comctl32 shell32" + (" pywintypes" if build_mingw32 else ""),
988 define_macros = [("WIN32GUI", None)],
989 ),
990 # winxpgui is built from win32gui.i, but sets up different #defines before
991@@ -1648,7 +1774,7 @@ win32_extensions += [
992 win32/src/winxpgui.rc win32/src/win32dynamicdialog.cpp
993 win32/src/win32gui.i
994 """.split(),
995- libraries="gdi32 user32 comdlg32 comctl32 shell32",
996+ libraries="gdi32 user32 comdlg32 comctl32 shell32" + (" pywintypes" if build_mingw32 else ""),
997 windows_h_version=0x0500,
998 define_macros = [("WIN32GUI",None), ("WINXPGUI",None)],
999 extra_swig_commands=["-DWINXPGUI"],
1000@@ -1656,7 +1782,7 @@ win32_extensions += [
1001 # winxptheme
1002 WinExt_win32("_winxptheme",
1003 sources = ["win32/src/_winxptheme.i"],
1004- libraries="gdi32 user32 comdlg32 comctl32 shell32 Uxtheme",
1005+ libraries="gdi32 user32 comdlg32 comctl32 shell32 Uxtheme" + (" pywintypes" if build_mingw32 else ""),
1006 windows_h_version=0x0500,
1007 ),
1008 ]
1009@@ -1664,7 +1790,7 @@ win32_extensions += [
1010 WinExt_win32('servicemanager',
1011 sources = ["win32/src/PythonServiceMessages.mc", "win32/src/PythonService.cpp"],
1012 extra_compile_args = ['-DPYSERVICE_BUILD_DLL'],
1013- libraries = "user32 ole32 advapi32 shell32",
1014+ libraries = "user32 ole32 advapi32 shell32" + (" pywintypes" if build_mingw32 else ""),
1015 windows_h_version = 0x500,
1016 unicode_mode=True,),
1017 ]
1018@@ -1695,7 +1821,8 @@ dirs = {
1019
1020 # The COM modules.
1021 pythoncom = WinExt_system32('pythoncom',
1022- sources=("""
1023+ sources=((("%(win32com)s/initguid.cpp" if build_mingw32 else "") +
1024+ """
1025 %(win32com)s/dllmain.cpp %(win32com)s/ErrorUtils.cpp
1026 %(win32com)s/MiscTypes.cpp %(win32com)s/oleargs.cpp
1027 %(win32com)s/PyComHelpers.cpp %(win32com)s/PyFactory.cpp
1028@@ -1737,7 +1864,7 @@ pythoncom = WinExt_system32('pythoncom',
1029 %(win32com)s/extensions/PyICancelMethodCalls.cpp %(win32com)s/extensions/PyIContext.cpp
1030 %(win32com)s/extensions/PyIEnumContextProps.cpp %(win32com)s/extensions/PyIClientSecurity.cpp
1031 %(win32com)s/extensions/PyIServerSecurity.cpp
1032- """ % dirs).split(),
1033+ """) % dirs).split(),
1034 depends=("""
1035 %(win32com)s/include\\propbag.h %(win32com)s/include\\PyComTypeObjects.h
1036 %(win32com)s/include\\PyFactory.h %(win32com)s/include\\PyGConnectionPoint.h
1037@@ -1763,7 +1890,7 @@ pythoncom = WinExt_system32('pythoncom',
1038 %(win32com)s/include\\PyIEnumContextProps.h %(win32com)s/include\\PyIClientSecurity.h
1039 %(win32com)s/include\\PyIServerSecurity.h
1040 """ % dirs).split(),
1041- libraries = "oleaut32 ole32 user32 urlmon",
1042+ libraries = "oleaut32 ole32 user32 urlmon uuid" + (" pywintypes" if build_mingw32 else ""),
1043 export_symbol_file = 'com/win32com/src/PythonCOM.def',
1044 extra_compile_args = ['-DBUILD_PYTHONCOM'],
1045 pch_header = "stdafx.h",
1046@@ -1788,7 +1915,7 @@ com_extensions += [
1047 %(adsi)s/PyIADs.cpp
1048 """ % dirs).split()),
1049 WinExt_win32com('axcontrol', pch_header="axcontrol_pch.h",
1050- sources=("""
1051+ sources=(("""
1052 %(axcontrol)s/AXControl.cpp
1053 %(axcontrol)s/PyIOleControl.cpp %(axcontrol)s/PyIOleControlSite.cpp
1054 %(axcontrol)s/PyIOleInPlaceActiveObject.cpp
1055@@ -1799,10 +1926,11 @@ com_extensions += [
1056 %(axcontrol)s/PyIOleClientSite.cpp %(axcontrol)s/PyIOleInPlaceSite.cpp
1057 %(axcontrol)s/PyIOleObject.cpp %(axcontrol)s/PyIViewObject2.cpp
1058 %(axcontrol)s/PyIOleCommandTarget.cpp
1059- """ % dirs).split()),
1060+ """ + ("%(axcontrol)s/initguid.cpp" if build_mingw32 else "")) % dirs).split(),
1061+ libraries="pythoncom pywintypes"),
1062 WinExt_win32com('axscript',
1063- sources=("""
1064- %(axscript)s/AXScript.cpp
1065+ sources=(("""
1066+ %(axscript)s/AXScript.cpp %(axscript)s/initguid.cpp
1067 %(axscript)s/GUIDS.CPP %(axscript)s/PyGActiveScript.cpp
1068 %(axscript)s/PyGActiveScriptError.cpp %(axscript)s/PyGActiveScriptParse.cpp
1069 %(axscript)s/PyGActiveScriptSite.cpp %(axscript)s/PyGObjectSafety.cpp
1070@@ -1810,7 +1938,7 @@ com_extensions += [
1071 %(axscript)s/PyIActiveScriptParse.cpp %(axscript)s/PyIActiveScriptParseProcedure.cpp
1072 %(axscript)s/PyIActiveScriptSite.cpp %(axscript)s/PyIMultiInfos.cpp
1073 %(axscript)s/PyIObjectSafety.cpp %(axscript)s/stdafx.cpp
1074- """ % dirs).split(),
1075+ """ + ("%(axscript)s/initguid.cpp" if build_mingw32 else "")) % dirs).split(),
1076 depends=("""
1077 %(axscript)s/AXScript.h
1078 %(axscript)s/guids.h %(axscript)s/PyGActiveScriptError.h
1079@@ -1820,7 +1948,8 @@ com_extensions += [
1080 """ % dirs).split(),
1081 extra_compile_args = ['-DPY_BUILD_AXSCRIPT'],
1082 implib_name="axscript",
1083- pch_header = "stdafx.h"
1084+ pch_header = "stdafx.h",
1085+ libraries="pythoncom pywintypes" if build_mingw32 else ""
1086 ),
1087 WinExt_win32com('axdebug',
1088 libraries="axscript",
1089@@ -1870,17 +1999,17 @@ com_extensions += [
1090 %(axdebug)s/PyIRemoteDebugApplicationEvents.cpp
1091 %(axdebug)s/PyIRemoteDebugApplicationThread.cpp
1092 %(axdebug)s/stdafx.cpp
1093- """ % dirs).split(),
1094- ),
1095+ """ % dirs).split() ),
1096 WinExt_win32com('internet', pch_header="internet_pch.h",
1097- sources=("""
1098+ sources=(("""
1099 %(internet)s/internet.cpp %(internet)s/PyIDocHostUIHandler.cpp
1100 %(internet)s/PyIHTMLOMWindowServices.cpp %(internet)s/PyIInternetBindInfo.cpp
1101 %(internet)s/PyIInternetPriority.cpp %(internet)s/PyIInternetProtocol.cpp
1102 %(internet)s/PyIInternetProtocolInfo.cpp %(internet)s/PyIInternetProtocolRoot.cpp
1103 %(internet)s/PyIInternetProtocolSink.cpp %(internet)s/PyIInternetSecurityManager.cpp
1104- """ % dirs).split(),
1105- depends=["%(internet)s/internet_pch.h" % dirs]),
1106+ """ + ("%(internet)s/initguid.cpp" if build_mingw32 else "")) % dirs).split(),
1107+ depends=["%(internet)s/internet_pch.h" % dirs],
1108+ libraries="pythoncom pywintypes" if build_mingw32 else ""),
1109 WinExt_win32com('mapi', libraries="advapi32", pch_header="PythonCOM.h",
1110 include_dirs=["%(mapi)s/mapi_headers" % dirs],
1111 optional_headers=['edkmdb.h', 'edkguid.h'],
1112@@ -1929,9 +2058,10 @@ com_extensions += [
1113 %(mapi)s/mapi_stub_library/MapiStubLibrary.cpp
1114 %(mapi)s/mapi_stub_library/StubUtils.cpp
1115 """ % dirs).split()),
1116- WinExt_win32com('shell', libraries='shell32', pch_header="shell_pch.h",
1117+
1118+ WinExt_win32com('shell', libraries=('pythoncom pywintypes ' if build_mingw32 else '') + 'shell32', pch_header="shell_pch.h",
1119 windows_h_version = 0x600,
1120- sources=("""
1121+ sources=(("""
1122 %(shell)s/PyIActiveDesktop.cpp
1123 %(shell)s/PyIApplicationDestinations.cpp
1124 %(shell)s/PyIApplicationDocumentLists.cpp
1125@@ -1956,8 +2086,6 @@ com_extensions += [
1126 %(shell)s/PyIEnumObjects.cpp
1127 %(shell)s/PyIEnumResources.cpp
1128 %(shell)s/PyIEnumShellItems.cpp
1129- %(shell)s/PyIEmptyVolumeCache.cpp
1130- %(shell)s/PyIEmptyVolumeCacheCallBack.cpp
1131 %(shell)s/PyIExplorerBrowser.cpp
1132 %(shell)s/PyIExplorerBrowserEvents.cpp
1133 %(shell)s/PyIExplorerCommand.cpp
1134@@ -2002,8 +2130,9 @@ com_extensions += [
1135 %(shell)s/PyITransferSource.cpp
1136 %(shell)s/PyIUniformResourceLocator.cpp
1137 %(shell)s/shell.cpp
1138-
1139- """ % dirs).split()),
1140+ """ + ("%(shell)s/initguid.cpp" if build_mingw32 else
1141+ "%(shell)s/PyIEmptyVolumeCache.cpp %(shell)s/PyIEmptyVolumeCacheCallBack.cpp"))
1142+ % dirs).split()),
1143
1144 WinExt_win32com('propsys', libraries='propsys', delay_load_libraries='shell32',
1145 unicode_mode=True,
1146@@ -2031,9 +2160,8 @@ com_extensions += [
1147 implib_name="pypropsys",
1148 ),
1149
1150-
1151- WinExt_win32com('taskscheduler', libraries='mstask',
1152- sources=("""
1153+ WinExt_win32com('taskscheduler', libraries='mstask' + (' pythoncom pywintypes' if build_mingw32 else ''),
1154+ sources=(("""
1155 %(taskscheduler)s/taskscheduler.cpp
1156 %(taskscheduler)s/PyIProvideTaskPage.cpp
1157 %(taskscheduler)s/PyIScheduledWorkItem.cpp
1158@@ -2041,7 +2169,7 @@ com_extensions += [
1159 %(taskscheduler)s/PyITaskScheduler.cpp
1160 %(taskscheduler)s/PyITaskTrigger.cpp
1161
1162- """ % dirs).split()),
1163+ """ + ("%(taskscheduler)s/initguid.cpp" if build_mingw32 else ""))% dirs).split()),
1164 WinExt_win32com('bits', libraries='Bits', pch_header="bits_pch.h",
1165 sources=("""
1166 %(bits)s/bits.cpp
1167@@ -2077,12 +2205,12 @@ com_extensions += [
1168 %(directsound)s/PyIDirectSoundCaptureBuffer.h %(directsound)s/PyIDirectSoundNotify.h
1169 """ % dirs).split(),
1170 optional_headers = ['dsound.h'],
1171- libraries='user32 dsound dxguid'),
1172- WinExt_win32com('authorization', libraries='aclui advapi32',
1173+ libraries=('pythoncom pywintypes ' if build_mingw32 else '') + 'user32 dsound dxguid uuid'),
1174+ WinExt_win32com('authorization', libraries=('pythoncom pywintypes ' if build_mingw32 else '') + 'aclui advapi32',
1175 sources=("""
1176 %(authorization)s/authorization.cpp
1177 %(authorization)s/PyGSecurityInformation.cpp
1178- """ % dirs).split()),
1179+ """ % dirs).split())
1180 ]
1181
1182 pythonwin_extensions = [
1183@@ -2253,20 +2381,24 @@ other_extensions.append(
1184 W32_exe_files = [
1185 WinExt_win32("pythonservice",
1186 sources=[os.path.join("win32", "src", s) for s in
1187- "PythonService.cpp PythonService.rc".split()],
1188+ (("PythonServiceMessages.mc " if build_mingw32 else "") + "PythonService.cpp PythonService.rc").split()],
1189 unicode_mode = True,
1190- extra_link_args=["/SUBSYSTEM:CONSOLE"],
1191- libraries = "user32 advapi32 ole32 shell32"),
1192- WinExt_pythonwin("Pythonwin",
1193- sources = [
1194- "Pythonwin/pythonwin.cpp",
1195- "Pythonwin/pythonwin.rc",
1196- "Pythonwin/stdafxpw.cpp",
1197- ],
1198- extra_link_args=["/SUBSYSTEM:WINDOWS"],
1199- optional_headers=['afxres.h']),
1200+ extra_link_args=[] if build_mingw32 else ["/SUBSYSTEM:CONSOLE"],
1201+ libraries = ("pywintypes " if build_mingw32 else "") + "user32 advapi32 ole32 shell32")
1202 ]
1203
1204+if not build_mingw32:
1205+ W32_exe_files.append(
1206+ WinExt_pythonwin("Pythonwin",
1207+ sources = [
1208+ "Pythonwin/pythonwin.cpp",
1209+ "Pythonwin/pythonwin.rc",
1210+ "Pythonwin/stdafxpw.cpp",
1211+ ],
1212+ extra_link_args=["/SUBSYSTEM:WINDOWS"],
1213+ optional_headers=['afxres.h'])
1214+ )
1215+
1216 # Special definitions for SWIG.
1217 swig_interface_parents = {
1218 # source file base, "base class" for generated COM support
1219@@ -2415,7 +2547,10 @@ packages=['win32com',
1220 ]
1221
1222 py_modules = expand_modules("win32\\lib")
1223-ext_modules = win32_extensions + com_extensions + pythonwin_extensions + \
1224+if build_mingw32:
1225+ ext_modules = win32_extensions + com_extensions + other_extensions
1226+else:
1227+ ext_modules = win32_extensions + com_extensions + pythonwin_extensions + \
1228 other_extensions
1229
1230 # Build a map of DLL base addresses. According to Python's PC\dllbase_nt.txt,
1231diff --git a/win32/src/PerfMon/perfmondata.cpp b/win32/src/PerfMon/perfmondata.cpp
1232index 23e7557..c456d89 100644
1233--- a/win32/src/PerfMon/perfmondata.cpp
1234+++ b/win32/src/PerfMon/perfmondata.cpp
1235@@ -89,10 +89,19 @@ PPERF_COUNTER_BLOCK pCounterBlock;
1236 // these are used to insure that the data collection functions
1237 // accessed by Perflib will have the correct calling format.
1238 //
1239+
1240+#if defined(__MINGW32__)
1241+extern "C" {
1242+#endif
1243+
1244 PM_OPEN_PROC OpenPerformanceData;
1245 PM_COLLECT_PROC CollectPerformanceData;
1246 PM_CLOSE_PROC ClosePerformanceData;
1247
1248+#if defined(__MINGW32__)
1249+}
1250+#endif
1251+
1252 TCHAR szFullModulePath[MAX_PATH];
1253 TCHAR szModuleName[MAX_PATH]; // will point into the buffer above.
1254
1255@@ -130,6 +139,9 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
1256
1257
1258
1259+#if defined(__MINGW32__)
1260+extern "C"
1261+#endif
1262 DWORD APIENTRY OpenPerformanceData( LPWSTR lpDeviceNames )
1263 /*++
1264 Routine Description:
1265@@ -278,6 +290,9 @@ OpenExitPoint:
1266 return status;
1267 }
1268
1269+#if defined(__MINGW32__)
1270+extern "C"
1271+#endif
1272 DWORD APIENTRY CollectPerformanceData(
1273 IN LPWSTR lpValueName,
1274 IN OUT LPVOID *lppData,
1275@@ -379,6 +394,9 @@ Arguments: IN LPWSTR lpValueName
1276 return ERROR_SUCCESS;
1277 }
1278
1279+#if defined(__MINGW32__)
1280+extern "C"
1281+#endif
1282 DWORD APIENTRY ClosePerformanceData()
1283 /*++
1284 Routine Description:
1285@@ -445,7 +463,11 @@ HANDLE MonOpenEventLog (const TCHAR *szSourceName)
1286 --*/
1287 {
1288 HKEY hAppKey;
1289+#if defined(__MINGW32__)
1290+ TCHAR LogLevelKeyName[] = _T("SOFTWARE\\Microsoft\\Windows_NT\\CurrentVersion\\Perflib");
1291+#else
1292 TCHAR LogLevelKeyName[] = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib");
1293+#endif
1294
1295 TCHAR LogLevelValueName[] = _T("EventLogLevel");
1296 LONG lStatus;
1297diff --git a/win32/src/PySECURITY_DESCRIPTOR.cpp b/win32/src/PySECURITY_DESCRIPTOR.cpp
1298index 218daf9..2873603 100644
1299--- a/win32/src/PySECURITY_DESCRIPTOR.cpp
1300+++ b/win32/src/PySECURITY_DESCRIPTOR.cpp
1301@@ -6,6 +6,10 @@
1302 #include "PySecurityObjects.h"
1303 #include "structmember.h"
1304
1305+#if defined(__MINGW32__)
1306+#include <algorithm>
1307+#endif
1308+
1309 #ifndef NO_PYWINTYPES_SECURITY
1310 BOOL (WINAPI *setsecuritydescriptorcontrol)(PSECURITY_DESCRIPTOR, SECURITY_DESCRIPTOR_CONTROL, SECURITY_DESCRIPTOR_CONTROL)=NULL;
1311
1312@@ -786,7 +790,11 @@ PySECURITY_DESCRIPTOR::PySECURITY_DESCRIPTOR(Py_ssize_t cb /*= 0*/)
1313 {
1314 ob_type = &PySECURITY_DESCRIPTORType;
1315 _Py_NewReference(this);
1316+#if defined(__MINGW32__)
1317+ cb = std::max(cb, static_cast<Py_ssize_t>(SECURITY_DESCRIPTOR_MIN_LENGTH));
1318+#else
1319 cb = max(cb, SECURITY_DESCRIPTOR_MIN_LENGTH);
1320+#endif
1321 PSECURITY_DESCRIPTOR psd = malloc(cb);
1322 this->m_psd=NULL;
1323 if (::InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION))
1324diff --git a/win32/src/PyWinTypes.h b/win32/src/PyWinTypes.h
1325index 00ac8a1..a5fc23e 100644
1326--- a/win32/src/PyWinTypes.h
1327+++ b/win32/src/PyWinTypes.h
1328@@ -393,8 +393,13 @@ PYWINTYPES_EXPORT PyObject *PyWinObject_FromULARGE_INTEGER(ULARGE_INTEGER &val);
1329 // We also happen to know a LARGE_INTEGER is an __int64, so do it the easy way
1330 #define PyWinObject_AsPY_LONG_LONG(ob, pResult) PyWinObject_AsLARGE_INTEGER((ob), (LARGE_INTEGER *)(pResult))
1331 #define PyWinObject_AsUPY_LONG_LONG(ob, pResult) PyWinObject_AsULARGE_INTEGER((ob), (ULARGE_INTEGER *)(pResult))
1332+#if defined(__MINGW32__)
1333+#define PyWinObject_FromPY_LONG_LONG(val) PyWinObject_FromLARGE_INTEGER(val)
1334+#define PyWinObject_FromUPY_LONG_LONG(val) PyWinObject_FromULARGE_INTEGER(val)
1335+#else
1336 #define PyWinObject_FromPY_LONG_LONG(val) PyWinObject_FromLARGE_INTEGER((LARGE_INTEGER)val)
1337 #define PyWinObject_FromUPY_LONG_LONG(val) PyWinObject_FromULARGE_INTEGER((ULARGE_INTEGER)val)
1338+#endif
1339
1340 // A DWORD_PTR and ULONG_PTR appear to mean "integer long enough to hold a pointer"
1341 // It is *not* actually a pointer (but is the same size as a pointer)
1342@@ -797,7 +802,7 @@ private:
1343
1344 // A helper for simple exception handling.
1345 // try/__try
1346-#ifdef MAINWIN
1347+#if defined(__MINGW32__) || defined(MAINWIN)
1348 #define PYWINTYPES_TRY try
1349 #else
1350 #define PYWINTYPES_TRY __try
1351diff --git a/win32/src/PyWinTypesmodule.cpp b/win32/src/PyWinTypesmodule.cpp
1352index e136fff..77e10a4 100644
1353--- a/win32/src/PyWinTypesmodule.cpp
1354+++ b/win32/src/PyWinTypesmodule.cpp
1355@@ -1140,7 +1140,11 @@ BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
1356 }
1357
1358 // Function to format a python traceback into a character string.
1359+#if defined(__MINGW32__)
1360+#define GPEM_ERROR(what) {errorMsg = "<Error getting traceback - " what ">";goto done;}
1361+#else
1362 #define GPEM_ERROR(what) {errorMsg = "<Error getting traceback - " ## what ## ">";goto done;}
1363+#endif
1364 char *GetPythonTraceback(PyObject *exc_type, PyObject *exc_value, PyObject *exc_tb)
1365 {
1366 // Sleep (30000); // Time enough to attach the debugger (barely)
1367diff --git a/win32/src/PythonService.cpp b/win32/src/PythonService.cpp
1368index c7b7531..8a9121d 100644
1369--- a/win32/src/PythonService.cpp
1370+++ b/win32/src/PythonService.cpp
1371@@ -302,7 +302,11 @@ static PyObject *PySetEventSourceName(PyObject *self, PyObject *args)
1372 if (!PyWinObject_AsTCHAR(obName, &msg))
1373 return NULL;
1374 _tcsncpy(g_szEventSourceName, msg,
1375+#if defined(__MINGW32__)
1376+ sizeof(g_szEventSourceName)/sizeof(TCHAR));
1377+#else
1378 sizeof g_szEventSourceName/sizeof TCHAR);
1379+#endif
1380 PyWinObject_FreeTCHAR(msg);
1381 g_bRegisteredEventSource = FALSE; // so this name re-registered.
1382 if (registerNow)
1383@@ -680,10 +684,18 @@ BOOL PythonService_Initialize( const TCHAR *evtsrc_name, const TCHAR *evtsrc_fil
1384 {
1385 if (evtsrc_name && *evtsrc_name)
1386 _tcsncpy(g_szEventSourceName, evtsrc_name,
1387+#if defined(__MINGW32__)
1388+ sizeof(g_szEventSourceName)/sizeof(TCHAR));
1389+#else
1390 sizeof g_szEventSourceName/sizeof TCHAR);
1391+#endif
1392 if (evtsrc_file && *evtsrc_file)
1393 _tcsncpy(g_szEventSourceFileName, evtsrc_file,
1394+#if defined(__MINGW32__)
1395+ sizeof(g_szEventSourceFileName)/sizeof(TCHAR));
1396+#else
1397 sizeof g_szEventSourceFileName/sizeof TCHAR);
1398+#endif
1399 return TRUE;
1400 }
1401
1402@@ -1443,7 +1455,11 @@ static void CheckRegisterEventSourceFile()
1403
1404 if (!g_szEventSourceFileName[0])
1405 GetModuleFileName(g_hdll, g_szEventSourceFileName,
1406+#if defined(__MINGW32__)
1407+ sizeof(g_szEventSourceFileName)/sizeof(TCHAR));
1408+#else
1409 sizeof g_szEventSourceFileName/sizeof TCHAR);
1410+#endif
1411
1412 HKEY hkey;
1413 TCHAR keyName[MAX_PATH];
1414@@ -1549,7 +1565,11 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
1415 #else // PYSERVICE_BUILD_DLL
1416 // Our EXE entry point.
1417
1418+#if defined(__MINGW32__)
1419+extern "C" int main(int argc, TCHAR **argv)
1420+#else
1421 int _tmain(int argc, TCHAR **argv)
1422+#endif
1423 {
1424 PyObject *module, *f;
1425 PyThreadState *threadState;
1426diff --git a/win32/src/PythonServiceMessages.mc b/win32/src/PythonServiceMessages.mc
1427index ef26675..c8787a4 100644
1428--- a/win32/src/PythonServiceMessages.mc
1429+++ b/win32/src/PythonServiceMessages.mc
1430@@ -134,6 +134,7 @@ MessageId=0x7
1431 Severity=Error
1432 SymbolicName=E_UNUSED2
1433 Language=English
1434+%1
1435 .
1436
1437 MessageId=0x8
1438diff --git a/win32/src/odbc.cpp b/win32/src/odbc.cpp
1439index c58aef5..9d3dc35 100644
1440--- a/win32/src/odbc.cpp
1441+++ b/win32/src/odbc.cpp
1442@@ -18,6 +18,10 @@
1443 #include "PyWinObjects.h"
1444 #include "structmember.h"
1445
1446+#if defined(__MINGW32__)
1447+#include <algorithm>
1448+#endif
1449+
1450 #include <sql.h>
1451 #include <sqlext.h>
1452
1453@@ -105,96 +109,10 @@ static cursorObject *cursor(PyObject *o)
1454 }
1455
1456 static void cursorDealloc(PyObject *self);
1457-PyMethodDef cursorMethods[];
1458-PyMemberDef cursorMembers[];
1459
1460-static PyTypeObject Cursor_Type =
1461-{
1462- PYWIN_OBJECT_HEAD
1463- "odbccur", /*tp_name */
1464- sizeof(cursorObject), /*tp_basicsize */
1465- 0, /*tp_itemsize */
1466- cursorDealloc, /*tp_dealloc */
1467- 0, /*tp_print */
1468- 0, /*tp_getattr */
1469- 0, /*tp_setattr */
1470- 0, /*tp_compare */
1471- 0, /*tp_repr */
1472- 0, /*tp_as_number */
1473- 0, /* tp_as_sequence */
1474- 0, /* tp_as_mapping */
1475- 0, /* tp_hash */
1476- 0, /* tp_call */
1477- 0, /*tp_str */
1478- PyObject_GenericGetAttr, /* tp_getattro dbiGetAttr */
1479- PyObject_GenericSetAttr, /* tp_setattro */
1480- 0, /*tp_as_buffer*/
1481- Py_TPFLAGS_DEFAULT, /* tp_flags */
1482- 0, /* tp_doc */
1483- 0, /* tp_traverse */
1484- 0, /* tp_clear */
1485- 0, /* tp_richcompare */
1486- 0, /* tp_weaklistoffset */
1487- 0, /* tp_iter */
1488- 0, /* tp_iternext */
1489- cursorMethods, /* tp_methods */
1490- cursorMembers, /* tp_members */
1491- 0, /* tp_getset */
1492- 0, /* tp_base */
1493- 0, /* tp_dict */
1494- 0, /* tp_descr_get */
1495- 0, /* tp_descr_set */
1496- 0, /* tp_dictoffset */
1497- 0, /* tp_init */
1498- 0, /* tp_alloc */
1499- 0, /* tp_new */
1500-};
1501
1502
1503 static void connectionDealloc(PyObject *self);
1504-PyMethodDef connectionMethods[];
1505-PyMemberDef connectionMembers[];
1506-static PyTypeObject Connection_Type =
1507-{
1508- PYWIN_OBJECT_HEAD
1509- "odbcconn", /*tp_name */
1510- sizeof (connectionObject), /*tp_basicsize */
1511- 0, /*tp_itemsize */
1512- connectionDealloc, /*tp_dealloc */
1513- 0, /*tp_print */
1514- 0, /*tp_getattr */
1515- 0, /*tp_setattr */
1516- 0, /*tp_compare */
1517- 0, /*tp_repr */
1518- 0, /*tp_as_number */
1519- 0, /* tp_as_sequence */
1520- 0, /* tp_as_mapping */
1521- 0, /* tp_hash */
1522- 0, /* tp_call */
1523- 0, /*tp_str */
1524- PyObject_GenericGetAttr, /* tp_getattro dbiGetAttr */
1525- PyObject_GenericSetAttr, /* tp_setattro */
1526- 0, /*tp_as_buffer*/
1527- Py_TPFLAGS_DEFAULT, /* tp_flags */
1528- 0, /* tp_doc */
1529- 0, /* tp_traverse */
1530- 0, /* tp_clear */
1531- 0, /* tp_richcompare */
1532- 0, /* tp_weaklistoffset */
1533- 0, /* tp_iter */
1534- 0, /* tp_iternext */
1535- connectionMethods, /* tp_methods */
1536- connectionMembers, /* tp_members */
1537- 0, /* tp_getset */
1538- 0, /* tp_base */
1539- 0, /* tp_dict */
1540- 0, /* tp_descr_get */
1541- 0, /* tp_descr_set */
1542- 0, /* tp_dictoffset */
1543- 0, /* tp_init */
1544- 0, /* tp_alloc */
1545- 0, /* tp_new */
1546-};
1547
1548 static int unsuccessful(RETCODE rc)
1549 {
1550@@ -334,144 +252,6 @@ static int attemptReconnect(cursorObject *cur)
1551 }
1552
1553
1554-/* @pymethod |connection|setautocommit|Sets the autocommit mode. */
1555-static PyObject *odbcSetAutoCommit(PyObject *self, PyObject *args)
1556-{
1557- int c;
1558- connectionObject *conn;
1559- /* @pyparm int|c||The boolean autocommit mode. */
1560- if (!PyArg_ParseTuple(args, "i",&c))
1561- return NULL;
1562- conn=connection(self);
1563- if (c==0)
1564- {
1565- if (unsuccessful(SQLSetConnectOption(
1566- conn->hdbc,
1567- SQL_AUTOCOMMIT,
1568- SQL_AUTOCOMMIT_OFF)))
1569- {
1570- connectionError(conn, _T("SETAUTOCOMMIT"));
1571- return NULL;
1572- }
1573- }
1574- else
1575- {
1576- if (unsuccessful(SQLSetConnectOption(
1577- conn->hdbc,
1578- SQL_AUTOCOMMIT,
1579- SQL_AUTOCOMMIT_ON)))
1580- {
1581- connectionError(conn, _T("SETAUTOCOMMIT"));
1582- return NULL;
1583- };
1584- }
1585-
1586- Py_INCREF(Py_None);
1587- return Py_None;
1588-}
1589-
1590-
1591-/* @pymethod |connection|commit|Commits a transaction. */
1592-static PyObject *odbcCommit(PyObject *self, PyObject *args)
1593-{
1594- RETCODE rc;
1595- Py_BEGIN_ALLOW_THREADS
1596- rc = SQLTransact(
1597- Env,
1598- connection(self)->hdbc,
1599- SQL_COMMIT);
1600- Py_END_ALLOW_THREADS
1601- if (unsuccessful(rc))
1602- {
1603- connectionError(connection(self), _T("COMMIT"));
1604- return 0;
1605- }
1606- else
1607- {
1608- Py_INCREF(Py_None);
1609- return Py_None;
1610- }
1611-}
1612-
1613-/* @pymethod |connection|rollback|Rollsback a transaction. */
1614-static PyObject *odbcRollback(PyObject *self, PyObject *args)
1615-{
1616- RETCODE rc;
1617- Py_BEGIN_ALLOW_THREADS
1618- rc = SQLTransact(
1619- Env,
1620- connection(self)->hdbc,
1621- SQL_ROLLBACK);
1622- Py_END_ALLOW_THREADS
1623- if (unsuccessful(rc))
1624- {
1625- connectionError(connection(self), _T("ROLLBACK"));
1626- return 0;
1627- }
1628- else {
1629- Py_INCREF(Py_None);
1630- return Py_None;
1631- }
1632-}
1633-
1634-/* @pymethod |connection|cursor|Creates a <o cursor> object */
1635-static PyObject *odbcCursor(PyObject *self, PyObject *args)
1636-{
1637- connectionObject *conn = connection(self);
1638- if (conn->connected == 0)
1639- {
1640- if (doConnect(conn))
1641- {
1642- return 0;
1643- }
1644- }
1645-
1646- cursorObject *cur = PyObject_New(cursorObject, &Cursor_Type);
1647- if (cur == NULL)
1648- return NULL;
1649-
1650- cur->outputVars = 0;
1651- cur->inputVars = 0;
1652- cur->description = 0;
1653- cur->max_width = 65536L;
1654- cur->my_conx = 0;
1655- cur->hstmt=NULL;
1656- cur->cursorError=odbcError;
1657- Py_INCREF(odbcError);
1658- if (unsuccessful(SQLAllocStmt(conn->hdbc, &cur->hstmt)))
1659- {
1660- connectionError(cur->my_conx, _T("OPEN"));
1661- Py_DECREF(cur);
1662- return NULL;
1663- }
1664- cur->my_conx = conn;
1665- cur->connect_id = cur->my_conx->connect_id;
1666- Py_INCREF(self); /* the cursors owns a reference to the connection */
1667- return (PyObject*) cur;
1668-}
1669-
1670-/* @pymethod |connection|close|Closes the connection. */
1671-static PyObject *odbcClose(PyObject *self, PyObject *args)
1672-{
1673- Py_INCREF(Py_None);
1674- return Py_None;
1675-}
1676-
1677-/* @object connection|An object representing an ODBC connection */
1678-static struct PyMethodDef connectionMethods[] = {
1679- { "setautocommit", odbcSetAutoCommit, 1 }, /* @pymeth setautocommit|Sets the autocommit mode. */
1680- { "commit", odbcCommit, 1 } , /* @pymeth commit|Commits a transaction. */
1681- { "rollback", odbcRollback, 1 } , /* @pymeth rollback|Rollsback a transaction. */
1682- { "cursor", odbcCursor, 1 } , /* @pymeth cursor|Creates a <o cursor> object */
1683- { "close", odbcClose, 1 } , /* @pymeth close|Closes the connection. */
1684- {0, 0}
1685-};
1686-
1687-static PyMemberDef connectionMembers[] = {
1688- {"error", T_OBJECT, offsetof(connectionObject, connectionError), READONLY},
1689- {NULL}
1690-};
1691-
1692 static void connectionDealloc(PyObject *self)
1693 {
1694 Py_XDECREF(connection(self)->connectionError);
1695@@ -1192,21 +972,41 @@ static int display_size(short coltype, int collen, const TCHAR *colname)
1696 case SQL_DATE:
1697 case SQL_TIMESTAMP:
1698 case SQL_BIT:
1699+#if defined(__MINGW32__)
1700+ return(std::max(collen, (int)_tcslen(colname)));
1701+#else
1702 return(max(collen, (int)_tcslen(colname)));
1703+#endif
1704 case SQL_SMALLINT:
1705 case SQL_INTEGER:
1706 case SQL_TINYINT:
1707+#if defined(__MINGW32__)
1708+ return(std::max(collen+1, (int)_tcslen(colname)));
1709+#else
1710 return(max(collen+1, (int)_tcslen(colname)));
1711+#endif
1712 case SQL_DECIMAL:
1713 case SQL_NUMERIC:
1714+#if defined(__MINGW32__)
1715+ return(std::max(collen+2, (int)_tcslen(colname)));
1716+#else
1717 return(max(collen+2, (int)_tcslen(colname)));
1718+#endif
1719 case SQL_REAL:
1720 case SQL_FLOAT:
1721 case SQL_DOUBLE:
1722+#if defined(__MINGW32__)
1723+ return(std::max(20, (int)_tcslen(colname)));
1724+#else
1725 return(max(20, (int)_tcslen(colname)));
1726+#endif
1727 case SQL_BINARY:
1728 case SQL_VARBINARY:
1729+#if defined(__MINGW32__)
1730+ return(std::max(2*collen, (int)_tcslen(colname)));
1731+#else
1732 return(max(2*collen, (int)_tcslen(colname)));
1733+#endif
1734 case SQL_LONGVARBINARY:
1735 case SQL_LONGVARCHAR:
1736 default:
1737@@ -1814,6 +1614,226 @@ static PyMemberDef cursorMembers[] = {
1738 {NULL}
1739 };
1740
1741+static PyTypeObject Cursor_Type =
1742+{
1743+ PYWIN_OBJECT_HEAD
1744+ "odbccur", /*tp_name */
1745+ sizeof(cursorObject), /*tp_basicsize */
1746+ 0, /*tp_itemsize */
1747+ cursorDealloc, /*tp_dealloc */
1748+ 0, /*tp_print */
1749+ 0, /*tp_getattr */
1750+ 0, /*tp_setattr */
1751+ 0, /*tp_compare */
1752+ 0, /*tp_repr */
1753+ 0, /*tp_as_number */
1754+ 0, /* tp_as_sequence */
1755+ 0, /* tp_as_mapping */
1756+ 0, /* tp_hash */
1757+ 0, /* tp_call */
1758+ 0, /*tp_str */
1759+ PyObject_GenericGetAttr, /* tp_getattro dbiGetAttr */
1760+ PyObject_GenericSetAttr, /* tp_setattro */
1761+ 0, /*tp_as_buffer*/
1762+ Py_TPFLAGS_DEFAULT, /* tp_flags */
1763+ 0, /* tp_doc */
1764+ 0, /* tp_traverse */
1765+ 0, /* tp_clear */
1766+ 0, /* tp_richcompare */
1767+ 0, /* tp_weaklistoffset */
1768+ 0, /* tp_iter */
1769+ 0, /* tp_iternext */
1770+ cursorMethods, /* tp_methods */
1771+ cursorMembers, /* tp_members */
1772+ 0, /* tp_getset */
1773+ 0, /* tp_base */
1774+ 0, /* tp_dict */
1775+ 0, /* tp_descr_get */
1776+ 0, /* tp_descr_set */
1777+ 0, /* tp_dictoffset */
1778+ 0, /* tp_init */
1779+ 0, /* tp_alloc */
1780+ 0, /* tp_new */
1781+};
1782+/* @pymethod |connection|setautocommit|Sets the autocommit mode. */
1783+static PyObject *odbcSetAutoCommit(PyObject *self, PyObject *args)
1784+{
1785+ int c;
1786+ connectionObject *conn;
1787+ /* @pyparm int|c||The boolean autocommit mode. */
1788+ if (!PyArg_ParseTuple(args, "i",&c))
1789+ return NULL;
1790+ conn=connection(self);
1791+ if (c==0)
1792+ {
1793+ if (unsuccessful(SQLSetConnectOption(
1794+ conn->hdbc,
1795+ SQL_AUTOCOMMIT,
1796+ SQL_AUTOCOMMIT_OFF)))
1797+ {
1798+ connectionError(conn, _T("SETAUTOCOMMIT"));
1799+ return NULL;
1800+ }
1801+ }
1802+ else
1803+ {
1804+ if (unsuccessful(SQLSetConnectOption(
1805+ conn->hdbc,
1806+ SQL_AUTOCOMMIT,
1807+ SQL_AUTOCOMMIT_ON)))
1808+ {
1809+ connectionError(conn, _T("SETAUTOCOMMIT"));
1810+ return NULL;
1811+ };
1812+ }
1813+
1814+ Py_INCREF(Py_None);
1815+ return Py_None;
1816+}
1817+
1818+
1819+/* @pymethod |connection|commit|Commits a transaction. */
1820+static PyObject *odbcCommit(PyObject *self, PyObject *args)
1821+{
1822+ RETCODE rc;
1823+ Py_BEGIN_ALLOW_THREADS
1824+ rc = SQLTransact(
1825+ Env,
1826+ connection(self)->hdbc,
1827+ SQL_COMMIT);
1828+ Py_END_ALLOW_THREADS
1829+ if (unsuccessful(rc))
1830+ {
1831+ connectionError(connection(self), _T("COMMIT"));
1832+ return 0;
1833+ }
1834+ else
1835+ {
1836+ Py_INCREF(Py_None);
1837+ return Py_None;
1838+ }
1839+}
1840+
1841+/* @pymethod |connection|rollback|Rollsback a transaction. */
1842+static PyObject *odbcRollback(PyObject *self, PyObject *args)
1843+{
1844+ RETCODE rc;
1845+ Py_BEGIN_ALLOW_THREADS
1846+ rc = SQLTransact(
1847+ Env,
1848+ connection(self)->hdbc,
1849+ SQL_ROLLBACK);
1850+ Py_END_ALLOW_THREADS
1851+ if (unsuccessful(rc))
1852+ {
1853+ connectionError(connection(self), _T("ROLLBACK"));
1854+ return 0;
1855+ }
1856+ else {
1857+ Py_INCREF(Py_None);
1858+ return Py_None;
1859+ }
1860+}
1861+
1862+/* @pymethod |connection|cursor|Creates a <o cursor> object */
1863+static PyObject *odbcCursor(PyObject *self, PyObject *args)
1864+{
1865+ connectionObject *conn = connection(self);
1866+ if (conn->connected == 0)
1867+ {
1868+ if (doConnect(conn))
1869+ {
1870+ return 0;
1871+ }
1872+ }
1873+
1874+ cursorObject *cur = PyObject_New(cursorObject, &Cursor_Type);
1875+ if (cur == NULL)
1876+ return NULL;
1877+
1878+ cur->outputVars = 0;
1879+ cur->inputVars = 0;
1880+ cur->description = 0;
1881+ cur->max_width = 65536L;
1882+ cur->my_conx = 0;
1883+ cur->hstmt=NULL;
1884+ cur->cursorError=odbcError;
1885+ Py_INCREF(odbcError);
1886+ if (unsuccessful(SQLAllocStmt(conn->hdbc, &cur->hstmt)))
1887+ {
1888+ connectionError(cur->my_conx, _T("OPEN"));
1889+ Py_DECREF(cur);
1890+ return NULL;
1891+ }
1892+ cur->my_conx = conn;
1893+ cur->connect_id = cur->my_conx->connect_id;
1894+ Py_INCREF(self); /* the cursors owns a reference to the connection */
1895+ return (PyObject*) cur;
1896+}
1897+
1898+/* @pymethod |connection|close|Closes the connection. */
1899+static PyObject *odbcClose(PyObject *self, PyObject *args)
1900+{
1901+ Py_INCREF(Py_None);
1902+ return Py_None;
1903+}
1904+
1905+/* @object connection|An object representing an ODBC connection */
1906+static struct PyMethodDef connectionMethods[6] = {
1907+ { "setautocommit", odbcSetAutoCommit, 1 }, /* @pymeth setautocommit|Sets the autocommit mode. */
1908+ { "commit", odbcCommit, 1 } , /* @pymeth commit|Commits a transaction. */
1909+ { "rollback", odbcRollback, 1 } , /* @pymeth rollback|Rollsback a transaction. */
1910+ { "cursor", odbcCursor, 1 } , /* @pymeth cursor|Creates a <o cursor> object */
1911+ { "close", odbcClose, 1 } , /* @pymeth close|Closes the connection. */
1912+ {0, 0}
1913+};
1914+
1915+static PyMemberDef connectionMembers[2] = {
1916+ {"error", T_OBJECT, offsetof(connectionObject, connectionError), READONLY},
1917+ {NULL}
1918+};
1919+
1920+static PyTypeObject Connection_Type =
1921+{
1922+ PYWIN_OBJECT_HEAD
1923+ "odbcconn", /*tp_name */
1924+ sizeof (connectionObject), /*tp_basicsize */
1925+ 0, /*tp_itemsize */
1926+ connectionDealloc, /*tp_dealloc */
1927+ 0, /*tp_print */
1928+ 0, /*tp_getattr */
1929+ 0, /*tp_setattr */
1930+ 0, /*tp_compare */
1931+ 0, /*tp_repr */
1932+ 0, /*tp_as_number */
1933+ 0, /* tp_as_sequence */
1934+ 0, /* tp_as_mapping */
1935+ 0, /* tp_hash */
1936+ 0, /* tp_call */
1937+ 0, /*tp_str */
1938+ PyObject_GenericGetAttr, /* tp_getattro dbiGetAttr */
1939+ PyObject_GenericSetAttr, /* tp_setattro */
1940+ 0, /*tp_as_buffer*/
1941+ Py_TPFLAGS_DEFAULT, /* tp_flags */
1942+ 0, /* tp_doc */
1943+ 0, /* tp_traverse */
1944+ 0, /* tp_clear */
1945+ 0, /* tp_richcompare */
1946+ 0, /* tp_weaklistoffset */
1947+ 0, /* tp_iter */
1948+ 0, /* tp_iternext */
1949+ connectionMethods, /* tp_methods */
1950+ connectionMembers, /* tp_members */
1951+ 0, /* tp_getset */
1952+ 0, /* tp_base */
1953+ 0, /* tp_dict */
1954+ 0, /* tp_descr_get */
1955+ 0, /* tp_descr_set */
1956+ 0, /* tp_dictoffset */
1957+ 0, /* tp_init */
1958+ 0, /* tp_alloc */
1959+ 0, /* tp_new */
1960+};
1961 static void parseInfo(connectionObject *conn, const TCHAR *c)
1962 {
1963 TCHAR *p;
1964diff --git a/win32/src/win32apimodule.cpp b/win32/src/win32apimodule.cpp
1965index f7e36b1..dd5223f 100644
1966--- a/win32/src/win32apimodule.cpp
1967+++ b/win32/src/win32apimodule.cpp
1968@@ -817,12 +817,16 @@ PyFormatMessageA(PyObject *self, PyObject *args)
1969
1970 {
1971 PyW32_BEGIN_ALLOW_THREADS
1972+#if !defined(__MINGW32__)
1973 __try{
1974+#endif
1975 lrc = ::FormatMessageA(flags, pSource, msgId, langId, (LPSTR)&resultBuf, 0, (va_list *)pInserts );
1976+#if !defined(__MINGW32__)
1977 }
1978 __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH){
1979 baccessviolation=TRUE;
1980 }
1981+#endif
1982 PyW32_END_ALLOW_THREADS
1983 }
1984
1985@@ -927,12 +931,16 @@ PyFormatMessageW(PyObject *self, PyObject *args)
1986
1987 {
1988 PyW32_BEGIN_ALLOW_THREADS
1989+#if !defined(__MINGW32__)
1990 __try{
1991+#endif
1992 lrc = ::FormatMessageW(flags, pSource, msgId, langId, (LPWSTR)&resultBuf, 0, (va_list *)pInserts );
1993+#if !defined(__MINGW32__)
1994 }
1995 __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH){
1996 baccessviolation=TRUE;
1997 }
1998+#endif
1999 PyW32_END_ALLOW_THREADS
2000 }
2001
2002@@ -5774,8 +5782,11 @@ static PyObject *PyApply(PyObject *self, PyObject *args)
2003 }
2004 PyThreadState *stateSave = PyThreadState_Swap(NULL);
2005 PyThreadState_Swap(stateSave);
2006+#if !defined(__MINGW32__)
2007 _try {
2008+#endif
2009 ret = PyObject_CallObject(obFunc, obArgs);
2010+#if !defined(__MINGW32__)
2011 }
2012 _except( PyApplyExceptionFilter( GetExceptionCode(),
2013 GetExceptionInformation(),
2014@@ -5804,6 +5815,7 @@ static PyObject *PyApply(PyObject *self, PyObject *args)
2015 Py_XDECREF(exc_value);
2016 ret = NULL;
2017 }
2018+#endif
2019 return ret;
2020 // @comm Calls the specified function in a manner similar to
2021 // the built-in function apply(), but allows Win32 exceptions
2022diff --git a/win32/src/win32crypt/PyCRYPTPROV.cpp b/win32/src/win32crypt/PyCRYPTPROV.cpp
2023index 140ddd3..3de895c 100644
2024--- a/win32/src/win32crypt/PyCRYPTPROV.cpp
2025+++ b/win32/src/win32crypt/PyCRYPTPROV.cpp
2026@@ -1,6 +1,10 @@
2027 // @doc
2028 #include "win32crypt.h"
2029
2030+#if defined(__MINGW32__)
2031+#include <algorithm>
2032+#endif
2033+
2034 // @object PyCRYPTPROV|Handle to a cryptographic provider, created using <om cryptoapi.CryptAcquireContext>
2035 struct PyMethodDef PyCRYPTPROV::methods[] = {
2036 // @pymeth CryptReleaseContext|Releases the CSP handle
2037@@ -351,7 +355,11 @@ PyObject *PyCRYPTPROV::PyCryptGenRandom(PyObject *self, PyObject *args, PyObject
2038 //initialize buffer with char string if passed if
2039 ZeroMemory(pbBuffer, dwLen+1);
2040 if (seeddata != NULL)
2041+#if defined(__MINGW32__)
2042+ memcpy(pbBuffer, seeddata, std::min(dwLen,seedlen));
2043+#else
2044 memcpy(pbBuffer, seeddata, min(dwLen,seedlen));
2045+#endif
2046 if (CryptGenRandom(hcryptprov, dwLen, pbBuffer))
2047 ret=PyString_FromStringAndSize((char *)pbBuffer, dwLen);
2048 else
2049diff --git a/win32/src/win32crypt/win32cryptmodule.cpp b/win32/src/win32crypt/win32cryptmodule.cpp
2050index 29b2c80..5875294 100644
2051--- a/win32/src/win32crypt/win32cryptmodule.cpp
2052+++ b/win32/src/win32crypt/win32cryptmodule.cpp
2053@@ -597,34 +597,59 @@ static PyObject *PyCertOpenStore(PyObject *self, PyObject *args, PyObject *kwarg
2054 }
2055 else{
2056 switch((ULONG_PTR)StoreProvider){
2057+#if defined(__MINGW32__)
2058+ case (ULONG_PTR)14:
2059+ case (ULONG_PTR)8:
2060+ case (ULONG_PTR)10:
2061+ case (ULONG_PTR)13:
2062+ case (ULONG_PTR)16:{
2063+#else
2064 case CERT_STORE_PROV_PHYSICAL:
2065 case CERT_STORE_PROV_FILENAME:
2066 case CERT_STORE_PROV_SYSTEM:
2067 case CERT_STORE_PROV_SYSTEM_REGISTRY:
2068 case CERT_STORE_PROV_LDAP:{
2069+#endif
2070 if (!PyWinObject_AsWCHAR(obpvPara, (WCHAR **)&pvPara))
2071 return NULL;
2072 free_wchar=TRUE;
2073 break;
2074 }
2075+#if defined(__MINGW32__)
2076+ case (ULONG_PTR)4:{
2077+#else
2078 case CERT_STORE_PROV_REG:{
2079+#endif
2080 if (!PyWinObject_AsHKEY(obpvPara, (HKEY *)&pvPara))
2081 return NULL;
2082 break;
2083 }
2084+#if defined(__MINGW32__)
2085+ case (ULONG_PTR)3:{
2086+#else
2087 case CERT_STORE_PROV_FILE:{
2088+#endif
2089 if (!PyWinObject_AsHANDLE(obpvPara, (HANDLE *)&pvPara))
2090 return NULL;
2091 break;
2092 }
2093+#if defined(__MINGW32__)
2094+ case (ULONG_PTR)6:
2095+ case (ULONG_PTR)5:{
2096+#else
2097 case CERT_STORE_PROV_SERIALIZED:
2098 case CERT_STORE_PROV_PKCS7:{
2099+#endif
2100 if (!PyWinObject_AsReadBuffer(obpvPara, (void **)&crypt_data_blob.pbData, &crypt_data_blob.cbData))
2101 return NULL;
2102 pvPara=(void *)&crypt_data_blob;
2103 break;
2104 }
2105+#if defined(__MINGW32__)
2106+ case (ULONG_PTR)2:{
2107+#else
2108 case CERT_STORE_PROV_MEMORY:{
2109+#endif
2110 // pvPara is not used, warn if something passed in
2111 if (obpvPara != Py_None)
2112 PyErr_Warn(PyExc_RuntimeWarning, "Para ignored for CERT_STORE_PROV_MEMORY");
2113diff --git a/win32/src/win32evtlog.i b/win32/src/win32evtlog.i
2114index 847230c..142923b 100644
2115--- a/win32/src/win32evtlog.i
2116+++ b/win32/src/win32evtlog.i
2117@@ -1012,11 +1012,15 @@ PyCFunction pfnPyEvtUpdateBookmark = (PyCFunction) PyEvtUpdateBookmark;
2118
2119 PyObject *PyWinObject_FromEVT_VARIANT(PEVT_VARIANT val)
2120 {
2121+#if defined(__MINGW32__)
2122+ DWORD val_type = val->Type;
2123+#else
2124 if (val->Type & EVT_VARIANT_TYPE_ARRAY){
2125 PyErr_SetString(PyExc_NotImplementedError, "EVT_VARIANT arrays not supported yet");
2126 return NULL;
2127 }
2128 DWORD val_type = val->Type & EVT_VARIANT_TYPE_MASK;
2129+#endif
2130 PyObject *obval = NULL;
2131 switch (val_type){
2132 case EvtVarTypeNull:
2133diff --git a/win32/src/win32file.i b/win32/src/win32file.i
2134index 2b82d37..39e7cd1 100644
2135--- a/win32/src/win32file.i
2136+++ b/win32/src/win32file.i
2137@@ -1420,11 +1420,19 @@ static PyObject *PyObject_FromFILE_NOTIFY_INFORMATION(void *buffer, DWORD nbytes
2138 // the filename is exactly 1 byte! Not clear the best way to
2139 // check this, but this works for now - is it at least the size of
2140 // the *head* of the struct.
2141+#if defined(__MINGW32__)
2142+ if (nbytes < sizeof(DWORD)*3+2)
2143+#else
2144 if (nbytes < sizeof DWORD*3+2)
2145+#endif
2146 return ret;
2147 DWORD nbytes_read = 0;
2148 while (1) {
2149+#if defined(__MINGW32__)
2150+ PyObject *fname = PyWinObject_FromOLECHAR(p->FileName, p->FileNameLength/sizeof(WCHAR));
2151+#else
2152 PyObject *fname = PyWinObject_FromOLECHAR(p->FileName, p->FileNameLength/sizeof WCHAR);
2153+#endif
2154 if (!fname) {
2155 Py_DECREF(ret);
2156 return NULL;
2157diff --git a/win32/src/win32file_comm.cpp b/win32/src/win32file_comm.cpp
2158index 19f2eb7..d16fb76 100644
2159--- a/win32/src/win32file_comm.cpp
2160+++ b/win32/src/win32file_comm.cpp
2161@@ -173,11 +173,19 @@ PyDCB::~PyDCB(void)
2162 {
2163 }
2164
2165+#if defined(__MINGW32__)
2166+#define GET_BITFIELD_ENTRY(bitfield_name) \
2167+ else if (strcmp(name, #bitfield_name)==0) { \
2168+ return PyInt_FromLong(pydcb->m_DCB. bitfield_name); \
2169+ } \
2170+
2171+#else
2172 #define GET_BITFIELD_ENTRY(bitfield_name) \
2173 else if (strcmp(name, #bitfield_name)==0) { \
2174 return PyInt_FromLong(pydcb->m_DCB.##bitfield_name); \
2175 } \
2176
2177+#endif
2178 PyObject *PyDCB::getattro(PyObject *self, PyObject *obname)
2179 {
2180 PyDCB *pydcb = (PyDCB *)self;
2181@@ -204,7 +212,19 @@ PyObject *PyDCB::getattro(PyObject *self, PyObject *obname)
2182 return PyObject_GenericGetAttr(self, obname);
2183 }
2184
2185+#if defined(__MINGW32__)
2186 #define SET_BITFIELD_ENTRY(bitfield_name) \
2187+ else if (strcmp(name, #bitfield_name)==0) { \
2188+ if (!PyInt_Check(v)) { \
2189+ PyErr_Format(PyExc_TypeError, szNeedIntAttr, #bitfield_name); \
2190+ return -1; \
2191+ } \
2192+ pydcb->m_DCB. bitfield_name = PyInt_AsLong(v); \
2193+ return 0; \
2194+ } \
2195+
2196+#else
2197+#define SET_BITFIELD_ENTRY(bitfield_name) \
2198 else if (strcmp(name, #bitfield_name)==0) { \
2199 if (!PyInt_Check(v)) { \
2200 PyErr_Format(PyExc_TypeError, szNeedIntAttr, #bitfield_name); \
2201@@ -214,6 +234,7 @@ PyObject *PyDCB::getattro(PyObject *self, PyObject *obname)
2202 return 0; \
2203 } \
2204
2205+#endif
2206 int PyDCB::setattro(PyObject *self, PyObject *obname, PyObject *v)
2207 {
2208 PyDCB *pydcb = (PyDCB *)self;
2209@@ -367,11 +388,19 @@ PyCOMSTAT::~PyCOMSTAT(void)
2210 }
2211
2212 #undef GET_BITFIELD_ENTRY
2213+#if defined(__MINGW32__)
2214+#define GET_BITFIELD_ENTRY(bitfield_name) \
2215+ else if (strcmp(name, #bitfield_name)==0) { \
2216+ return PyInt_FromLong(pyCOMSTAT->m_COMSTAT. bitfield_name); \
2217+ } \
2218+
2219+#else
2220 #define GET_BITFIELD_ENTRY(bitfield_name) \
2221 else if (strcmp(name, #bitfield_name)==0) { \
2222 return PyInt_FromLong(pyCOMSTAT->m_COMSTAT.##bitfield_name); \
2223 } \
2224
2225+#endif
2226 PyObject *PyCOMSTAT::getattro(PyObject *self, PyObject *obname)
2227 {
2228 PyCOMSTAT *pyCOMSTAT = (PyCOMSTAT *)self;
2229@@ -392,6 +421,18 @@ PyObject *PyCOMSTAT::getattro(PyObject *self, PyObject *obname)
2230 }
2231
2232 #undef SET_BITFIELD_ENTRY
2233+#if defined(__MINGW32__)
2234+#define SET_BITFIELD_ENTRY(bitfield_name) \
2235+ else if (strcmp(name, #bitfield_name)==0) { \
2236+ if (!PyInt_Check(v)) { \
2237+ PyErr_Format(PyExc_TypeError, szNeedIntAttr, #bitfield_name); \
2238+ return -1; \
2239+ } \
2240+ pyCOMSTAT->m_COMSTAT. bitfield_name = PyInt_AsLong(v); \
2241+ return 0; \
2242+ } \
2243+
2244+#else
2245 #define SET_BITFIELD_ENTRY(bitfield_name) \
2246 else if (strcmp(name, #bitfield_name)==0) { \
2247 if (!PyInt_Check(v)) { \
2248@@ -402,6 +443,7 @@ PyObject *PyCOMSTAT::getattro(PyObject *self, PyObject *obname)
2249 return 0; \
2250 } \
2251
2252+#endif
2253 int PyCOMSTAT::setattro(PyObject *self, PyObject *obname, PyObject *v)
2254 {
2255 PyCOMSTAT *pyCOMSTAT = (PyCOMSTAT *)self;
2256diff --git a/win32/src/win32gui.i b/win32/src/win32gui.i
2257index 94b738f..bc5e494 100644
2258--- a/win32/src/win32gui.i
2259+++ b/win32/src/win32gui.i
2260@@ -34,6 +34,9 @@
2261 #include "Dbt.h" // device notification
2262 #include "malloc.h"
2263
2264+#if defined(__MINGW32__)
2265+#include <algorithm>
2266+#endif
2267 #ifdef MS_WINCE
2268 #include "winbase.h"
2269 #define IS_INTRESOURCE(res) (((DWORD)(res) & 0xffff0000) == 0)
2270@@ -640,7 +643,11 @@ typedef int UINT;
2271 // @object TRACKMOUSEEVENT|A tuple of (dwFlags, hwndTrack, dwHoverTime)
2272 %typemap(python,in) TRACKMOUSEEVENT *INPUT(TRACKMOUSEEVENT e){
2273 PyObject *obhwnd;
2274+#if defined(__MINGW32__)
2275+ e.cbSize = sizeof(e);
2276+#else
2277 e.cbSize = sizeof e;
2278+#endif
2279 if (PyTuple_Check($source)) {
2280 if (PyArg_ParseTuple($source, "lOl", &e.dwFlags, &obhwnd, &e.dwHoverTime) == 0) {
2281 return PyErr_Format(PyExc_TypeError, "%s: a TRACKMOUSEEVENT must be a tuple of 3 integers", "$name");
2282@@ -1822,7 +1829,11 @@ PyObject *PyFlashWindowEx(PyObject *self, PyObject *args)
2283 PyObject *ret, *obhwnd;
2284 BOOL rc;
2285 FLASHWINFO f;
2286+#if defined(__MINGW32__)
2287+ f.cbSize = sizeof(f);
2288+#else
2289 f.cbSize = sizeof f;
2290+#endif
2291 // @pyparm <o PyHANDLE>|hwnd||Handle to a window
2292 // @pyparm int|dwFlags||Combination of win32con.FLASHW_* flags
2293 // @pyparm int|uCount||Nbr of times to flash
2294@@ -3802,7 +3813,11 @@ static PyObject *PyExtractIconEx(PyObject *self, PyObject *args)
2295 nicons_got = 1;
2296 #endif
2297 // Asking for 1 always says it got 2!?
2298+#if defined(__MINGW32__)
2299+ nicons = std::min(nicons, nicons_got);
2300+#else
2301 nicons = min(nicons, nicons_got);
2302+#endif
2303 objects_large = PyList_New(nicons);
2304 if (!objects_large) goto done;
2305 objects_small = PyList_New(nicons);
2306@@ -4596,29 +4611,49 @@ BOOL GetOpenFileName(OPENFILENAME *INPUT);
2307 %typemap (python, in) MENUITEMINFO *INPUT (Py_ssize_t target_size){
2308 if (0 != PyObject_AsReadBuffer($source, (const void **)&$target, &target_size))
2309 return NULL;
2310+#if defined(__MINGW32__)
2311+ if (sizeof(MENUITEMINFO) != target_size)
2312+ return PyErr_Format(PyExc_TypeError, "Argument must be a %d-byte string/buffer (got %d bytes)", sizeof(MENUITEMINFO), target_size);
2313+#else
2314 if (sizeof MENUITEMINFO != target_size)
2315 return PyErr_Format(PyExc_TypeError, "Argument must be a %d-byte string/buffer (got %d bytes)", sizeof MENUITEMINFO, target_size);
2316+#endif
2317 }
2318
2319 %typemap (python,in) MENUITEMINFO *BOTH(Py_ssize_t target_size) {
2320 if (0 != PyObject_AsWriteBuffer($source, (void **)&$target, &target_size))
2321 return NULL;
2322+#if defined(__MINGW32__)
2323+ if (sizeof(MENUITEMINFO) != target_size)
2324+ return PyErr_Format(PyExc_TypeError, "Argument must be a %d-byte buffer (got %d bytes)", sizeof(MENUITEMINFO), target_size);
2325+#else
2326 if (sizeof MENUITEMINFO != target_size)
2327 return PyErr_Format(PyExc_TypeError, "Argument must be a %d-byte buffer (got %d bytes)", sizeof MENUITEMINFO, target_size);
2328+#endif
2329 }
2330
2331 %typemap (python, in) MENUINFO *INPUT (Py_ssize_t target_size){
2332 if (0 != PyObject_AsReadBuffer($source, (const void **)&$target, &target_size))
2333 return NULL;
2334+#if defined(__MINGW32__)
2335+ if (sizeof(MENUINFO) != target_size)
2336+ return PyErr_Format(PyExc_TypeError, "Argument must be a %d-byte string/buffer (got %d bytes)", sizeof(MENUINFO), target_size);
2337+#else
2338 if (sizeof MENUINFO != target_size)
2339 return PyErr_Format(PyExc_TypeError, "Argument must be a %d-byte string/buffer (got %d bytes)", sizeof MENUINFO, target_size);
2340+#endif
2341 }
2342
2343 %typemap (python,in) MENUINFO *BOTH(Py_ssize_t target_size) {
2344 if (0 != PyObject_AsWriteBuffer($source, (void **)&$target, &target_size))
2345 return NULL;
2346+#if defined(__MINGW32__)
2347+ if (sizeof(MENUINFO) != target_size)
2348+ return PyErr_Format(PyExc_TypeError, "Argument must be a %d-byte buffer (got %d bytes)", sizeof(MENUINFO), target_size);
2349+#else
2350 if (sizeof MENUINFO != target_size)
2351 return PyErr_Format(PyExc_TypeError, "Argument must be a %d-byte buffer (got %d bytes)", sizeof MENUINFO, target_size);
2352+#endif
2353 }
2354
2355 // @pyswig |InsertMenuItem|Inserts a menu item
2356@@ -4750,8 +4785,13 @@ PyObject *PySetMenuInfo(PyObject *self, PyObject *args)
2357
2358 if (0 != PyObject_AsReadBuffer(obInfo, (const void **)&pInfo, &cbInfo))
2359 return NULL;
2360+#if defined(__MINGW32__)
2361+ if (sizeof(MENUINFO) != cbInfo)
2362+ return PyErr_Format(PyExc_TypeError, "Argument must be a %d byte string/buffer (got %d bytes)", sizeof(MENUINFO), cbInfo);
2363+#else
2364 if (sizeof MENUINFO != cbInfo)
2365 return PyErr_Format(PyExc_TypeError, "Argument must be a %d byte string/buffer (got %d bytes)", sizeof MENUINFO, cbInfo);
2366+#endif
2367
2368 Py_BEGIN_ALLOW_THREADS
2369 result = (*pfnSetMenuInfo)(hmenu, pInfo);
2370@@ -4787,8 +4827,13 @@ PyObject *PyGetMenuInfo(PyObject *self, PyObject *args)
2371
2372 if (0 != PyObject_AsWriteBuffer(obInfo, (void **)&pInfo, &cbInfo))
2373 return NULL;
2374+#if defined(__MINGW32__)
2375+ if (sizeof(MENUINFO) != cbInfo)
2376+ return PyErr_Format(PyExc_TypeError, "Argument must be a %d byte buffer (got %d bytes)", sizeof(MENUINFO), cbInfo);
2377+#else
2378 if (sizeof MENUINFO != cbInfo)
2379 return PyErr_Format(PyExc_TypeError, "Argument must be a %d byte buffer (got %d bytes)", sizeof MENUINFO, cbInfo);
2380+#endif
2381
2382 Py_BEGIN_ALLOW_THREADS
2383 result = (*pfnGetMenuInfo)(hmenu, pInfo);
2384@@ -6005,7 +6050,11 @@ PyGetClassName(PyObject *self, PyObject *args)
2385 if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd))
2386 return NULL;
2387 // dont bother with lock - no callback possible.
2388+#if defined(__MINGW32__)
2389+ int nchars = GetClassName(hwnd, buf, sizeof(buf)/sizeof(buf[0]));
2390+#else
2391 int nchars = GetClassName(hwnd, buf, sizeof buf/sizeof buf[0]);
2392+#endif
2393 if (nchars==0)
2394 return PyWin_SetAPIError("GetClassName");
2395 return PyWinObject_FromTCHAR(buf, nchars);
2396@@ -6370,7 +6419,11 @@ BOOL PyParse_OPENFILENAMEW_Args(PyObject *args, PyObject *kwargs, OPENFILENAMEW
2397 // lpstrFile buffer receives full path and possibly multiple file names, allocate extra space
2398 if (!PyWinObject_AsWCHAR(obFile, &initfile, TRUE, &initfilechars))
2399 goto done;
2400+#if defined(__MINGW32__)
2401+ pofn->nMaxFile=std::max(pofn->nMaxFile, initfilechars+1);
2402+#else
2403 pofn->nMaxFile=max(pofn->nMaxFile, initfilechars+1);
2404+#endif
2405 bufsize=pofn->nMaxFile*sizeof(WCHAR);
2406 pofn->lpstrFile=(LPWSTR)malloc(bufsize);
2407 if (pofn->lpstrFile==NULL){
2408@@ -7506,13 +7559,13 @@ PyObject *PyRegisterDeviceNotification(PyObject *self, PyObject *args)
2409 "structure says it has %d bytes, but %d was provided",
2410 (int)struct_bytes, (int)nbytes);
2411 // @pyseeapi RegisterDeviceNotification
2412- HDEVNOTIFY not;
2413+ HDEVNOTIFY notify;
2414 Py_BEGIN_ALLOW_THREADS
2415- not = RegisterDeviceNotification(handle, (void *)filter, flags);
2416+ notify = RegisterDeviceNotification(handle, (void *)filter, flags);
2417 Py_END_ALLOW_THREADS
2418- if (not == NULL)
2419+ if (notify == NULL)
2420 return PyWin_SetAPIError("RegisterDeviceNotification");
2421- return PyWinObject_FromHDEVNOTIFY(not);
2422+ return PyWinObject_FromHDEVNOTIFY(notify);
2423 }
2424 %}
2425 %native(RegisterDeviceNotification) PyRegisterDeviceNotification;
2426diff --git a/win32/src/win32inet.i b/win32/src/win32inet.i
2427index 92d7462..16a8912 100644
2428--- a/win32/src/win32inet.i
2429+++ b/win32/src/win32inet.i
2430@@ -15,6 +15,9 @@
2431 %{
2432 #undef PyHANDLE // undef earlier define, so we are back to the class.
2433 #include "pywinobjects.h"
2434+#if defined(__MINGW32__)
2435+#include <algorithm>
2436+#endif
2437
2438 void CALLBACK PyHINTERNET_StatusChange(
2439 HINTERNET hInternet,
2440@@ -953,8 +956,10 @@ PyObject *PyInternetQueryOption(PyObject *self, PyObject *args)
2441 case INTERNET_OPTION_RECEIVE_TIMEOUT: // @flag INTERNET_OPTION_RECEIVE_TIMEOUT|Int - timeout in millseconds
2442 // @flag INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT|Int - timeout in millseconds
2443 case INTERNET_OPTION_CODEPAGE: // @flag INTERNET_OPTION_CODEPAGE|Int - Codepage of host part of URL
2444+#if !defined(__MINGW32__)
2445 case INTERNET_OPTION_CODEPAGE_PATH: // @flag INTERNET_OPTION_CODEPAGE_PATH|Int - Codepage for URL
2446 case INTERNET_OPTION_CODEPAGE_EXTRA: // @flag INTERNET_OPTION_CODEPAGE_EXTRA|Int - Codepage for path part of URL
2447+#endif
2448 case INTERNET_OPTION_CONNECT_RETRIES: // @flag INTERNET_OPTION_CONNECT_RETRIES|Int - Number of time to try to reconnect to host
2449 case INTERNET_OPTION_CONNECT_TIMEOUT: // @flag INTERNET_OPTION_CONNECT_TIMEOUT|Int - Connection timeout in milliseconds
2450 case INTERNET_OPTION_CONNECTED_STATE: // @flag INTERNET_OPTION_CONNECTED_STATE|Int - Connection state, INTERNET_STATE_*
2451@@ -962,7 +967,9 @@ PyObject *PyInternetQueryOption(PyObject *self, PyObject *args)
2452 case INTERNET_OPTION_ERROR_MASK: // @flag INTERNET_OPTION_ERROR_MASK|Int, combination of INTERNET_ERROR_MASK_*
2453 case INTERNET_OPTION_EXTENDED_ERROR: // @flag INTERNET_OPTION_EXTENDED_ERROR|Int, ERROR_INTERNET_*
2454 case INTERNET_OPTION_FROM_CACHE_TIMEOUT: // @flag INTERNET_OPTION_FROM_CACHE_TIMEOUT|Int - Timeout in ms before cached copy is used
2455+#if !defined(__MINGW32__)
2456 case INTERNET_OPTION_IDN: // @flag INTERNET_OPTION_IDN|Int, INTERNET_FLAG_IDN_*
2457+#endif
2458 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER: // @flag INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER|Int
2459 case INTERNET_OPTION_MAX_CONNS_PER_SERVER: // @flag INTERNET_OPTION_MAX_CONNS_PER_SERVER|Int
2460 case INTERNET_OPTION_READ_BUFFER_SIZE: // @flag INTERNET_OPTION_READ_BUFFER_SIZE|Int
2461@@ -974,7 +981,9 @@ PyObject *PyInternetQueryOption(PyObject *self, PyObject *args)
2462 ret=PyLong_FromUnsignedLong(*(unsigned long *)buf);
2463 break;
2464 case INTERNET_OPTION_BYPASS_EDITED_ENTRY: // @flag INTERNET_OPTION_BYPASS_EDITED_ENTRY|Boolean
2465+#if !defined(__MINGW32__)
2466 case INTERNET_OPTION_HTTP_DECODING: // @flag INTERNET_OPTION_HTTP_DECODING|Boolean
2467+#endif
2468 case INTERNET_OPTION_IGNORE_OFFLINE: // @flag INTERNET_OPTION_IGNORE_OFFLINE|Boolean
2469 ret=PyBool_FromLong(*(BOOL *)buf);
2470 break;
2471@@ -1157,14 +1166,18 @@ PyObject *PyInternetSetOption(PyObject *self, PyObject *args)
2472 case INTERNET_OPTION_RECEIVE_TIMEOUT: // @flag INTERNET_OPTION_RECEIVE_TIMEOUT|Int - timeout in millseconds
2473 // @flag INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT|Int - timeout in millseconds
2474 case INTERNET_OPTION_CODEPAGE: // @flag INTERNET_OPTION_CODEPAGE|Int - Codepage of host part of URL
2475+#if !defined(__MINGW32__)
2476 case INTERNET_OPTION_CODEPAGE_PATH: // @flag INTERNET_OPTION_CODEPAGE_PATH|Codepage for URL
2477 case INTERNET_OPTION_CODEPAGE_EXTRA: // @flag INTERNET_OPTION_CODEPAGE_EXTRA|Int - Codepage for path part of URL
2478+#endif
2479 case INTERNET_OPTION_CONNECT_RETRIES: // @flag INTERNET_OPTION_CONNECT_RETRIES|Int - Number of time to try to reconnect to host
2480 case INTERNET_OPTION_CONNECT_TIMEOUT: // @flag INTERNET_OPTION_CONNECT_TIMEOUT|Int - Connection timeout in milliseconds
2481 case INTERNET_OPTION_CONNECTED_STATE: // @flag INTERNET_OPTION_CONNECTED_STATE|Int - Connection state, INTERNET_STATE_*
2482 case INTERNET_OPTION_ERROR_MASK: // @flag INTERNET_OPTION_ERROR_MASK|Int, combination of INTERNET_ERROR_MASK_*
2483 case INTERNET_OPTION_FROM_CACHE_TIMEOUT: // @flag INTERNET_OPTION_FROM_CACHE_TIMEOUT|Int - Timeout in ms before cached copy is used
2484+#if !defined(__MINGW32__)
2485 case INTERNET_OPTION_IDN: // @flag INTERNET_OPTION_IDN|Int, INTERNET_FLAG_IDN_*
2486+#endif
2487 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER: // @flag INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER|Int
2488 case INTERNET_OPTION_MAX_CONNS_PER_SERVER: // @flag INTERNET_OPTION_MAX_CONNS_PER_SERVER|Int
2489 case INTERNET_OPTION_READ_BUFFER_SIZE: // @flag INTERNET_OPTION_READ_BUFFER_SIZE|Int
2490@@ -1189,7 +1202,9 @@ PyObject *PyInternetSetOption(PyObject *self, PyObject *args)
2491 }
2492 break;
2493 case INTERNET_OPTION_BYPASS_EDITED_ENTRY: // @flag INTERNET_OPTION_BYPASS_EDITED_ENTRY|Boolean
2494+#if !defined(__MINGW32__)
2495 case INTERNET_OPTION_HTTP_DECODING: // @flag INTERNET_OPTION_HTTP_DECODING|Boolean
2496+#endif
2497 case INTERNET_OPTION_IGNORE_OFFLINE: // @flag INTERNET_OPTION_IGNORE_OFFLINE|Boolean
2498 bufsize=sizeof(BOOL);
2499 buf=malloc(bufsize);
2500@@ -1835,7 +1850,11 @@ BOOL PyWinObject_AsINTERNET_CACHE_GROUP_INFO(PyObject *ob, INTERNET_CACHE_GROUP_
2501 }
2502 }
2503 if (bsuccess && GroupName)
2504+#if defined(__MINGW32__)
2505+ _tcsncpy(GroupInfo->szGroupName, GroupName, std::min(namelen, (DWORD)GROUPNAME_MAX_LENGTH));
2506+#else
2507 _tcsncpy(GroupInfo->szGroupName, GroupName, min(namelen, GROUPNAME_MAX_LENGTH));
2508+#endif
2509 Py_DECREF(dummy_tuple);
2510 PyWinObject_FreeTCHAR(GroupName);
2511 if (OwnerStorage)
2512diff --git a/win32/src/win32net/win32net.h b/win32/src/win32net/win32net.h
2513index ae7c690..c961c18 100644
2514--- a/win32/src/win32net/win32net.h
2515+++ b/win32/src/win32net/win32net.h
2516@@ -62,15 +62,27 @@ PyObject *PyDoGroupDelMembers(PyObject *self, PyObject *args);
2517
2518 #if WINVER >= 0x0500
2519 typedef NET_API_STATUS (NET_API_FUNCTION *NetValidateNamefunc)(LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, NETSETUP_NAME_TYPE);
2520-extern NetValidateNamefunc pfnNetValidateName;
2521+extern
2522+#if defined(__MINGW32__)
2523+"C"
2524+#endif
2525+NetValidateNamefunc pfnNetValidateName;
2526
2527 typedef NET_API_STATUS (NET_API_FUNCTION *NetGetJoinInformationfunc)(LPCWSTR, LPWSTR *, PNETSETUP_JOIN_STATUS);
2528 extern NetGetJoinInformationfunc pfnNetGetJoinInformation;
2529
2530 typedef NET_API_STATUS (NET_API_FUNCTION *NetValidatePasswordPolicyfunc)(LPCWSTR, LPVOID, NET_VALIDATE_PASSWORD_TYPE, LPVOID, LPVOID *);
2531-extern NetValidatePasswordPolicyfunc pfnNetValidatePasswordPolicy;
2532+extern
2533+#if defined(__MINGW32__)
2534+"C"
2535+#endif
2536+NetValidatePasswordPolicyfunc pfnNetValidatePasswordPolicy;
2537
2538 typedef NET_API_STATUS (NET_API_FUNCTION *NetValidatePasswordPolicyFreefunc)(LPVOID *);
2539-extern NetValidatePasswordPolicyFreefunc pfnNetValidatePasswordPolicyFree;
2540+extern
2541+#if defined(__MINGW32__)
2542+"C"
2543+#endif
2544+NetValidatePasswordPolicyFreefunc pfnNetValidatePasswordPolicyFree;
2545
2546 #endif // WINVER
2547diff --git a/win32/src/win32pdhmodule.cpp b/win32/src/win32pdhmodule.cpp
2548index 94c4ed1..533dad7 100644
2549--- a/win32/src/win32pdhmodule.cpp
2550+++ b/win32/src/win32pdhmodule.cpp
2551@@ -15,6 +15,10 @@ generates Windows .hlp files.
2552 #include "pdh.h"
2553 #include "pdhmsg.h"
2554
2555+#if defined(__MINGW32__)
2556+#include <algorithm>
2557+#endif
2558+
2559 /*
2560 According to MSDN, Pdh calls are thread safe, although there was a bug
2561 in Win2k that might make it appear to not be. Plus, the PyW32* macros
2562@@ -1013,12 +1017,21 @@ PDH_STATUS __stdcall PyCounterPathCallback(DWORD_PTR dwArg)
2563 return rc;
2564 }
2565
2566+#if defined(__MINGW32__)
2567+#define SET_BOOL(r, i) { \
2568+ if (i<seqLen){ \
2569+ PyObject *subItem = PyTuple_GET_ITEM(flags_tuple, i); \
2570+ myCfg.cfg. r = PyObject_IsTrue(subItem); \
2571+ } \
2572+}
2573+#else
2574 #define SET_BOOL(r, i) { \
2575 if (i<seqLen){ \
2576 PyObject *subItem = PyTuple_GET_ITEM(flags_tuple, i); \
2577 myCfg.cfg.##r = PyObject_IsTrue(subItem); \
2578 } \
2579 }
2580+#endif
2581
2582 // @pymethod string|win32pdh|BrowseCounters|Displays the counter browsing dialog box so that the user can select the counters to be returned to the caller.
2583 static PyObject *PyBrowseCounters(PyObject *self, PyObject *args, PyObject *kwargs)
2584@@ -1082,7 +1095,11 @@ static PyObject *PyBrowseCounters(PyObject *self, PyObject *args, PyObject *kwar
2585 // Initialize the return buffer if starting path is passed in. (bInitializePath will also be set)
2586 if (!PyWinObject_AsTCHAR(obInitialPath, &InitialPath, TRUE, &cchInitialPath))
2587 return NULL; // Last exit without cleanup
2588+#if defined(__MINGW32__)
2589+ myCfg.cfg.cchReturnPathLength = std::max(cchInitialPath+1, 1024UL);
2590+#else
2591 myCfg.cfg.cchReturnPathLength = max(cchInitialPath+1, 1024);
2592+#endif
2593 myCfg.cfg.szReturnPathBuffer = (TCHAR *)malloc(myCfg.cfg.cchReturnPathLength * sizeof(TCHAR));
2594 if (myCfg.cfg.szReturnPathBuffer == NULL){
2595 PyErr_NoMemory();
2596diff --git a/win32/src/win32service.i b/win32/src/win32service.i
2597index 11a4a23..fab8092 100644
2598--- a/win32/src/win32service.i
2599+++ b/win32/src/win32service.i
2600@@ -1818,7 +1818,6 @@ PyObject *PyQueryServiceConfig2(PyObject *self, PyObject *args)
2601 #define SERVICE_CONTROL_HARDWAREPROFILECHANGE SERVICE_CONTROL_HARDWAREPROFILECHANGE
2602 #define SERVICE_CONTROL_POWEREVENT SERVICE_CONTROL_POWEREVENT
2603 #define SERVICE_CONTROL_SESSIONCHANGE SERVICE_CONTROL_SESSIONCHANGE
2604-#define SERVICE_CONTROL_PRESHUTDOWN SERVICE_CONTROL_PRESHUTDOWN
2605
2606
2607 #define SC_MANAGER_ALL_ACCESS SC_MANAGER_ALL_ACCESS
2608@@ -1875,7 +1874,6 @@ PyObject *PyQueryServiceConfig2(PyObject *self, PyObject *args)
2609 #define SERVICE_ACCEPT_HARDWAREPROFILECHANGE SERVICE_ACCEPT_HARDWAREPROFILECHANGE
2610 #define SERVICE_ACCEPT_POWEREVENT SERVICE_ACCEPT_POWEREVENT
2611 #define SERVICE_ACCEPT_SESSIONCHANGE SERVICE_ACCEPT_SESSIONCHANGE
2612-#define SERVICE_ACCEPT_PRESHUTDOWN SERVICE_ACCEPT_PRESHUTDOWN
2613
2614 //#define SERVICE_ERROR_IGNORER_IGNORE SERVICE_ERROR_IGNORER_IGNORE
2615 #define SERVICE_BOOT_START SERVICE_BOOT_START
2616diff --git a/win32/src/win32trace.cpp b/win32/src/win32trace.cpp
2617index 2237094..60e7c83 100644
2618--- a/win32/src/win32trace.cpp
2619+++ b/win32/src/win32trace.cpp
2620@@ -35,6 +35,9 @@ See - I told you the implementation was simple :-)
2621
2622
2623
2624+#if defined(__MINGW32__)
2625+#include <algorithm>
2626+#endif
2627
2628 const unsigned long BUFFER_SIZE = 0x20000; // Includes size integer.
2629 const TCHAR *MAP_OBJECT_NAME = _T("Global\\PythonTraceOutputMapping");
2630@@ -341,7 +344,11 @@ BOOL PyTraceObject::WriteData(const char *data, unsigned len)
2631 Py_BEGIN_ALLOW_THREADS
2632 const char *data_this = data;
2633 while (len) {
2634+#if defined(__MINGW32__)
2635+ unsigned len_this = std::min(static_cast<unsigned long>(len), BUFFER_SIZE/2);
2636+#else
2637 unsigned len_this = min(len, BUFFER_SIZE/2);
2638+#endif
2639 BOOL ok = GetMyMutex();
2640 if (ok) {
2641 // must use types with identical size on win32 and win64
Note: See TracBrowser for help on using the repository browser.