user3508865
user3508865

Reputation: 153

Use of DLL's Class's method

I'm trying to include a use DLL's methods using C++.

I've tried to include the DLL using this code:

HMODULE DLL = LoadLibrary(_T("name.dll"));

        if (DLL)
        {
            std::cout << "DLL loaded!" << std::endl;


            if (_pdisconnect)
            {
                std::cout << "Successful link to function in DLL!" << std::endl;
            }

            else
            {
                std::cout << "Unable to link to function in DLL!" << std::endl;
            }
        }
        else
        {
            std::cout << "DLL failed to load!" << std::endl;
        }
    FreeLibrary(DLL);

That DLL that I'm trying to include has two classes PCls and TPCls. The PCls has a method which I'm trying to include is getOP(LONG a). How to use that method, please?

Thanks a lot!

Upvotes: 0

Views: 60

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409166

The problem is that you can't import classes from a DLL, only functions. However, you could have factory functions in the DLL which creates the instances and return a pointer (or you pass in a reference to the factory function that it initializes).

To get a pointer to a function you use GetProcAddress. However note that you must pass it the mangled name of the function.

Upvotes: 2

Related Questions