gpt4 book ai didi

c# - BadImageFormatException : PInvoke ImportDll with hdf5dll. dll

转载 作者:行者123 更新时间:2023-11-30 20:11:39 25 4
gpt4 key购买 nike

好的,我已经从官方网站下载了 HDF5 库,并且我有一些 DLL,包括 hdf5dll.dll 和 hdf5_hldll.dll。

在我的类 H5H5LTH5FH5T。来自 H5.cs 的示例:

namespace HDF5
{
using hid_t = System.Int32;
using herr_t = System.Int32;
using hsize_t = System.UInt64;
using size_t = System.UInt32;
// hbool_t is 0:false, +:true
using hbool_t = System.UInt32;
// htri_t is 0:false, +:true, -:failure
using htri_t = System.Int32;

public class H5
{
const CharSet StringMarshallingType = CharSet.Ansi;
const string DLLNAME = "hdf5dll.dll";

        ///* Functions in H5.c */
//H5_DLL herr_t H5open(void);
[DllImport(DLLNAME,
CharSet = StringMarshallingType)]
public static extern herr_t H5open();

在 Program.cs 中,我使用 H5.H5open();,但我得到了一个 BadImageFormatException。我需要一个不同的 DLL 吗?方法签名看起来不对吗?

作为下一步,我想在 C# 中获取它:http://www.hdfgroup.org/HDF5/Tutor/h5lite.html .

操作系统:Windows 7 64 位
环境:Visual Studio 2008 Professional

更新:不知道会不会和这个有关系,也不记得我的环境是不是VS2008 SP1,但是this question或许是解开谜团的 key 。我现在正尝试在家里用 32 位 VS 2010 重复这个场景。

最佳答案

当您尝试在 x64 进程中对用于 x86 架构的 dll 运行 P/Invoke 操作时会发生这种情况,反之亦然。我会检查所有这些,如果它们不同步,请考虑将 HDF5 针对的处理器与您的应用程序结合使用,或者检查是否有特定于处理器的版本可用。

关于c# - BadImageFormatException : PInvoke ImportDll with hdf5dll. dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3471926/

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