gpt4 book ai didi

c++ - Visual Studio 2012 中的 BadImageFormatExeption

转载 作者:行者123 更新时间:2023-11-30 04:21:18 26 4
gpt4 key购买 nike

我将 cimg( native c++ 头库)包装到 dot net,我测试了它,它在 c++ CLR 中运行良好,我使用的方法如下所示。 因为 cimg 只是一个头文件,所以我创建了一个 win32 静态库项目并构建了它 然后我在 CLR c++ 中使用了 header ,并在附加库中添加了我的 win32 静态库 (我这样做的原因是为了避免链接器错误),并且它工作正常最后我尝试从 CLR 制作一个 DLL,这样我就可以在我的 c# GUI 项目中使用它 所以我将 CLR c++ 项目的输出更改为 DLL,然后我在 c# winform 应用程序中引用它,然后当我尝试运行它时,我收到此错误消息。

    System.BadImageFormatException was unhandled
HResult=-2147024885
Message=Could not load file or assembly 'cpp tester, Version=1.0.4775.2046, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source=WindowsFormsApplication1
FileName=cpp tester, Version=1.0.4775.2046, Culture=neutral, PublicKeyToken=null
FusionLog==== Pre-bind state information ===
LOG: User = serak-PC\serak
LOG: DisplayName = cpp tester, Version=1.0.4775.2046, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Users/serak/Desktop/Cimg Wrapper/WindowsFormsApplication1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/serak/Desktop/Cimg Wrapper/WindowsFormsApplication1/bin/Debug/cpp tester.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

StackTrace:
at WindowsFormsApplication1.Form1.button2_Click(Object sender, EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at WindowsFormsApplication1.Program.Main() in c:\Users\serak\Desktop\Cimg Wrapper\WindowsFormsApplication1\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

最佳答案

您的 DLL 和应用程序的“位数”是否可能不匹配?如果您正在进行 32 位构建,请确保 C++/CLI 包装器 .DLL 和 WinForms C# GUI .EXE 都是使用平台目标 x86(而不是“任何 CPU”)。要检查这一点,在 VS2010 中,您可以转到项目属性,然后选择“构建”选项卡。

关于c++ - Visual Studio 2012 中的 BadImageFormatExeption,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14578856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com