Dynamically Loading DLL Class Member Function

I have created a dll but I'm not sure how to interact with a class member function in the client code.
Say there's a function called Foo laid out like this inside a .hpp in the dll:

1
2
3
4
5
6
7
8
9
10
11
12
namespace MyNamespace
{
    extern "C"
    {
        EXPORT struct StructB {...}

        EXPORT struct StructA
        {
             void Foo(StructB & pMyArg) {...}
        }
    }
}


I have 2 questions.

1. What would I put into GetProcAddress to get Foo?
2. And, since Foo takes StructB defined inside the dll, how do I access that in a client program?

Thanks to anyone.
Last edited on
Why don't you just export the class/struct so it can be instantiated within the client? Do you know how to do that? You would need the class header describing the class available to the client. The client needs to know the layout of any classes or structures instantiated within the server that are referenced by the client. It doesn't need to instantiate any, but just know their layout.

GetProcAddress() is most suitable for obtaining the virtual memory address of simple exported functions - not member functions of a class. For a simple function not a member of a class you would simply provide the HINSTANCE of the dll and the textural name of the function.

It looks to me like you are making things hard on yourself.
Last edited on
GetProcAddress could work for this, but you'd end up using your object through void pointers and it gets all kinds of needlessly complicated from there.

freddie1 called it, export your class from the DLL and use a header file in your application for it's declaration: https://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx
Sorry, I forgot to add the exp/imp define in the example I provided.
Alright then, that clears a lot up. So, I guess with dlls, class members just aren't the done thing? But is there a way to export static member functions normally?
Last edited on
Topic archived. No new replies allowed.