c# - 来自 C# 的 DLL 调用在较新的 .Net 框架中不起作用(3.5 与 4.6.1)
问题描述
我有以下代码:
[DllImport("ftcjtag.dll", CallingConvention = CallingConvention.Cdecl)]
static extern uint JTAG_OpenHiSpeedDevice(string DeviceName, uint locationID, string channel, ref IntPtr pftHandle);
[DllImport("ftcjtag.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern uint JTAG_InitDevice(IntPtr ftHandle, uint clockDivisor);
IntPtr ftHandle = IntPtr.Zero;
ftStatus = JTAG_OpenHiSpeedDevice(hiSpeedDeviceName, locationId, hiSpeedChannel, ref ftHandle);
if (ftStatus != FTC_SUCCESS)
{
throw new JTAGApiException("An error occurred while calling JTAG_OpenHiSpeedDevice for device:" + hiSpeedDeviceName + ". API Error:" + GetError(ftStatus));
}
ftStatus = JTAG_InitDevice(ftHandle, 1);
if (ftStatus != FTC_SUCCESS)
{
throw new Exception("An error occurred during init jtag device " + HiSpeedDevice.DeviceName);
}
当我使用 ,Net 3.5 运行它时,它运行良好。
当我切换到 4.6.1 时,JTAG_InitDevice 返回一个错误代码,指出提供的句柄无效。JTAG_OpenHiSpeedDevice 是我得到句柄的地方。我看不出为什么在 3.5 中句柄是有效的,而在 4.6.1 中它是无效的。
谢谢
解决方案
推荐阅读
- r - Shiny:根据另一个数据表上的点击事件创建动态数据表
- c# - 开始时未选中单选按钮
- eclipse - 有没有办法让 jubula 映射外部对象?
- vue.js - 根据附加的变量值,绑定类似乎无法正常工作
- javascript - 重构 JavaScript / TypeScript:避免重复属性
- java - 我应该如何使用另一个线程来获取光标位置并使用坐标更新 2 个标签?
- regex - 如何在 Mongo 中根据表达式查询字符串
- java - 为 elasticsearch 客户端构建 XContentBuilder json 查询
- android - 有没有办法在 WebView 中显示 Chromecast 按钮?
- jackson - 从 Spring Batch 3 迁移到 4