1

I am trying to use an external DLL library. All the functions that I used so far are working fine except for this one function which throws an EntryPointNotFoundException

I tried using VS dumpbin and I can find the function's name in the exports

Dumpbin Result

My dllimport code

[return: MarshalAs(UnmanagedType.I1)]
[DllImport(DLLPATH, EntryPoint = prefix + "APIConfigureEyeMeasurements"]
protected static extern bool ConfigureEyeMeasurements(byte instance, bool doTopMeasurements, bool doBaseMeasurements, bool doMin,
                                      bool doMax, bool doRiseTime, bool doFallTime, bool doPeakToPeak,
                                      bool doEyeAmplitude, bool doEyeHeight, bool doEyeWidth, bool doCrossingPercentage, bool doJitter, bool doSNR, bool doVEC, bool doTDEC);

The function from its header file:

bool __stdcall APIConfigureEyeMeasurements(
    byte instance,
    bool doTopMeasurements, bool doBaseMeasurements, bool doMin,
    bool doMax, bool doRiseTime, bool doFallTime, bool doPeakToPeak,
    bool doEyeAmplitude, bool doEyeHeight, bool doEyeWidth,
    bool doCrossingY, bool doJitter, bool doSNR, bool doVEC, bool doTDEC);

Could it be something caused by the parameters or from the import that I am using. The strange thing is that all the other functions are working fine

Hasan H
  • 142
  • 11
  • Could you tell us what `prefix` is here? (Perhaps it's `"_API"` for example, and you need to get rid of the `API` part of your string literal?) – Jon Skeet Jun 25 '20 at 08:13
  • @JonSkeet It's only an empty string. `protected const string prefix = "";` – Hasan H Jun 25 '20 at 08:16
  • 1
    Mismatch on @68, there is a parameter missing from both declarations. Tends to be a DLL Hell problem. – Hans Passant Jun 25 '20 at 08:20

1 Answers1

3

Your C# declaration has 16 arguments, each of which consume 4 bytes of stack space. Therefore the postfix should be @64. It is actually @68 which means that your declaration of the function is incorrect. You are probably missing an argument, or have misdeclared the type of an argument, which I am sure you will discover if you double check with the C++ header file.

Ah, I've just re-read the question right the way to the end, and seen that the header file is also missing an argument. So it seems like you will need to get in touch with the developer of the DLL to resolve this issue. The DLL that you are using does not match the header file that you have.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • That was exactly the problem. I didn't realize what the suffix is until now. I tried adding one variable to the end of the dllimport and the function passed. I'll have to contact support to see what this variable do. – Hasan H Jun 25 '20 at 08:34
  • 1
    @HansPassant's answer here (https://stackoverflow.com/questions/15660722/why-are-cdecl-calls-often-mismatched-in-the-standard-p-invoke-convention) has lots of really useful information – David Heffernan Jun 25 '20 at 08:56