Testand - 使用 C# DLL 使用 C# Wrapper 使用 C# DLL

Testand - Use of a C# DLL using a C# Wrapper using a C DLL

有一个我用作 DLL 的 C-Funktion。该函数由

导出
__declspec(dllexport) uint8_t *SomeFunction(uint8_t *a);

在相应的头文件中。

包装器导入函数

[DllImport("SomeCFunction.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SomeFunction")]
private static extern IntPtr SomeFunction(Byte[] array1);

包装器有一个方法,其中包含对该函数的调用

public unsafe Byte[] SomeFunction(Byte[] array1, Byte[] array2)
{
    IntPtr parray2 = CalculateKeyFromSeed(array1);

}

现在在 TestStand 中执行步骤时出现错误:

An exception occurred inside the call to .NET member 'SomeFunction': System.BadImageFormatException: Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B) bei SomeFunctionWrapperNameSpace.WrapperClass.SomeFunction(Byte[] array1) bei WrapperNameSpace.WrapperClass.SomeFunction(Byte[] array1, Byte[] array2) in SomeFunctionWrapper.cs:Zeile 33. bei SomeFunction(Byte[] array1, Byte[] array2) in SomeFunction.cs:Zeile 39.

知道我是如何让 TestStand 接受这个 DLL 的吗?

BadImageFormat 通常意味着其中一个部分的位数不匹配。

这些需要匹配,你有3个部分要检查

  • C dll 是 64 位的吗?
  • C# dll 是 64 位的吗? (这里 AnyCPU 应该没问题 AFAIK)
  • TestStand 进程是 64 位的吗?