I'm trying to create an unmanaged C++ DLL. For the most part, I use the interface and factory pattern to instantiate complex objects across the DLL boundary for the user.
My question is in regards to primitive class types that may be allocated on the stack.
For example, consider the code below for a class and 2 utility functions in my library:
// Forward declaration for the PIMPL idiom
class SimpleData;
class Simple
{
public:
AWESOME_API Simple();
AWESOME_API Simple(const Simple& other);
AWESOME_API Simple& operator=(const Simple& other);
AWESOME_API ~Simple();
AWESOME_API void PublicFunction1(); // Public function with private implementation
AWESOME_API void PublicFunction2();
// ...
private:
void SecretFunction1();
void SecretFunction2();
// ...
private:
int m_Number;
SimpleData* m_Data;
// ... Other primitive data types ...
};
AWESOME_API static void DoSomethingWithSimple(Simple& simple);
AWESOME_API static Simple GiveMeASimple();
Assume that the AWESOME_API
is the correct implementation of the __declspec(dllimport)
/__declspec(dllexport)
attributes.
Could I then safely do the following in my application using this library while giving the user the freedom to compile their application with whatever compiler they choose (as long as they are both 32-bit applications)?
#include "Awesome/Simple.h"
int main(int argc, char* argv[])
{
Simple s0;
Simple s1(s0);
Simple* s2 = new Simple();
Simple s3 = GiveMeASimple();
DoSomethingWithSimple(s1);
DoSomethingWithSimple(*s2);
delete s2;
return 0;
}
If not, how can I achieve this functionality across the DLL boundary? By doing this, what limitations am I imposing on the user?