Correct Windows unicode build issues.
This commit is contained in:
		@@ -89,39 +89,69 @@ namespace chaiscript
 | 
			
		||||
 | 
			
		||||
#ifdef WIN32
 | 
			
		||||
 | 
			
		||||
    std::string GetErrorMessage(DWORD err)
 | 
			
		||||
    {
 | 
			
		||||
        LPSTR lpMsgBuf = 0;
 | 
			
		||||
 | 
			
		||||
        FormatMessage(
 | 
			
		||||
            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
 | 
			
		||||
            FORMAT_MESSAGE_FROM_SYSTEM |
 | 
			
		||||
            FORMAT_MESSAGE_IGNORE_INSERTS,
 | 
			
		||||
            NULL,
 | 
			
		||||
            err,
 | 
			
		||||
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 | 
			
		||||
            (LPSTR)&lpMsgBuf,
 | 
			
		||||
            0, NULL );
 | 
			
		||||
        
 | 
			
		||||
        std::string retval;
 | 
			
		||||
 | 
			
		||||
        if (lpMsgBuf)
 | 
			
		||||
        {
 | 
			
		||||
          retval = lpMsgBuf;
 | 
			
		||||
        } else {
 | 
			
		||||
          retval = "Unknown error occured";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        LocalFree(lpMsgBuf);
 | 
			
		||||
        return retval;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    struct Loadable_Module
 | 
			
		||||
    {
 | 
			
		||||
        template<typename T>
 | 
			
		||||
        static std::wstring towstring(const T &str) 
 | 
			
		||||
        {
 | 
			
		||||
            return std::wstring(str.begin(), str.end());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        template<typename T>
 | 
			
		||||
        static std::string tostring(const T &str)
 | 
			
		||||
        {
 | 
			
		||||
            return std::string(str.begin(), str.end());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#ifdef _UNICODE
 | 
			
		||||
        template<typename T>
 | 
			
		||||
        static std::wstring toproperstring(const T &str)
 | 
			
		||||
        {
 | 
			
		||||
            return towstring(str);
 | 
			
		||||
        }
 | 
			
		||||
#else
 | 
			
		||||
        template<typename T>
 | 
			
		||||
        static std::string toproperstring(const T &str)
 | 
			
		||||
        {
 | 
			
		||||
            return tostring(str);
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        static std::string GetErrorMessage(DWORD err)
 | 
			
		||||
        {
 | 
			
		||||
#ifdef _UNICODE
 | 
			
		||||
            typedef LPWSTR StringType;
 | 
			
		||||
            std::wstring retval = L"Unknown Error";
 | 
			
		||||
#else
 | 
			
		||||
            typedef LPSTR StringType;
 | 
			
		||||
            std::string retval = "Unknown Error";
 | 
			
		||||
#endif
 | 
			
		||||
            StringType lpMsgBuf = 0;
 | 
			
		||||
 | 
			
		||||
            FormatMessage(
 | 
			
		||||
                FORMAT_MESSAGE_ALLOCATE_BUFFER | 
 | 
			
		||||
                FORMAT_MESSAGE_FROM_SYSTEM |
 | 
			
		||||
                FORMAT_MESSAGE_IGNORE_INSERTS,
 | 
			
		||||
                NULL,
 | 
			
		||||
                err,
 | 
			
		||||
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 | 
			
		||||
                (StringType)&lpMsgBuf,
 | 
			
		||||
                0, NULL );        
 | 
			
		||||
 | 
			
		||||
            if (lpMsgBuf)
 | 
			
		||||
            {
 | 
			
		||||
              retval = lpMsgBuf;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            LocalFree(lpMsgBuf);
 | 
			
		||||
            return tostring(retval);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        struct DLModule
 | 
			
		||||
        {
 | 
			
		||||
           DLModule(const std::string &t_filename)
 | 
			
		||||
             : m_data(LoadLibrary(t_filename.c_str()))
 | 
			
		||||
             : m_data(LoadLibrary(toproperstring(t_filename).c_str()))
 | 
			
		||||
           {
 | 
			
		||||
              if (!m_data)
 | 
			
		||||
              {
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,7 @@
 | 
			
		||||
			<Tool
 | 
			
		||||
				Name="VCCLCompilerTool"
 | 
			
		||||
				Optimization="0"
 | 
			
		||||
				AdditionalIncludeDirectories="C:\Programming\chaiscript\trunk\include"
 | 
			
		||||
				AdditionalIncludeDirectories=""$(ProjectDir)\..\..\include""
 | 
			
		||||
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
 | 
			
		||||
				MinimalRebuild="true"
 | 
			
		||||
				BasicRuntimeChecks="3"
 | 
			
		||||
@@ -117,6 +117,7 @@
 | 
			
		||||
				Name="VCCLCompilerTool"
 | 
			
		||||
				Optimization="2"
 | 
			
		||||
				EnableIntrinsicFunctions="true"
 | 
			
		||||
				AdditionalIncludeDirectories=""$(ProjectDir)\..\..\include""
 | 
			
		||||
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
 | 
			
		||||
				RuntimeLibrary="2"
 | 
			
		||||
				EnableFunctionLevelLinking="true"
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@
 | 
			
		||||
			ConfigurationType="1"
 | 
			
		||||
			InheritedPropertySheets=".\Boost.vsprops"
 | 
			
		||||
			UseOfMFC="2"
 | 
			
		||||
			CharacterSet="0"
 | 
			
		||||
			CharacterSet="1"
 | 
			
		||||
			>
 | 
			
		||||
			<Tool
 | 
			
		||||
				Name="VCPreBuildEventTool"
 | 
			
		||||
@@ -100,7 +100,7 @@
 | 
			
		||||
			IntermediateDirectory="$(ConfigurationName)"
 | 
			
		||||
			ConfigurationType="1"
 | 
			
		||||
			InheritedPropertySheets=".\Boost.vsprops"
 | 
			
		||||
			CharacterSet="0"
 | 
			
		||||
			CharacterSet="1"
 | 
			
		||||
			WholeProgramOptimization="1"
 | 
			
		||||
			>
 | 
			
		||||
			<Tool
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,7 @@
 | 
			
		||||
			<Tool
 | 
			
		||||
				Name="VCCLCompilerTool"
 | 
			
		||||
				Optimization="0"
 | 
			
		||||
				AdditionalIncludeDirectories="C:\Programming\chaiscript\trunk\include"
 | 
			
		||||
				AdditionalIncludeDirectories=""$(ProjectDir)\..\..\include""
 | 
			
		||||
				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;TEST_MODULE_EXPORTS"
 | 
			
		||||
				MinimalRebuild="true"
 | 
			
		||||
				BasicRuntimeChecks="3"
 | 
			
		||||
@@ -118,6 +118,7 @@
 | 
			
		||||
				Name="VCCLCompilerTool"
 | 
			
		||||
				Optimization="2"
 | 
			
		||||
				EnableIntrinsicFunctions="true"
 | 
			
		||||
				AdditionalIncludeDirectories=""$(ProjectDir)\..\..\include""
 | 
			
		||||
				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;TEST_MODULE_EXPORTS"
 | 
			
		||||
				RuntimeLibrary="2"
 | 
			
		||||
				EnableFunctionLevelLinking="true"
 | 
			
		||||
 
 | 
			
		||||
@@ -149,7 +149,7 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
  //Dynamic objects test
 | 
			
		||||
  chai.add(chaiscript::Proxy_Function(new Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world");
 | 
			
		||||
  chai.add(chaiscript::Proxy_Function(new Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType");
 | 
			
		||||
  chai.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&dynamic_object_attribute, "TestType", "attr", _1))), "attr");
 | 
			
		||||
  chai.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr");
 | 
			
		||||
 | 
			
		||||
  chai.eval("var x = TestType()");
 | 
			
		||||
  chai.eval("x.attr = \"hi\"");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user