Index: main/trunk/greenstone2/common-src/indexers/mg/jni/MGPassesWrapperImpl.c
===================================================================
--- main/trunk/greenstone2/common-src/indexers/mg/jni/MGPassesWrapperImpl.c	(revision 26661)
+++ main/trunk/greenstone2/common-src/indexers/mg/jni/MGPassesWrapperImpl.c	(revision 26662)
@@ -20,4 +20,22 @@
 
 #include <jni.h>
+
+#ifdef __MINGW32__
+
+/* Cross compiling for Windows
+ Want the type definitions in *win32* version of jni_md.h but
+ this then leads to C-mangled style functions which we *don't*
+ want.  The following achieves this */
+
+#undef JNIEXPORT
+#undef JNIIMPORT
+#undef JNICALL
+
+#define JNIEXPORT
+#define JNIIMPORT
+#define JNICALL
+#endif
+
+
 #include <assert.h>
 #include "sysfuncs.h"
Index: main/trunk/greenstone2/common-src/indexers/mg/jni/MGRetrieveWrapperImpl.c
===================================================================
--- main/trunk/greenstone2/common-src/indexers/mg/jni/MGRetrieveWrapperImpl.c	(revision 26661)
+++ main/trunk/greenstone2/common-src/indexers/mg/jni/MGRetrieveWrapperImpl.c	(revision 26662)
@@ -19,6 +19,23 @@
 
 
+#include <jni.h>
+#ifdef __MINGW32__
+
+/* Cross compiling for Windows
+ Want the type definitions in *win32* version of jni_md.h but
+ this then leads to C-mangled style functions which we *don't*
+ want.  The following achieves this */
+
+#undef JNIEXPORT
+#undef JNIIMPORT
+#undef JNICALL
+
+#define JNIEXPORT
+#define JNIIMPORT
+#define JNICALL
+#endif
+
 #include "MGWrapperImpl.h"
-#include <jni.h>
+
 #include "org_greenstone_mg_MGRetrieveWrapper.h"
 
@@ -213,5 +230,5 @@
 					  jstring j_index)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*)(intptr_t) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
 
   /* Get the index name as a C string */
@@ -243,5 +260,5 @@
 					     jlong j_docnum)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*)(intptr_t) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
 
   char* index_path;
Index: main/trunk/greenstone2/common-src/indexers/mg/jni/MGSearchWrapperImpl.c
===================================================================
--- main/trunk/greenstone2/common-src/indexers/mg/jni/MGSearchWrapperImpl.c	(revision 26661)
+++ main/trunk/greenstone2/common-src/indexers/mg/jni/MGSearchWrapperImpl.c	(revision 26662)
@@ -19,6 +19,23 @@
 
 
+#include <jni.h>
+
+#ifdef __MINGW32__
+
+/* Cross compiling for Windows
+   Want the type definitions in *win32* version of jni_md.h but
+   this then leads to C-mangled style functions which we *don't*
+   want.  The following achieves this */
+
+#undef JNIEXPORT
+#undef JNIIMPORT
+#undef JNICALL
+
+#define JNIEXPORT
+#define JNIIMPORT
+#define JNICALL
+#endif
+
 #include "MGWrapperImpl.h"
-#include <jni.h>
 #include "org_greenstone_mg_MGSearchWrapper.h"
 
@@ -252,5 +269,5 @@
 					  jstring j_query)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*) (intptr_t)(*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
 
   char* index_path;
@@ -517,5 +534,5 @@
 					 jboolean j_on)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*)(intptr_t) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
 
   if (j_on) {
@@ -532,5 +549,5 @@
 					 jboolean j_on)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*) (intptr_t)(*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
 
   if (j_on) {
@@ -547,5 +564,5 @@
 					    jint j_max)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*)(intptr_t) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
   data->queryInfo->maxDocs = j_max;
 }
@@ -570,5 +587,5 @@
 						jboolean j_on)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*)(intptr_t) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
   data->queryInfo->needTermFreqs = j_on;
 }
@@ -580,5 +597,5 @@
 					  jstring j_index)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*)(intptr_t) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
 
   /* Get the index name as a C string */
@@ -606,5 +623,5 @@
 					      jint j_mode)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*)(intptr_t) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
   data->defaultBoolCombine = j_mode;
 }
@@ -615,5 +632,5 @@
 Java_org_greenstone_mg_MGSearchWrapper_getQueryParams(JNIEnv *j_env, jobject j_obj)
 {
-  MGWrapperData* data = (MGWrapperData*) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
+  MGWrapperData* data = (MGWrapperData*)(intptr_t) (*j_env)->GetLongField(j_env, j_obj, FID_mg_data);
   char result[512];  /* Assume this is big enough */
 
Index: main/trunk/greenstone2/common-src/indexers/mg/jni/MGWrapperImpl.c
===================================================================
--- main/trunk/greenstone2/common-src/indexers/mg/jni/MGWrapperImpl.c	(revision 26661)
+++ main/trunk/greenstone2/common-src/indexers/mg/jni/MGWrapperImpl.c	(revision 26662)
@@ -18,8 +18,25 @@
  */
 
+#include <jni.h>
+
+#ifdef __MINGW32__
+
+// Cross compiling for Windows
+// Want the type definitions in *win32* version of jni_md.h but
+// this then leads to C-mangled style functions which we *don't*
+// want.  The following achieves this
+
+#undef JNIEXPORT
+#undef JNIIMPORT
+#undef JNICALL
+
+#define JNIEXPORT
+#define JNIIMPORT
+#define JNICALL
+#endif
 
 #include "MGWrapperImpl.h"
-#include <jni.h>
 #include "org_greenstone_mg_MGWrapper.h"
+
 
 #include "backend.h"
