IT-Consultant: Frederick J. Harris > PowerBASIC Programmer's Survival Guide To C And C++

Calling C++ Dll with export class from PB 10 Host

(1/2) > >>

Heinz Grandjean:
I try to call a C++ Dll that has an export class from PB10.

--- Code: ---#ifdef DLL_Test1_EXPORTS
#define DLL_Test1_API __declspec(dllexport)
#define DLL_Test1_API __declspec(dllimport)

namespace CL_Export
     // This class is exported from the DLL_Test1.dll
     class CL_Export
         static DLL_Test1_API int Calculate(int a);

--- End code ---

--- Code: ---#include "stdafx.h"
#include "DLL_Test.h"
#include <stdexcept>

using namespace std;

namespace CL_Export
    int CL_Export::Calculate(int a)
return 13;

--- End code ---

Naturally the traditional PB- declare doesn't work:


--- End code ---

Do I have to use a special class definition in PB??
Maybe as Com?

Thank You
Heinz Grandjean

José Roca:
Sorry, but C++ clases can't be used with PB.

Patrice Terrier:
Yes, write procedural code, that would work with everything.


Heinz Grandjean:
PB-Classes are restricted to Com???

On the procedural side connecting to a C++ -DLL is ok. Tested it.
But then I have to make a procedural interface dealing internally with the Classes inside the DLL.
Coming very close to a philosophical discussion about future.

Thanks for the replies
Heinz Grandjean

Maybe there is a chance if the C++ DLL works as a Com-Server, hopefully unregistered....

Frederick J. Harris:
Sorry I'm coming late to the discussion Heinz.

The whole reason for COM was to create a standard binary footprint in memory so that various programming languages could interoperate at a binary level instead of a source code level.  Therefore, given a C++ class (not a COM based class), that class will only, with 100% certainty of success, be able to be accessed by a client written with the exact same version of C++.  In other words, there is no guarantee that an ordinary C++ class in a dll written in Microsoft C++ will be able to be accessed correctly by GNU C++.  In fact, there is no absiolute guarantee that a Microsoft Version 6 C++ class will be accessable from a version 7 client.  While it likely will, there is no guarantee.  The reason for that is that the C++ standard specifies all kinds of things related to syntax and what must compile and what must not compile, and behaviors, but does not specify how any C++ language implementor must layout binary objects. 

COM was designed to overcome that hurdle by specifying a particular binary layout.  Any language can then create COM objects that can be used by any other language.  For example, I freely interoperate between C, C++ and PowerBASIC in my work.  But the objects I create in C or C++ or low level PowerBASIC adhere to the COM memory layout for objects.  I hope this philosophical point of view helps clear it up for you.  This is a point that confuses a lot of folks.  They think that now that PowerBASIC supports objects, it should freely interoperate with C++.  It will, if the C++ class one wishes to interoperate with was built according to the COM specification, which involves a particular memory setup involving the virtual function table and virtual function table pointers.


[0] Message Index

[#] Next page

Go to full version