Author Topic: Calling C++ Dll with export class from PB 10 Host  (Read 3190 times)

0 Members and 1 Guest are viewing this topic.

Offline Heinz Grandjean

  • Newbie
  • *
  • Posts: 22
Calling C++ Dll with export class from PB 10 Host
« on: September 05, 2013, 06:47:55 PM »
Hello,
I try to call a C++ Dll that has an export class from PB10.

Code: [Select]
#ifdef DLL_Test1_EXPORTS
#define DLL_Test1_API __declspec(dllexport)
#else
#define DLL_Test1_API __declspec(dllimport)
#endif


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


Code: [Select]
#include "stdafx.h"
#include "DLL_Test.h"
#include <stdexcept>

using namespace std;

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


Naturally the traditional PB- declare doesn't work:
Code: [Select]
DECLARE FUNCTION Calculate STDCALL LIB "DLL_Test1" ALIAS "Calculate" (BYVAL LONG) AS LONG
   

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

Thank You
Heinz Grandjean
« Last Edit: September 05, 2013, 06:51:19 PM by Heinz Grandjean »

Offline Josť Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2491
    • Josť Roca Software
Re: Calling C++ Dll with export class from PB 10 Host
« Reply #1 on: September 05, 2013, 07:03:22 PM »
Sorry, but C++ clases can't be used with PB.

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1998
    • www.zapsolution.com
Re: Calling C++ Dll with export class from PB 10 Host
« Reply #2 on: September 05, 2013, 07:07:53 PM »
Yes, write procedural code, that would work with everything.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Heinz Grandjean

  • Newbie
  • *
  • Posts: 22
Re: Calling C++ Dll with export class from PB 10 Host
« Reply #3 on: September 05, 2013, 08:21:17 PM »
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

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

Offline Frederick J. Harris

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 938
    • Frederick J. Harris
Re: Calling C++ Dll with export class from PB 10 Host
« Reply #4 on: September 10, 2013, 05:26:02 PM »
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.

Offline Heinz Grandjean

  • Newbie
  • *
  • Posts: 22
Re: Calling C++ Dll with export class from PB 10 Host
« Reply #5 on: September 18, 2013, 10:38:56 PM »
I apologize  for late answering, Frederick!

I have not checked the thread any longer, thinking it had become inactive.
But in the meantime I have tested Your helpful advices concerning the call to C++ DLLs.
(I love PB, but I have realized the fact to be in a certain dead end street.)
Therefore I started to learn C++, following Patrice Terrier.

By the way I think it to be not only  a question of translating PB to C++
It is a different approach and more than "simply interpreter's work"...

Please allow me some additional sentences.
Detecting the impossibility to access C++ classes (inside C++ DLLs) via PB,  I focused the Com-aspect,
because I want to avoid a (historical) procedural export-interface (what I got working...).

I now can reach my PB!!!-compiled DLLs via late com-binding (PB-style and without registry).
I did that in the hope to do it in the same way with C++.
......??
Thanks,
Heinz Grandjean