Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C+中包括Lua+;DLL使其与C#不兼容? 我试图用WPF来制作一个UI,它使用WPF调用非托管C++。我尝试过使用平台调用方法,也只是通过用/CLR选项编译C++代码,这是比较好的。这两种方法都很好,直到C++ +DLL使用包含标准Lua头文件的任何代码。当然,C++代码编译为A.exe时也很好,并且当.dll被另一C++项目调用时。p>_C#_C++_Dll_Lua_Pinvoke - Fatal编程技术网

在C+中包括Lua+;DLL使其与C#不兼容? 我试图用WPF来制作一个UI,它使用WPF调用非托管C++。我尝试过使用平台调用方法,也只是通过用/CLR选项编译C++代码,这是比较好的。这两种方法都很好,直到C++ +DLL使用包含标准Lua头文件的任何代码。当然,C++代码编译为A.exe时也很好,并且当.dll被另一C++项目调用时。p>

在C+中包括Lua+;DLL使其与C#不兼容? 我试图用WPF来制作一个UI,它使用WPF调用非托管C++。我尝试过使用平台调用方法,也只是通过用/CLR选项编译C++代码,这是比较好的。这两种方法都很好,直到C++ +DLL使用包含标准Lua头文件的任何代码。当然,C++代码编译为A.exe时也很好,并且当.dll被另一C++项目调用时。p>,c#,c++,dll,lua,pinvoke,C#,C++,Dll,Lua,Pinvoke,仅用于测试,C#端类似于使用PInvoke时的第一个代码块: namespace ThermoSIM_UI { public class CppInterface { [DllImport("ThermoSIMDLL_1.2.dll")] public static extern int TestPassString(); public CppInterface() { TestPassSt

仅用于测试,C#端类似于使用PInvoke时的第一个代码块:

namespace ThermoSIM_UI
{
    public class CppInterface
    {
        [DllImport("ThermoSIMDLL_1.2.dll")]
        public static extern int TestPassString();

        public CppInterface()
        {
            TestPassString();
        }
    }
}    

和C++ +DLL有这样的标题:

#ifdef THERMOSIMDLL_EXPORTS
#define THERMOSIMDLL_API __declspec(dllexport) 
#else
#define THERMOSIMDLL_API __declspec(dllimport) 
#endif

extern "C"
{
    THERMOSIMDLL_API int TestPassString();
}

正如我所说的,这是工作的,直到我在C++中有一个文件。使用LUA的DLL包括:

extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "luajit.h"
}
啊,C#错误是:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: The invocation of the constructor on type 'ThermoSIM_UI.MainWindow' that matches the specified binding constraints threw an exception.
A first chance exception of type 'System.BadImageFormatException' occurred in ThermoSIM_UI.exe
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type 'System.Xaml.XamlObjectWriterException' occurred in System.Xaml.dll
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: The invocation of the constructor on type 'ThermoSIM_UI.MainWindow' that matches the specified binding constraints threw an exception.
The program '[8048] ThermoSIM_UI.vshost.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).
此外,在输出窗口中还有以下内容:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: The invocation of the constructor on type 'ThermoSIM_UI.MainWindow' that matches the specified binding constraints threw an exception.
A first chance exception of type 'System.BadImageFormatException' occurred in ThermoSIM_UI.exe
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type 'System.Xaml.XamlObjectWriterException' occurred in System.Xaml.dll
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: The invocation of the constructor on type 'ThermoSIM_UI.MainWindow' that matches the specified binding constraints threw an exception.
The program '[8048] ThermoSIM_UI.vshost.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).
BadImageFormatException似乎与具有不同构建配置的.dll有关,例如混合使用x64和x86或其他内容。不管怎样,我还没弄明白。


有没有人遇到过这种情况,或者知道为什么这个.dll与C#不兼容?

遵循@scholli的建议,成功了:如果我自己用Visual Studio构建Lua,它就会工作。这篇文章很有帮助,只做了一点修改:

  • 下载Lua文件Lua.org/download.html
  • 创建了一个创建库的新Visual Studio项目。我制作了一个静态库
  • 删除解释器文件lua.c,因为它与luac.c冲突
  • 编译为与我的C++ DLL相同的设置,即x64,版本。李>
    <>现在,C++项目可以调用C++ DLL。< /p>你在“任何CPU”编译吗?不,我正在编译C 64和C++的X64,你只是添加了.h,停止工作,或者使用了来自Lua的任何方法?你是用与C++的DLL相同的配置设置来构建Lua吗?只是把头文件包含到.CPP文件中,然后停止工作。也许Scholli的问题是去哪里看。我为x64构建了LuaJIT,但它不像其他项目那样是通过VS实现的。我试着从这里使用预构建的x64二进制文件,运气不好。我不知道如何从VS构建lua库。你应该接受你自己的答案,这样它就可以接近了。谢谢,它不会让我再等10个小时。谢谢你的帮助,我原以为我有一个x64版本的Lua它会工作。但这是一个棘手的错误,因为它没有那么冗长。