diff --git a/src/bits.c b/src/bits.c
index 7d81fae..ebe2e30 100644
--- a/src/bits.c
+++ b/src/bits.c
@@ -18,8 +18,12 @@
  * modified by James Mike Dupont
  */
 
-
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#else
+#include "generic.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/src/bits.h b/src/bits.h
index ff066c8..740ac21 100644
--- a/src/bits.h
+++ b/src/bits.h
@@ -29,10 +29,7 @@
 #ifndef BITS_H
 #define BITS_H
 
-#ifndef DWG_H
 #include "dwg.h"
-#endif
-
 #include "common.h"
 
 /**
diff --git a/src/common.c b/src/common.c
index e5a6aa1..7ccf066 100644
--- a/src/common.c
+++ b/src/common.c
@@ -17,9 +17,15 @@
  * modified by Rodrigo Rodrigues da Silva
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#else
+#include "generic.h"
+#endif
+
+#include <stdio.h>
+
 #include "common.h"
-#include "stdio.h"
 
 unsigned char *
 dwg_sentinel(Dwg_Sentinel s)
diff --git a/src/decode.c b/src/decode.c
index 261c086..b01233c 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -18,8 +18,15 @@
  * modified by Till Heuschmann
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#else
+#include "generic.h"
+#endif
+
+#ifdef HAVE_STDBOOL_H
 #include <stdbool.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -237,14 +244,17 @@ static void \
 
 #define DWG_ENTITY_END }
 
-#define DWG_OBJECT(token) static void  dwg_decode_ ## token (Bit_Chain * dat, Dwg_Object * obj) {\
+#define DWG_OBJECT(token)\
+static void  dwg_decode_ ## token (Bit_Chain * dat, Dwg_Object * obj)\
+{\
+  char R2007plus_text_area_is_present = 0;\
   int vcount, rcount, rcount2, rcount3;\
   Dwg_Object_##token *_obj;\
   Dwg_Data* dwg = obj->parent;\
   LOG_INFO("Object " #token ":\n")\
   obj->supertype = DWG_SUPERTYPE_OBJECT;\
-  obj->tio.object = (Dwg_Object_Object*)malloc (sizeof (Dwg_Object_Object));	\
-  obj->tio.object->tio.token = (Dwg_Object_##token * ) calloc (sizeof (Dwg_Object_##token), 1); \
+  obj->tio.object = (Dwg_Object_Object*)malloc (sizeof (Dwg_Object_Object));\
+  obj->tio.object->tio.token = (Dwg_Object_##token * ) calloc (sizeof (Dwg_Object_##token), 1);\
   obj->tio.object->object = obj;\
   if (dwg_decode_object (dat, obj->tio.object)) return;\
   _obj = obj->tio.object->tio.token;\
@@ -2433,7 +2443,7 @@ dwg_decode_xdata(Bit_Chain * dat, int size)
 
 /* OBJECTS *******************************************************************/
 
-#include<dwg.spec>
+#include "dwg.spec"
 
 
 /*--------------------------------------------------------------------------------
diff --git a/src/dwg.c b/src/dwg.c
index d90de82..c97fe2f 100644
--- a/src/dwg.c
+++ b/src/dwg.c
@@ -18,7 +18,12 @@
  * modified by Anderson Pierre Cardoso
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#else
+#include "generic.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/src/dwg.spec b/src/dwg.spec
index c2f3465..bb674ac 100644
--- a/src/dwg.spec
+++ b/src/dwg.spec
@@ -1842,7 +1842,6 @@ DWG_OBJECT_END
 
 /*(57)*/
 DWG_OBJECT(LTYPE);
-  char R2007plus_text_area_is_present = 0;
 
   FIELD(entry_name, TV);
   FIELD(_64_flag, B);
@@ -2780,10 +2779,10 @@ DWG_OBJECT_END
 //pg.150
 DWG_OBJECT(RASTERVARIABLES);
 
-  BITCODE_BL (class_version);
-  BITCODE_BS (display_frame);
-  BITCODE_BS (display_quality);
-  BITCODE_BS (units);
+  FIELD_BL (class_version);
+  FIELD_BS (display_frame);
+  FIELD_BS (display_quality);
+  FIELD_BS (units);
   FIELD_HANDLE (parenthandle, 4);
   REACTORS(4);
   XDICOBJHANDLE(3);
diff --git a/src/encode.c b/src/encode.c
index 42273f3..2eb43a8 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -21,8 +21,15 @@
  * modified by Anderson Pierre Cardoso
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#else
+#include "generic.h"
+#endif
+
+#ifdef HAVE_STDBOOL_H
 #include <stdbool.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -206,10 +213,12 @@ static void dwg_encode_##token (Dwg_Object* obj, Dwg_Entity_##token * _obj, Bit_
 
 #define DWG_ENTITY_END }
 
