how to export function in namespace to dll

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sjdltzy
    New Member
    • Aug 2010
    • 2

    how to export function in namespace to dll

    I'm writing a dll for other people ,but I don't wan't to give him codes.
    How can I export the function class and namespace in dll .like:
    namespace name
    {
    class a
    {
    a();
    ~a();
    public :
    int fun1(int i);
    double b;
    };
    int fun2(int j);
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You provide the dll in binary form plus a header file. In your example, your header could look like:

    Code:
    namespace name
    {
    class a;   //forward reference
    int fun1(a* obj,int i);
    int fun2(a* obj,int j);
    double getb(a* obj);
    a* Create();
    }
    You provide a forward reference for your class. That's enough to allow the compiler to accept an a*. You can't actually create an "a" object without exposing the class and its constructors.

    Next, you write a Create function to create and object and return pointer to it. This is a factory. Research the Factory design pattern.

    Next, you provide interface functions that can interact with an "a" object whose pointer was obtained from Create. These interfact functions will have pointers to an "a" object argument plus the other arguments.

    You are not required to provide an interface function for every method of your class but only the ones the dll users can call.

    In effect your header is treating the entire dll as a class and the functions in the header are the methods available in the dll.

    Comment

    Working...