Search code examples
c++dllcaplcanoe

CANoe - Could not open .dll in CAPL script


I'm trying to include my own .dll file and export its functions to my CAPL script.

I'm quite certain I've written my .dll file correctly, here is the relevant code, some of it is copy/pasted from the documentation:

#include "pch.h"
#include "CDLL.h"


long CAPLEXPORT far CAPLPASCAL addCAPL(long a, long b) {
    return a + b;
}

#ifdef __BCPLUSPLUS__
#pragma warn -pin
#endif

// Define how to export functions to capl,
// Arg0 = name, arg1=function, arg2=return type, arg3=# of params, arg4=type of params, args5=depth of param if array (aboslutely useless as c++ cannot used 2+D arrays as params without knowing the dimensions)
CAPL_DLL_INFO CAPL_DLL_INFO_LIST[] = {

 {CDLL_VERSION_NAME,(CAPL_FARCALL)CDLL_VERSION, CAPL_DLL_CDECL, 0xabcd,CDLL_EXPORT},

 {"Add",    (CAPL_FARCALL)addCAPL,      'L', 2, "LL", "\x0\x0"},

 {0,0}
};

// Magic export table to capl function?
unsigned long CAPLEXPORT __cdecl caplDllGetTable(void)
{
    return (unsigned long)CAPL_DLL_INFO_LIST;
}

I'm testing with a simple adder function. The required CDLL.h is included and the cpp code compiles successfully into a .dll (LAD.dll).

In CANoe I have added the .dll file under options -> programming -> CAPL DLLs under both simulation and measurement mode. The file is in the exec32 file of the CANoe installation just to be sure (and the exec64).

When I compile my CAPL script I receive the warning:

Warning   2102 at (-1,-1): Could not open C:\Program Files\Vector CANoe 10.0\Exec64\LAD.dll, .  Logger.can

which in turn means I cannot use the exported 'Add()' function in my CAPL script as it does not find the function.

I have read all the documentation regarding CANoe add-ons, and read the three existing stack overflow questions with similar issues to no avail. If I move or rename the .dll CAPL instead warns that the file could not be found. I have edited the permissions of LAD.dll to allow any program full modify access.

I realize this might be a bit obscure but I would greatly appreciate any help on the matter. I'm really pulling my hair out because it feels like I'm doing everything correctly.


Solution

  • Warning 2102 at (-1,-1): Could not open C:\Program Files\Vector CANoe 10.0\Exec64\LAD.dll

    One possible reason for this type of error is that you are mixing 32 and 64 bit. Remember a 64 bit application can't directly load a 32 bit dll. Same goes with a 32 bit application and 64 bit dll. You must not mix these.

    Alternate possibilities could be a corrupt dll, possible missing dependent dlls of the dll or possible missing exported function(s) that may be required by the plugin mechanism.

    In this case it was verified in the comments the problem was a mixing of 32 and 64 bit executables.