Alexander
Thu Jan 10 18:29:16 CST 2008
I know you do :), but from your post it wasn't clear why you are
suggesting COM. My reply was a clarification for posterity.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ:
http://vcfaq.mvps.org
=====================================
"Giovanni Dicanio" <giovanni.dicanio@invalid.com> wrote in message
news:u$y7OF3UIHA.4624@TK2MSFTNGP03.phx.gbl...
> Yes, I know that.
> In fact I also wrote in my previous post:
>
> "If I want to export an object model for the DLL, I would use COM [...]"
>
> IMHO, a pure Win32 DLL is fine if we expose a C interface (the
> implementation can be C++, of course).
> To export an object model from a DLL, COM is the way to go.
>
> Giovanni
>
>
>
> "Alexander Nickolov" <agnickolov@mvps.org> ha scritto nel messaggio
> news:O$tQ4xuUIHA.4092@TK2MSFTNGP06.phx.gbl...
>> That solves nothing since the class is still exported. What one
>> needs to do is define a C++ interface for the class and return
>> that from the C function (and the C++ interface should not
>> directly or indirectly reference any other C++ class that is not
>> in turn another C++ interface, should have no data nor static
>> members, and should not be derived from multiple other C++
>> interfaces). A C++ interface is a class containing only public
>> pure virtual methods. Also note you can't call operator delete
>> on the interface outside of your DLL, so you need to provide
>> another mechanism for disposing it (a global C function or
>> an interface emthod). Once you get there, you may realize
>> you've nearly reinvented COM, so you may go the extra step
>> and convert to a COM server...
>>
>> --
>> =====================================
>> Alexander Nickolov
>> Microsoft MVP [VC], MCSD
>> email: agnickolov@mvps.org
>> MVP VC FAQ:
http://vcfaq.mvps.org
>> =====================================
>>
>> "Giovanni Dicanio" <giovanni.dicanio@invalid.com> wrote in message
>> news:uDZ60rdUIHA.3916@TK2MSFTNGP02.phx.gbl...
>>>
>>> "2b|!2b==?" <user@domain.invalid> ha scritto nel messaggio
>>> news:_9udncYmgLGlah_anZ2dnUVZ8uWdnZ2d@bt.com...
>>>>I have a DLL project that I need to export a data variable from. I have
>>>>defined the variable in a .cpp file in the project like this
>>>>
>>>> //C++ file (DLL Project)
>>>>
>>>> class MYPROJ_API data_type
>>>> {
>>>> //Impl here ...
>>>> };
>>>
>>> You are exporting a C++ class.
>>> Are you using the same compiler version to build the DLL and the client
>>> of your DLL?
>>>
>>>> MYPROJ_API data_type exported_data;
>>>
>>> Instead of exporting the class instance, you may try to export a global
>>> function which returns a pointer to the class instance, something like
>>> this:
>>>
>>> data_type globalData;
>>>
>>> MYPROJ_API data_type * GetExportedData(void)
>>> {
>>> return &globalData;
>>> }
>>>
>>> So the DLL client could call GetExportedData() to access the class
>>> instance.
>>>
>>> Giovanni
>>>
>>>
>>
>>
>
>