detect wrong dll (delay loaded)

I’m providing a C++ DLL used by an application which delay load this DLL, compile its header file and link it using its .lib file.
When I change this DLL by adding a new param to an exported function, the project which is using it compile fine with the new header+lib files even if I forget to replace the DLL by the new one. The problem is the program crash only when the DLL is used (because of delay loading), I want to be able the program to crash early before (or any other solution) if the DLL is not the good one.
You can't do that. When you build a DLL the code is written to a .dll file, and a .lib references entry points by ordinal into that .dll file.

If you change the .dll file, you are most likely upsetting the ordinal/function relationship. And an old .lib will not match this new mapping.

The Microsoft C++ runtime solves this by creating a .def file that defines the mapping of ordinal/mangled C++ function name. New methods are added at the end in later releases so an old lib can be safely used with the new DLL.

A C++ solution to this problem is to provide a public abstract interface to the C++ object in the DLL. You also export a factory function that returns a pointer to this interface use that pointer to the object to do your stuff.

The functions just act as indexes into the interface's vtable. So you're back to some kind of mapping again, but this time it's controlled by the C++ language, not the Operating System, and so is portable.

For example:
class EXPORT I3DShape
    virtual void Release() = 0;
    virtual double Volume() = 0;
    virtual double Area() = 0;
    virtual I2DShape* Project(double dx, double dy, double dz) = 0;

    static I3DShape* Create(std::istream &);
Topic archived. No new replies allowed.