PInvoke签名与非托管目标签名不匹配。检查PInvoke签名的调用约定和参数是否与目标匹配 [英] PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target

查看:330
本文介绍了PInvoke签名与非托管目标签名不匹配。检查PInvoke签名的调用约定和参数是否与目标匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调用DLL函数时遇到此运行时错误请帮帮我


这是dll functioj

 [DllImport(" candll.dll",EntryPoint =" CanOpenTool2")] 
internal static extern int CanOpenTool2(uint channel,int baudRate,ushort destination,ushort source);

像这样调用
int fd = 0;
const int REGULUS_TOOL_ID = 30;
ushort src = 0;
UInt16 bd = Convert.ToUInt16(iBaudRate);

fd = CommunicationClass.CanOpenTool2(channel,iBaudRate,Convert.ToUInt16(canId),0);

if(canId == 30)//索引1下拉列表中的工具ID,与PROM_TOOL_ID(30)相同
{
nSensorID =(int)SensorId.DM_ELECTRONICS;
}
else //索引0(和默认值)下拉列表中的工具ID,与NEW_PROM_TOOL_ID(9)相同,以及其他所有内容
{
nSensorID =(int)SensorId.NODEID_DM ;





int fd = 0;

        const int REGULUS_TOOL_ID = 30;

        ushort src = 0;

        UInt16 bd = Convert.ToUInt16(iBaudRate);



        fd = CommunicationClass.CanOpenTool2(channel,iBaudRate,Convert.ToUInt16(canId),0);  



        if(canId == 30)//索引1下拉列表中的工具ID,与PROM_TOOL_ID(30)相同为
        {

            nSensorID =(int)SensorId.DM_ELECTRONICS;

        }¥b $ b        else //索引0(和默认值)下拉菜单中的工具ID,与NEW_PROM_TOOL_ID(9)相同,其他一切为
        {

            nSensorID =(int)SensorId.NODEID_DM;



并尝试了2次差异,但同样的例外情况。 



fd = CommunicationClass.CanOpenTool2(channel,iBaudRate,canId,0);  

解决方案

向我们展示如何在C / C ++代码中声明CanOpenTool2函数并从DLL导出。



I am getting this runtime error when tried to call DLL function please help me

this is dll functioj

[DllImport("candll.dll", EntryPoint = "CanOpenTool2")]
        internal static extern int CanOpenTool2(uint channel, int baudRate, ushort destination, ushort source);

Invoking like this
int fd=0;
        const int REGULUS_TOOL_ID = 30;
        ushort src = 0;
        UInt16 bd = Convert.ToUInt16(iBaudRate);

        fd = CommunicationClass.CanOpenTool2(channel, iBaudRate, Convert.ToUInt16(canId), 0);

        if (canId == 30)// Tool ID in dropdown at index 1, same as PROM_TOOL_ID (30)
        {
            nSensorID = (int)SensorId.DM_ELECTRONICS;
        }
        else // Tool ID in dropdown at index 0 (and default), same as NEW_PROM_TOOL_ID (9) and everything else
        {
            nSensorID = (int)SensorId.NODEID_DM;


int fd=0;
        const int REGULUS_TOOL_ID = 30;
        ushort src = 0;
        UInt16 bd = Convert.ToUInt16(iBaudRate);

        fd = CommunicationClass.CanOpenTool2(channel, iBaudRate, Convert.ToUInt16(canId), 0);  

        if (canId == 30)// Tool ID in dropdown at index 1, same as PROM_TOOL_ID (30)
        {
            nSensorID = (int)SensorId.DM_ELECTRONICS;
        }
        else // Tool ID in dropdown at index 0 (and default), same as NEW_PROM_TOOL_ID (9) and everything else
        {
            nSensorID = (int)SensorId.NODEID_DM;

and tried 2 diff ways but the same exception. 

fd = CommunicationClass.CanOpenTool2(channel, iBaudRate,canId, 0);  

解决方案

Show us how the CanOpenTool2 function is declared in the C/C++ code and exported from the DLL.


这篇关于PInvoke签名与非托管目标签名不匹配。检查PInvoke签名的调用约定和参数是否与目标匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