首页 文章

dll <dllname.dll> <functionname>中的类型无效,但我没有看到错误

提问于
浏览
2
CAPL_DLL_INFO4 table[] = {
{CDLL_VERSION_NAME, (CAPL_FARCALL)CDLL_VERSION, "", "", CAPL_DLL_CDECL, 0xabcd, CDLL_EXPORT },

  ... 
  {"dllTEST",(CAPL_FARCALL)GetAttribute,"CAPL_DLL","...",'I', 5, "IIICI", "\001\001\001\100\001",{ "x","x","x","x","x" } },
  ...

{0, 0}
};
CAPLEXPORT CAPL_DLL_INFO4 far * caplDllTable4 = table;

这是源文件中的CAPL导出表,用c语言编写,编译时没有错误或警告* .dll . 在我的定义和原型中,函数接口如下所示:

int CAPLEXPORT far CAPLPASCAL GetAttribute(int16 a, int16 b, int16 c, char d[], int16 e);

成功将* .dll实现到CANoe后,我在CANoe中得到了编译错误:

CAPL node 'ECU 1': Compilation of '..\ecu.can' failed with error(s)
Invalid type in DLL ..\abc.dll, function dllTEST.

我错过了一些明显的东西吗函数中使用的类型都精确地转换为CAPL符合类型,在第15页的this pdf中,您可以阅读有关错误的信息:

编译CAPL程序时会捕获此错误 . CAPL导出表中定义的函数不正确 . 大多数情况下,它是CAPL导出表中的参数设置 .

1 回答

  • 1

    根据"Implementing and Integrating CAPL DLLs"手册,您的函数声明和函数表应如下所示:

    long CAPLEXPORT far CAPLPASCAL GetAttribute(long a, long b, long c, char d[], long e);
    
    CAPL_DLL_INFO table[] = {
        {CDLL_VERSION_NAME, (CAPL_FARCALL)CDLL_VERSION, CAPL_DLL_CDECL, 0xabcd, CDLL_EXPORT},
        ... 
        {"dllTEST", (CAPL_FARCALL)GetAttribute, 'L', 5, "LLLCL", "\000\000\000\001\000"},
        ...
        {0, 0}
    };
    
    unsigned long CAPLEXPORT __cdecl caplDllGetTable(void)
    {
        return (unsigned long)table;
    }
    

    解释

    • 由于只有第4个参数( d )是一个数组(1维), Array Depth Definition 是:
    "\000\000\000\001\000"
    
    • 不要使用 int16 . 使用表3( Function Parameter And Return Value Data Types )中描述的类型 . 由于 intchar 只能在数组大小!= 0时使用,因此我们使用 long .

相关问题