Calling C/C++ DLL function Entry Point Error

I have a dll that was made for C/C++ in Borland. The problem is that I keep getting an "entry point not found" error when I run the program. When I compile, I get no errors.

I use DllImport like this:


[DllImport("C:\\Program Files\\SPF\\SpfIIDll.dll",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi,
EntryPoint = "InitSpfII",
ExactSpelling = true)]
static extern unsafe int InitSpfII(char* cSpfCfg, char* cHardwareCfg);

When I call the function, I do it to allow a char* by doing this:

fixed (char* spfcfgpath = spfpath.ToCharArray())
{
fixed (char* hardwarecfgpath = hardwarepath.ToCharArray())
{
initValue = InitSpfII(spfcfgpath, hardwarecfgpath);
}
}

I know that the function exists and I have the header file with the listings of functions:

extern "C" int __declspec(IMOREX1) InitSpfII(char* cSpfCfg, char* cHardwareCfg);
// Initialized comm port and driver. This function has to be called before any other function in this dll
// cSpfCfg: config filename, usually "SpfII.cfg"
// cHardwareCfg: hardware config file, usually "Hardware.cfg"
// return value: 0 OK. Error otherwise

I don't know what else to do. I've been working on this for weeks with no result. I would appreciate any and all help. I don't want to abandon C#, I like it a lot.


Answer this question

Calling C/C++ DLL function Entry Point Error

  • BHOGuy

    Actually, all I needed to do was to add an underscore '_' right before the function name definition at EntryPoint.

    [DllImport("C:\\Program Files\\SPF\\SpfIIDll.dll",
    CallingConvention = CallingConvention.Cdecl,
    CharSet = CharSet.Ansi,
    EntryPoint = "_InitSpfII",
    ExactSpelling = true)]
    static extern unsafe int InitSpfII(char* cSpfCfg, char* cHardwareCfg);

    That did the trick.


  • Stubey

    Yes, you're right. I switched to using 'String' and put in code in braces about using unmanaged marshalling pointers or something like that. Otherwise, it would not work with the corrected entry point signature.

  • Jazz4sale

    The function may be exported with a mangled name. Use a tool like Dumpbin.exe to check the export names.

    BTW, a char in C# isn't the same as a char in C++. If you change the parameter types to string instead of char* it should work better, plus you don't need the unsafe code block.



  • Calling C/C++ DLL function Entry Point Error