-#define DWG_OBJECT(token) static void dwg_encode_##token (Dwg_Object* obj, Dwg_Object_##token *_obj, Bit_Chain * dat)\
+#define DWG_OBJECT(token)\
+static void dwg_encode_##token (Dwg_Object* obj, Dwg_Object_##token *_obj, Bit_Chain * dat)\
 {\
+  char R2007plus_text_area_is_present = 0;\
   int vcount, rcount, rcount2, rcount3;\
-	Dwg_Data* dwg = obj->parent;
+  Dwg_Data* dwg = obj->parent;
 
 #define DWG_OBJECT_END }
 
@@ -243,7 +252,8 @@ void
 dwg_encode_handleref(Bit_Chain * dat, Dwg_Object * obj, Dwg_Data* dwg, Dwg_Object_Ref* ref);
 void 
 dwg_encode_handleref_with_code(Bit_Chain * dat, Dwg_Object * obj,Dwg_Data* dwg, Dwg_Object_Ref* ref, int code);
-
+void
+dwg_encode_common_entity_handle_data(Bit_Chain * dat, Dwg_Object * obj);
 
 /*--------------------------------------------------------------------------------
  * Public variables
@@ -696,7 +706,7 @@ dwg_encode_chains(Dwg_Data * dwg, Bit_Chain * dat)
   return 0;
 }
 
-#include<dwg.spec>
+#include "dwg.spec"
 
 static void
 dwg_encode_entity(Dwg_Object * obj, Bit_Chain * dat)
@@ -705,6 +715,7 @@ dwg_encode_entity(Dwg_Object * obj, Bit_Chain * dat)
   unsigned int size;
   unsigned int extended_size;
   int i;
+  Dwg_Object_Entity *ent;
   
   size =  obj->tio.entity->bitsize;
   bit_write_RL(dat, size);
@@ -733,9 +744,10 @@ dwg_encode_entity(Dwg_Object * obj, Bit_Chain * dat)
           bit_advance_position(dat, -(4 * 8 + 1));
         }
      }
-  
-  Dwg_Object_Entity* ent = obj->tio.entity;
-   VERSIONS(R_13,R_14)
+
+  ent = obj->tio.entity;
+
+  VERSIONS(R_13,R_14)
     {
       bit_write_RL(dat, ent->bitsize);
     }
@@ -777,7 +789,6 @@ dwg_encode_entity(Dwg_Object * obj, Bit_Chain * dat)
     {
        bit_write_RC(dat, ent->lineweight);
     }
-
 }
 
 void
@@ -795,7 +806,6 @@ dwg_encode_common_entity_handle_data(Bit_Chain * dat, Dwg_Object * obj)
   _obj = ent;
 
   //#include "common_entity_handle_data.spec"
-  
 }
 
 void
diff --git a/src/generic.h b/src/generic.h
new file mode 100644
index 0000000..9a966df
--- /dev/null
+++ b/src/generic.h
@@ -0,0 +1,25 @@
+/* generic.h
+   LibreDWG - Free DWG read and write library
+   based on LibDWG - Free DWG read-only library
+
+   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009 Felipe Corrêa da Silva Sanches <juca@members.fsf.org>
+   Copyright (C) 2009 Rodrigo Rodrigues da Silva <rodrigopitanga@gmail.com>
+
+   This library is free software, licensed under the terms of the GNU
+   General Public License as published by the Free Software Foundation,
+   either version 3 of the License, or (at your option) any later version.
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   */
+
+#ifndef GENERIC_H
+#define GENERIC_H
+
+#ifdef _MSC_VER
+#undef HAVE_STDBOOL_H
+#define inline __inline
+#endif
+
+#endif
+
diff --git a/src/logging.h b/src/logging.h
index a9b2211..c81b35e 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -46,6 +46,22 @@
 #define HANDLER fprintf
 #define OUTPUT stderr
 
+#ifdef _MSC_VER
+#define LOG(level, ...) \
+          if (DWG_LOGLEVEL >= DWG_LOGLEVEL_##level) { \
+            HANDLER(OUTPUT, __VA_ARGS__); \
+          }
+
+#define LOG_ERROR(...) \
+          if (DWG_LOGLEVEL > DWG_LOGLEVEL_ERROR) { \
+              HANDLER(OUTPUT, "ERROR: "); \
+              LOG(ERROR, __VA_ARGS__) \
+          }
+
+#define LOG_INFO(...) LOG(INFO, __VA_ARGS__)
+#define LOG_TRACE(...) LOG(TRACE, __VA_ARGS__)
+#define LOG_ALL(...) LOG(ALL, __VA_ARGS__)
+#else
 #define LOG(level, args...) \
           if (DWG_LOGLEVEL >= DWG_LOGLEVEL_##level) { \
             HANDLER(OUTPUT, args); \
@@ -60,6 +76,6 @@
 #define LOG_INFO(args...) LOG(INFO, args)
 #define LOG_TRACE(args...) LOG(TRACE, args)
 #define LOG_ALL(args...) LOG(ALL, args)
-
+#endif
 
 #endif //#ifndef LOGGING_H
diff --git a/src/print.c b/src/print.c
index f2384d1..9760b71 100644
--- a/src/print.c
+++ b/src/print.c
@@ -15,7 +15,12 @@
  * written by Rodrigo Rodrigues da Silva
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#else
+#include "generic.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -163,10 +168,10 @@ dwg_print_##token (Bit_Chain * dat, Dwg_Object * obj)\
 
 #define DWG_ENTITY_END }
 
-#define DWG_OBJECT(token) \
-static void \
-dwg_print_ ##token (Bit_Chain * dat, Dwg_Object * obj) \
-{ \
+#define DWG_OBJECT(token)\
+static void dwg_print_ ##token (Bit_Chain * dat, Dwg_Object * obj)\
+{\
+  char R2007plus_text_area_is_present = 0;\
   int vcount, rcount, rcount2, rcount3;\
   Dwg_Object_##token *_obj;\
   LOG_INFO("Object " #token ":\n")\
