gpt4 book ai didi

c# - 不调用静态构造函数

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:48 26 4
gpt4 key购买 nike

<分区>

我有以下类(class):

 private static class NativeSomeWrapper
{
[DllImport(NativeMethods.myCeeLib, EntryPoint = "Get_300_bars",
CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.SysInt)]
internal static extern IntPtr Get300bars([MarshalAs(UnmanagedType.SysInt)] IntPtr assessment);
}

我有一个负责初始化 dll 的静态类:

internal static class NativeMethods
{
public const string myCeeLib= "myCeeLib.dll";


static NativeMethods()
{
var path = GetPathToMyCeeLibFile();
var err = SetPath(path);
if (err != ErrorCode.Ok)
{
throw new FileNotFoundException("Coulnt find myCeeLib file.");
}
}
}

问题是 NativeMethods 构造函数没有按预期被调用。

如何确保 NativeMethods 静态构造函数被调用并且库文件的路径设置正确?

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