Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used the ATL Project Wizard to develop my dll. I want to intantiate an instance of my abstract class "PT2_B_db" in my C++ client and call the pure virtual method "DoubleValueString" from this class instance. How do I write the client code? Which header file do I include in my client code?

the expanded interface header code might give some hints...

virtual HRESULT __stdcall IPT2_B_db::DoubleValueString(DOUBLE dblInputValue,
BSTR bstrFormatString, BSTR *bstrReturnString) = 0;

------------------------------------------------------------
I used the ATL Project template in Visual Studio 2013 to create a “PT2_B.dll.” The “DoubleValueString” method I’m trying to call is part of the “CPT2_B_db” class in that dll. I am able to call all the functions in this dll from Visual Basic, referencing the PT2_BLib. But I need to be able to call the functions from C++ in a separate program.

I’m able to execute the LoadLibrary() function and get a valid pointer to the library. But I’m having trouble structuring the signature of my function pointer to correctly call GetProcAddress(). I’m not sure how to do this. I suspect I need to include the class name somehow. Here are the various definitions from different files in the project. How do I correctly cast my function pointer, call GetProcAddress, and finally execute the function?

From my PT2_B.idl file…
[id(10)] HRESULT DoubleValueString([in] DOUBLE dblInputValue, [in] BSTR bstrFormatString, [out, retval] BSTR* bstrReturnString);

From my PT2_B_db.h file…
STDMETHOD(DoubleValueString)(DOUBLE dblInputValue, BSTR bstrFormatString, BSTR* bstrReturnString);

And from my PT2_B_db.cpp file…
STDMETHODIMP CPT2_B_db::DoubleValueString(DOUBLE dblInputValue, BSTR bstrFormatString, BSTR* bstrReturnString) {}

From my PT2_B_i.h file…
virtual /* [id] */ HRESULT STDMETHODCALLTYPE DoubleValueString(
/* [in] */ DOUBLE dblInputValue,
/* [in] */ BSTR bstrFormatString,
/* [retval][out] */ BSTR *bstrReturnString) = 0;
Posted
Updated 3-Mar-15 10:53am
v2
Comments
barneyman 2-Mar-15 18:57pm    
you're mixing two interface mechanics there - IDL refers to the use of COM, where you'd instantiate a COM object via CoCreateInstance

LoadLibrary is used for getting to exported (via .DEF files) classes/functions

the latter is quick and dirty and suitable for most 'old school' forms of DLL use (C/C++ consumption), the former is much more flexible (C, scripting, etc consumption), but 'troublesome' to understand properly

which do you want?
Sergey Alexandrovich Kryukov 2-Mar-15 19:42pm    
You are right. COM requires a factory, which can be, in a pinch, reduced to a single (non-class) exported function creating an instance of the top object implementing some interface. Just the idea...
—SA

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900