--- jmorecfg.h
+++ jmorecfg.h
@@ -243,9 +243,22 @@ typedef unsigned int JDIMENSION;
 /* a function used only in its module: */
 #define LOCAL(type)		static type
 /* a function referenced thru EXTERNs: */
-#define GLOBAL(type)		type
+/*#define GLOBAL(type)		type*/
 /* a reference to a GLOBAL function: */
+/*#define EXTERN(type)		extern type*/
+
+#if (!defined(_MSC_VER) || defined(JPEG_STATIC))
+#define GLOBAL(type)		type
 #define EXTERN(type)		extern type
+#else
+#ifdef JPEG_DLL_EXPORTS
+#define GLOBAL(type)		__declspec(dllexport) type
+#define EXTERN(type)		extern __declspec(dllexport) type
+#else
+#define GLOBAL(type)		__declspec(dllimport) type
+#define EXTERN(type)		extern __declspec(dllimport) type
+#endif
+#endif
 
 
 /* This macro is used to declare a "method", that is, a function pointer.
--- makefile.vc
+++ makefile.vc
@@ -12,7 +12,33 @@
 !include <win32.mak>
 
 # You may want to adjust these compiler options:
-CFLAGS= $(cflags) $(cdebug) $(cvars) -I.
+
+!ifndef DLL
+DLL=0
+!endif
+!ifndef NODEBUG
+NODEBUG=0
+!endif
+
+!if $(NODEBUG) == 1
+DBGEXT=
+!else
+DBGEXT=d
+!endif
+
+!if $(DLL) == 1
+!if $(NODEBUG) == 1
+CFLAGS = -MD -nologo -Ox -DJPEG_DLL_EXPORTS -DNDEBUG -I. -c
+!else
+CFLAGS = -MDd -nologo -Od -RTC1 -DJPEG_DLL_EXPORTS -D_DEBUG -I. -c
+!endif
+!else
+!if $(NODEBUG) == 1
+CFLAGS = -MD -nologo -Ox -DNDEBUG  -DJPEG_STATIC -I. -c 
+!else
+CFLAGS = -MDd -nologo -Od -RTC1 -D_DEBUG  -DJPEG_STATIC -I. -c
+!endif
+!endif
 # Generally, we recommend defining any configuration symbols in jconfig.h,
 # NOT via -D switches here.
 
@@ -42,12 +68,12 @@ LIBSOURCES= jaricom.c jcapimin.c jcapist
         jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \
         jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \
         jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \
-        jquant2.c jutils.c jmemmgr.c
+        jquant2.c jutils.c jmemmgr.c transupp.c
 # memmgr back ends: compile only one of these into a working library
 SYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
 # source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom
 APPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \
-        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \
+        rdcolmap.c rdswitch.c rdppm.c wrppm.c rdgif.c wrgif.c \
         rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c
 SOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)
 # files included by source files
@@ -79,7 +105,7 @@ TESTFILES= testorig.jpg testimg.ppm test
 DISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
         $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)
 # library object files common to compression and decompression
-COMOBJECTS= jaricom.obj jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)
+COMOBJECTS= jaricom.obj jcomapi.obj jutils.obj jerror.obj jmemmgr.obj transupp.obj $(SYSDEPMEM)
 # compression library object files
 CLIBOBJECTS= jcapimin.obj jcapistd.obj jcarith.obj jctrans.obj jcparam.obj \
         jdatadst.obj jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj \
@@ -98,7 +124,7 @@ COBJECTS= cjpeg.obj rdppm.obj rdgif.obj 
         rdswitch.obj cdjpeg.obj
 DOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \
         rdcolmap.obj cdjpeg.obj
-TROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj
+TROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj
 
 # Template command for compiling .c to .obj
 .c.obj:
@@ -107,18 +133,24 @@ TROBJECTS= jpegtran.obj rdswitch.obj cdj
 
 all: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe
 
+!if $(DLL) == 1
+libjpeg.lib: $(LIBOBJECTS)
+	$(RM) libjpeg$(DBGEXT).dll
+	cl -o libjpeg$(DBGEXT).dll $(LIBOBJECTS) /link /DLL
+!else
 libjpeg.lib: $(LIBOBJECTS)
-	$(RM) libjpeg.lib
-	lib -out:libjpeg.lib  $(LIBOBJECTS)
+	$(RM) libjpeg$(DBGEXT).lib
+	lib -out:libjpeg$(DBGEXT).lib  $(LIBOBJECTS)
+!endif
 
 cjpeg.exe: $(COBJECTS) libjpeg.lib
-	$(link) $(LDFLAGS) -out:cjpeg.exe $(COBJECTS) libjpeg.lib $(LDLIBS)
+	$(link) $(LDFLAGS) -out:cjpeg.exe $(COBJECTS) libjpeg$(DBGEXT).lib $(LDLIBS)
 
 djpeg.exe: $(DOBJECTS) libjpeg.lib
-	$(link) $(LDFLAGS) -out:djpeg.exe $(DOBJECTS) libjpeg.lib $(LDLIBS)
+	$(link) $(LDFLAGS) -out:djpeg.exe $(DOBJECTS) libjpeg$(DBGEXT).lib $(LDLIBS)
 
 jpegtran.exe: $(TROBJECTS) libjpeg.lib
-	$(link) $(LDFLAGS) -out:jpegtran.exe $(TROBJECTS) libjpeg.lib $(LDLIBS)
+	$(link) $(LDFLAGS) -out:jpegtran.exe $(TROBJECTS) libjpeg$(DBGEXT).lib $(LDLIBS)
 
 rdjpgcom.exe: rdjpgcom.obj
 	$(link) $(LDFLAGS) -out:rdjpgcom.exe rdjpgcom.obj $(LDLIBS)
@@ -128,9 +160,12 @@ wrjpgcom.exe: wrjpgcom.obj
 
 
 clean:
-	$(RM) *.obj *.exe libjpeg.lib
+	$(RM) *.obj *.exe *.lib *.dll *.exp *.manifest *.pdb jconfig.h
 	$(RM) testout*
 
+jconfig.h: jconfig.vc
+	if not exist jconfig.h copy jconfig.vc jconfig.h
+
 setup-vc6:
 	ren jconfig.vc jconfig.h
 	ren makejdsw.vc6 jpeg.dsw
@@ -171,8 +206,8 @@ setup-v10:
 	ren makewvcx.v10 wrjpgcom.vcxproj
 	ren makewfil.v10 wrjpgcom.vcxproj.filters
 
-test:
-	IF EXIST testout* $(RM) testout*
+test: cjpeg.exe djpeg.exe jpegtran.exe
+	IF EXIST $(RM) testout*
 	.\djpeg -dct int -ppm -outfile testout.ppm  testorig.jpg
 	.\djpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg
 	.\cjpeg -dct int -outfile testout.jpg  testimg.ppm
