Author Topic: How to write c++ to call a PB dll  (Read 490 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 221
How to write c++ to call a PB dll
« on: August 21, 2018, 07:32:58 PM »
Hello all

i'm looking for a c++ code that can call a PB dll and retrive a string from that PB dll.

how to write this c++ code ?

all help appreciated and thanxx in advance

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1997
    • www.zapsolution.com
Re: How to write c++ to call a PB dll
« Reply #1 on: August 22, 2018, 03:28:03 PM »
The easiest way is to export your strings as ASCIIZ.

But if you link with a PB DLL, then you are limiting yourself to 32-bit only.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 221
Re: How to write c++ to call a PB dll
« Reply #2 on: August 22, 2018, 03:54:48 PM »
Thanxx Patrice

i'm doing the conversion to C++ stage by stage, something like testing the water first
before leaping into it.  The main thing is to shed the PB codes or modules whenever i find a better
replacement for it.

so do you have any codes in C++ and PB that i can test out ?

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1997
    • www.zapsolution.com
Re: How to write c++ to call a PB dll
« Reply #3 on: August 22, 2018, 06:25:09 PM »
Exported ASCIIZ return a pointer.

So you can use movememory to copy it into you own buffer.

See also
https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/56114-conversion-c-c-pb
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Frederick J. Harris

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 938
    • Frederick J. Harris
Re: How to write c++ to call a PB dll
« Reply #4 on: October 03, 2018, 04:14:00 AM »
Quote
i'm looking for a c++ code that can call a PB dll and retrive a string from that PB dll.

Everything depends on what you mean by retrieve 'a string'.  Most PB'ers use PowerBASIC's Dynamic String Type, i.e., String or WString.  The underlying machinery involved in that is the COM based BSTR data type, which is actually a very simple class.  I would assume if you have a PowerBASIC dll containing one or more functions which take as a parameter a String as described above, then you are going to get yourself into C/C++ 'deep water' very fast, as you are going to have to master some fairly advanced C++ topics including C++ low level COM and the nuances of the BSTR type. 

If you are just starting out with C++ your best bet is to do as Patrice says and rework your PowerBASIC dll to use null terminated strings (asciiz or wstringz).  Having done that, using a C/C++ host/client, the incomming string will simply be interpreted as a pointer to a string of characters - something a beginning C/C++ coder can easily deal with.  Hope this helps.  In my various tutorials I give a number of simple examples of this.