diff --git a/include/hgetopt.h b/include/hgetopt.h
index 9a1c874..900d95c 100644
--- a/include/hgetopt.h
+++ b/include/hgetopt.h
@@ -28,6 +28,8 @@
 #define APPLY_OPTVAR_REPLACEMENTS 1
 #endif
 
+#define HAVE_OPTIND 1
+
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -38,7 +40,7 @@ extern "C" {
    Also, when `ordering' is RETURN_IN_ORDER,
    each non-option ARGV-element is returned here.  */
 
-extern char *optarg;
+extern char __declspec(dllimport) *optarg;
 
 /* Index in ARGV of the next element to be scanned.
    This is used for communication to and from the caller
@@ -52,16 +54,16 @@ extern char *optarg;
    Otherwise, `optind' communicates from one call to the next
    how much of ARGV has been scanned so far.  */
 
-extern int optind;
+extern int __declspec(dllimport) optind;
 
 /* Callers store zero here to inhibit the error message `getopt' prints
    for unrecognized options.  */
 
-extern int opterr;
+extern int __declspec(dllimport) opterr;
 
 /* Set to an option character which was unrecognized.  */
 
-extern int optopt;
+extern int __declspec(dllimport) optopt;
 
 /* Describe the long-named options requested by the application.
    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
diff --git a/src/getopt.c b/src/getopt.c
index 57326ac..1f9d74f 100644
--- a/src/getopt.c
+++ b/src/getopt.c
@@ -32,13 +32,13 @@
 #undef optind
 
 #ifdef HAVE_OPTIND
-extern char* optarg;
+extern char __declspec(dllimport) *optarg;
 #else
 char *optarg = 0;
 #endif
 
 #ifdef HAVE_OPTIND
-extern int optind;
+extern int __declspec(dllimport) optind;
 #else
 int optind = 0;
 #endif
@@ -46,13 +46,13 @@ int optind = 0;
 static char *nextchar;
 
 #ifdef HAVE_OPTIND
-extern int opterr;
+extern int __declspec(dllimport) opterr;
 #else
 int opterr = 1;
 #endif
 
 #ifdef HAVE_OPTIND
-extern int optint;
+extern int __declspec(dllimport) optint;
 #else
 int optopt = '?';
 #endif
diff --git a/src/hexcurse.c b/src/hexcurse.c
index e723ddc..b7d3625 100644
--- a/src/hexcurse.c
+++ b/src/hexcurse.c
@@ -173,8 +173,8 @@ void printDebug(hexList *head, long int loc)
 \********************************************************/
 off_t parseArgs(int argc, char *argv[])
 {
-    extern char *optarg;				/* extern vars for    */
-    extern int optind, /*opterr,*/ optopt;		/* getopt()	      */
+    extern char __declspec(dllimport) *optarg;				/* extern vars for    */
+    extern int __declspec(dllimport) optind, /*opterr,*/ optopt;		/* getopt()	      */
 
     int val;						/* counters, etc.     */
 
