Powerbasic Museum 2020-B

IT-Berater: Theo Gottwald (IT-Consultant) => PureBasic Tipps and Tricks => Topic started by: Bob Houle on February 16, 2016, 04:41:42 PM

Title: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Bob Houle on February 16, 2016, 04:41:42 PM
In PureBasic the Visual Designer is a free add-on to help a few 'NEW' people to get started with simple Windows forms. Used how it was intended, it's perfectly adequate.

Besides PureBasic is 'MILES' ahead of PowerBASIC in many areas.

PureBasic has many included libraries:
- 2D and Engine3D libs
- CGI
- Cipher
- Database
- Dialog
- DragDrop
- Image libs
- Json
- Network
- Printer
- VectorDrawing
- XML
(and at least 75 more)

All FREE for you to use 'if you wish' (yes, if used, they will add some size to your EXE)

And, besides the above, there's at least 2 gigs of samples located on the PB forums (just checkout the Tips and Tricks sub-forum)

PureBasic 5.41 (latest is always available).... 79 euros (94 USD)
- LIFETIME licence
- 32 and 64 bit
- FREE Console Compiler included
- Windows/Mac/Linux
- FREE VISUAL DESIGNER
- tons of libraries to speed your work
- English/French/German forums
- IDE is excellent (subjective)
- Compiler updated often since 2002

The 'DEMO' version of PureBasic is available at: https://www.purebasic.com/download.php (https://www.purebasic.com/download.php)

Limitations:
The demo-version of PureBasic is limited as shown below:

- No DLLs can be created
- you can't use the whole external Win32 API support
- no development kit for external libraries
- maximum number of source lines: 800 lines (approximate... depends on system)

----------------------------------------

Here's some critical things about PowerBASIC
- 32-bit only
- NO VISUAL DESIGNER
- NO Libraries
- pre-war IDE
- last update was 2013??
- Future???

A bit more...
PowerBASIC Windows 10.04 (2013)..... 199 USD
PowerBASIC Console Compiler(2013).... 169 USD
PowerBASIC Forms 2.0.........................   99 USD
             Total       267 USD

Price difference.. PureBasic puts 173 USD in your pockets!

Using PowerBASIC is like using a hand-mower to cut your lawn... it gets the job done, but you're left dripping wet with sweat. You know, you could go out and buy a new riding lawn-mower... but you paid good money for that hand-mower. (Besides... your wife says you have to keep using it.) :)
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on February 17, 2016, 08:28:03 AM
I have splitted and remixed this Topic, because you are making an Comparison with PowerBasic.
Also this way its easie to read for people. The other Topic was about SpiderBasic mostly.

Ok, in my Opinion, Powerbasic still has a lot of advantages in the Compiler and about the Visual Designers.
But Fred and the people there are aware of the shortcomings as i see it.

Of course if you are used to PureBasic, thats just like you are used to a car XY and you get also used to deal with these shortcomings.
Possibly you do not even know the difference to FireFly, Phoenix 2 or even QTAB.

Ok, about the Compiler, i see it like this:

1. About the price, features and libraries, nearly all that you write is also my opinion.

2. Besides that PureBasic would need a second Pass, i do not like to always write "DECLARE ...." thats Dinosaur-Technology we had this until PowerBasic 8. For me this is a step back.

3. It does need a Updated Visual Designer - the built in is free, but even the commercial PureForm does not look better.
    It can not compete against FireFly (for Freebasic -and thats even Freeware). There is NO good VD for PureBasic anywhere.
    Did not Edwin have something in the Past?

Besides that, Purebasic has some limitations from the Compiler for Example, it has no "GOSUB", but ok ... could live with this.

How about Loops, can it make an "For i.f=0.001 TO 10.09 STEP 0.5" actually?
Did not try ... last time this was not possible.
Means in scientific cases you had to "Hand code" your Loops. Thats was not state-of-the-art also.
I did not yet check if there are actually changes.

So far i coded today with PureBasic and the biggest problem i have is that i simply miss FireFly from Paul :-). Its so much faster then to handcode all the stuff.

Having said this, the reason why i chose PureBasic for my current Project is that it has an Vector-Print Library that Prints on any device with a constant size.  This way i could Print on a PDF Printer as well as on a Laser Printer getting the same results.
In PowerBasic this would not be so easy. It does have XPRINT but this is not as good, as i see it.

Here is a more complete Listing of the Libraries that are included with PureBasic 5.41 LTS
2D Drawing
Array
AudioCD
CGI
Cipher
Clipboard
Console
Database
Date
Debugger
Desktop
Dialog
Drag & Drop
File
FileSystem
Ftp
Font
Gadget
Help
Http
Image
ImagePlugin
JSON
Library
Linked List
Mail
Map
Math
Memory
Menu
Movie
Network
OnError
Packer
Preference
Printer
Process
Regular Expression
Requester
Runtime
Scintilla
Serial Port
Sort
StatusBar
String
System
SysTray
Thread
Toolbar
VectorDrawing
Window
XML


Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Israel Vega on February 17, 2016, 06:16:35 PM
Is need a good Visual Designer, how Firefly.  I have a license of PureVision and do not like.  There may be an opportunity for Firefly, Phoenix or EZGUI. 

Also in Database I not know why does not exist a LastDatabaseRow . You can find NextDatabaseRow,  FirstDatabaseRow, PreviousDatabaseRow but no statement for LastRow.


Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Israel Vega on February 17, 2016, 06:23:39 PM
It may be that the community is accustomed to free PureBasic libraries and there is no stimulus to produce a decent version of VD. Yes I would be willing to pay if it's worth it.
I personally love the IDE Longtion RadBuilder of other software but I have been combining with PowerBasic and PureBasic.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on February 17, 2016, 10:23:58 PM
How large is the PureBasic Community really at this time?
My impression when i was there last time was, that many people "run away" from Purebasic.
Gnozal, the Author of JapBe included. Nearly all those alternative VD Tools, or Module Authors are not available,
or do not more update their stuff.

Did this happen after Fred stopped making so many updates?
Did they think he would give up PureBasic?
I don't know what went wrong. Anyway PureBasic and Fred is alive.
And the curretn state of the Compiler about reliability makes a good impression.
I did not find any bugs or problems this time.

Must say that PureBasic has a larger Problem with version compatibility then PowerBasic.
Modules/libraries created for older PureBasic versions often do not more work with newer versions.

If there is no large customer base, nobody makes a good Visual Designer.
However, Paul could possibly adapt Firefly if he wants.
While i would prefer a version that does not compete with my PowerBasic FireFly that i have installed.
Thats also the reason for me to avoid Freebasic. It will steal the ".bas" Ending which is reserved for PowerBasic.
Also it needs a "Second Firefly" and i don't know if it will beat up my Firefly for Powerbasic.

PureBasic has all different from PowerBasic. They do not beat each other therefore they fit together on one Computer.

EZ GUI is largely a library system. Theoretically it could also be adapted to PureBasic.
But i do not know if Chris would do it and if it would pay out at the end.

One thing is sure, PureBasic is going to last longer.
Fred is around, he is active (while possibly more with Spider-Basic?) but he is around and he makes Updates from time to time, and if its only to fix some errors.
Therefore developments for PureBasic may make sense on long run.

Did Edwin Knoppert not also had something for PureBasic long time ago?
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Bob Houle on February 18, 2016, 04:50:33 PM
Theo...
QuoteBesides that, Purebasic has some limitations from the Compiler for Example, it has no "GOSUB", but ok ... could live with this.
It pays to read the manual... {grin}

From the manual: https://www.purebasic.com/documentation/reference/gosub_return.html (https://www.purebasic.com/documentation/reference/gosub_return.html)

From the Rosetta Code web-site: http://rosettacode.org/wiki/Jump_anywhere#PureBasic (http://rosettacode.org/wiki/Jump_anywhere#PureBasic)

The complete PureBasic Help On-line:  https://www.purebasic.com/documentation/index.html (https://www.purebasic.com/documentation/index.html)

As far as:
QuoteHow about Loops, can it make an "For i.f=0.001 TO 10.09 STEP 0.5" actually?

True... but how hard is it to use a While/Wend statement?

;"For i.f=0.001 TO 10.09 STEP 0.5"

a.f = 0.001
While a < 10.09
     a = a+0.5
Wend


Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on February 19, 2016, 01:29:04 PM
There are some loop structures that are normally there in any high level language.
One of them is "FOR ..NEXT". In this case its just not completely implemented.
Its implemnted just for integer.

Of course loops can be hand-coded. Anything can be hand-coded.
Its just not so easy like it is in PowerBasic.

And there is no real reason, it looks to me rather then they forgot about it when designing "FOR .. NEXT" Loops.
So there is no reason to find out why, rather hope they will correct it one day.

About the GOSUB, it does only work in the Main Program Part, it can not be used inside of Procedures.
But most of the code is within Procedures, means that its near to useless
Manual says:
QuoteGosub kann nur im Hauptteil des Quellcodes verwendet werden, jedoch nicht innerhalb von Prozeduren.

Reason is:
PureBasic Forum Wishlist from a PB user (http://www.purebasic.fr/english/viewtopic.php?f=13&t=40122)

I am near to say that PureBasic is a french product with all the advantages and dissadavantages from that.
Its simply been started, and has a lot of tasty features, but its not designed in a way how we would do it in germany.

On the other side WINDEV is also from france and at least about design its really complete. While for me the needed runtime is currently too large.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Patrice Terrier on February 19, 2016, 07:35:10 PM
QuoteWhile for me the needed runtime is currently too large.
Comparing p-code and native code is like comparing apple and orange.

The WinDev runtime is smaller than the .NET Framework, and once you get accustomed to use it, there are several DLL from the runtime that you can remove from the default build.

...

Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on February 22, 2016, 08:16:19 AM
Thats definitely the case, Patrice.
Just that its a lot more then with PureBasic or PowerBasic.
Depending on the Project its no problem or too much.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Patrice Terrier on February 22, 2016, 09:46:51 AM
With WinDev the smallest size of the framework is 4058 Kb, including the EXE, but not the .wdl specific to the application.

The 4058 Kb framework, is what you can get when writting only in pure SDK code style, and when you put everything into the project code section.

...
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on March 05, 2016, 09:00:22 AM
Must say that i am a long year PureBasic customer. I boiught it when it came out.
Now after a lot of years, i went back to see how it developed.

Looking about features and libraries, PureBasic is a good deal.
It has so many - ready to use - libraries for so many things.

And this is where PureBasic is going to be developed.
As a sort of Toolbox. Not primarily as a compiler.

Seen from the standpoint of a PowerBasic user, in many aspects PureBasic looks more like some sort of "Macro Assembler" with included library collection "Toolbox".
For example even now, after many years , there is no real "GOSUB" within Procedures. Because this would corrupt the stack with the cariables.

Other topics include OOP - from reading in the Forum, the point is that "Fred does not like it".
And this means, that it is not going to happen.

To me it looks like that this "Fred does not like it" shows up in teh PureBasic Forum at many places.
And this slows down the further development of PureBasic.

It stays at this advanced "Macro Assembler Level". No changes in structiure for the last years.

Single-Pass, need to declare Procedures. Like in PowerBasic 8.
Simple constructs like FOR .. NEXT Loops don't take Floating Point numbers.
GOSUB does not work inside Procdures. No interest in user-friendly OOP constructs.
The visual Designer - while included for free, is not state of the art.
String commands are far behind PowerBasic standards.

The worst point is that there is no real hope about it, because the spirit in the Forum is like this
"Fred does not like it" -> it will never happen.

And what reminds me to older times in the PowerBasic Forum ... if you discuss these topics you are in trouble.
I even got a message from Fred that he want to kick me from the forum because i criticized the fact that these topics are still open.
As i see it.

And this missing interest about points that need to be fixed just because "Fred does not like it".
Is the biggest problem that i see in the future for PureBasic.
Especially as this is true also for things that could be fixed easily.

For this reason i am still looking for alternatives about x64.

At least for larger projects, the PureBaisc code looks to unreadable to me as it currently is.
And i currently have no hope that this "Fred does not like it" thing is going to be repaired in the future :-).
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Bob Houle on March 05, 2016, 03:23:16 PM
QuoteAnd this missing interest about points that need to be fixed just because "Fred does not like it".
Is the biggest problem that i see in the future for PureBasic.

Sheeesh.. Theo, you'd complain if you were hung with new rope.  >:(

You don't understand the language, you don't know how to use it.

Ever think it could be YOU?

Insulting the designer of a language because you want something your way (besides calling it: "PoorBasic")
is NOT the way to make friends.

Nobody cares... move on.  >:(
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on March 05, 2016, 07:07:49 PM
I am to old to just praise their buggy programming.
At this time i just say what i think, if somebody doesn't like they can delete it.
You know i do the same here.

Thats not the problem. The problem is the unability to get forward with points that i think are important, as i wrote above.
I have seen some (at least 2) PureBasic users are making their own PreProcessors to overcome some of these "Fred-doesn't like it" Features (OOP ...).
The concept is interesting, but at the end this will only work if somebody makes a completely new IDE.

Having said this, also PowerBasic could be improved with a "PreProcessor IDE"
... and i think i would do this, if there would be a visiible perspective for x64.

I also have a lot of ideas what could be added to PowerBasic, it happens if you use a tool for some time.

PS:Do you know a trick how i can make PureBasic to compile a "Main File" like it can be set in the PowerBasic IDE?
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Bob Houle on March 06, 2016, 03:53:07 PM
QuoteI am to old to just praise their buggy programming.

If you think have found a bug, place it in the Code forum.
People will look at it, and IF TRUE, the moderator will place it in the Bugs forum and it will be fixed ASAP.
If it's not a bug, you will be helped to solve your problem.

Calling a program buggy when you don't even understand it doesn't make sense.

You want PureBasic to operate the way you want.
While a bit of that is O.K., you'll want to work WITH the program, as intended.

Same as below... you want PureBasic to work like PowerBASIC. Why?

PowerBASIC...

#COMPILER PBWIN 10
#COMPILE EXE
FUNCTION PBMAIN () AS LONG

    MSGBOX "Hello, World!"

END FUNCTION   

'-------------------------------------------------------------------------------

I assume you mean?

Procedure Main()
    MessageRequester("", "Hello, World!")
EndProcedure

Main() ; Executes the above just like PowerBASIC


Why not?   
MessageRequester("", "Hello, World!")

Does the same thing, with less typing.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on March 07, 2016, 02:42:37 PM
Don't turn my words around, Bob.
For the price it has and the licencing, PureBasic is an possibly unbeatable collection of libraries
combined with an great Marco Assembler.

With even a bit "BASIC like Syntax".

Seeing the shortcomings that i told you before, its in my opinion not really a complete "compiler".
For this the second Pass is missing, and some very BASIC things

Its built on some sort of Middleware to be able to compile to many different environments.
But its architectural shortcomings are just nasty for people coming from a really complete compiler - and that is PowerBasic.

If you don't need a really usable and complex String Engine (like the one in PowerBasic),
if you don't need For NEXT Loops with the Option of using Floating Point Numbers ...
You don't use really fast CALL ... RET or GOSUB .. .RETURN in your Programming.
Thats up to you. Then you will be quite happy with PureBaisc ... possibly.

I think "thats BASIC stuff it should be in there".

Note that i will delete insults from Postings, or delete missleading postings, but i will not block you or anybody for that you believe that
"PureBasic" is the last word in Computerprogramming". Thats your good right.

Even i would like to have more enthusiastic PureBasic people here in the Forum.
So we could start exchange sollutions to the builtin shortcomings.

Because anyway PureBasic has advantages in its libraries, its a strong Macro-Assembler with some compiler-features, and it "compiles" on x64 and multiple other systems.
For that price it has thats definitely an good offer.

Even if it will stay forever on the "Single Pass" and "No OOP" standpoint because "Fred doesn't like it".

Which programming system does not have anywhere such people who slow down the train?
They are anywhere i guerss. Also at PowerBasic we always had some of these " XY... doesn't like it" people.

However about the Second Pass and Objects, in PowerBasic we got it finally with PB 10.
And i believe that nobody will go back into the reverse direction.

The whole thing with PureBasic reminds me to PowerBasic 7 or more years ago.
All Sollutions were there. Jose already made a superb Editor, gave them perfect include files.
They would just had to incorporate this stuff and concentrate on doing their Job.
Making a good compiler and possibly for x64.

Instead they continued to build the wheel a second time and of course never reached the quality of Jose's work.

Also in the PureBasic Forum there are people who have nearly ready sollutions (for OOP) .
Fred could just implement these ready made "preProcessor" based sollutions into the compiler and this would not be a lot of work.
For the user its completely transparent, if there is internally an Preprocessor or not.

The second Pass ... can't be a big problem, i have heared there are utilities for this also out there.

The FOR .. NEXT Loop?
Could internally be reformated to another LOOP-construct with FP-Variables.

Transparently for the user.
All this is not an technical problem. Its just "Fred doesn't like it".

There is anotehr thing that you see in the PureBasic Forums.

This was at eaxctly that time when Fred stopped the further "thinking ahead" and started to concentrate on SpiederBasic.
Then many people were going away from PureBasic.

A lot of Projects in the forum are dropped at that time.
I have seen a lot of promissing - started - but never endede projects in the PureBasic Forum.

I wished they could have kept the dynamic PureBasic had in earlier years.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Bob Houle on March 07, 2016, 03:49:06 PM
Look... you said you thought you had found some buggy code and I said:
"Post it on the forum"

You then asked for a way to create a Main() program like PowerBASIC,
and I provided an answer.
--------------
QuoteDon't turn my words around, Bob.


Where is this coming from?  ???

It's obvious you don't like PureBasic. Or PBDev.

That's O.K.

Just move on.  :)

If you like things as they are with PowerBASIC... that's fine.

Just move on.  :)

But please stop bashing something you "think" you know (but don't)
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on March 09, 2016, 08:11:32 AM
Sometimes i believe i have violett glases on, or the other person has green.
But thats the world.

You then asked for a way to create a Main() program like PowerBASIC,

Can you show me where i asked that?
So i can find out who has the glases on :-)

I have clearly stated where i see the shortcomings.
Point - by point.

That does not mean i don't like PureBasic. Thats just your opinion.
Why is it not OK, to clearly tell the shortcomings of a computer-program?

There should not be any reason to take thios personal.
As i see it, there is a difference between somebody writing

QuoteXY is just bad

and somebody writing

QuoteXY missing some features that i am used to, and the person working on XY doesn't like to add these features

Where do you see the "bashing"?
So please stop insulting my clear criticism of openly visible facts as bashing.

I will still use PureBasic and also closely watch its developement.

Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Bob Houle on March 09, 2016, 02:52:30 PM
QuoteCan you show me where i asked that?
So i can find out who has the glases on :-)


Here...
Quote from: Theo Gottwald on March 05, 2016, 07:07:49 PM

PS:Do you know a trick how i can make PureBasic to compile a "Main File" like it can be set in the PowerBasic IDE?


Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Patrice Terrier on March 09, 2016, 03:28:22 PM
He he.

This is like when Theo, spoke of Windows 10, compared to Windows 2000  ;D

...
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: Theo Gottwald on March 09, 2016, 07:19:07 PM
Hahaha ... i guess we run from Missunderstanding to missunderstanding.
Have to say that the PureBasic IDE is very good even compared to any PowerBasic IDE.
(Other the Firefly or Phoenix because of the VD :-).

There is just one thing that i did not yet find out - but i think its in there.
In PureBasic I must currently first switch to the "main file" before i can press "Compile".
I believe this is my mistake - that was my question about "Main File".

You know i don't like Win 10 at all Patrice :-).

But i never said that i would not like PureBasic.

What do you think, do i  have "glasses on"?

It was in the year 2000 when i bought myself this so called C-Meter i guess it was about $400 or more.
In fact its some sort of "Lie detector".

It was the time when my last gf left me. When i got it, she was already gone.
Since then i had it in my cupboard.

This week i took it out and realized that it needs a "COM-Port" which no modern PC has.
And the Software was on a "Disk". But my Computer has no Disk drive.

Ok, so i got an RS232 to USB Adapter and also an old computer with Disc-Drive.
And funny enough - the thing still works. Even under Win 10.

And from what it shows, i would say that i speak the truth.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: David Roberts on November 02, 2016, 02:13:50 AM
I've had PureBasic for quite a while but I did not take to it. After reading through this thread I decided to have another go. There have been quite a few updates since my last look and was surprised to see a SHA3 plugin. What I embarked on stretched me no end but I got there in the end. Purists will no doubt frown at what I'm doing here but I am not a purist.

PureBasic dll saved to SHA3Hash.dll

UseSHA3Fingerprint()

ProcedureDLL.s SHA3_256( text$ )

  *Buffer = AllocateMemory( Len( text$ ) )
  If *Buffer
    PokeS(*Buffer, text$, -1, #PB_Ascii)
    SHA3$ = Fingerprint(*Buffer, MemoryStringLength(*Buffer, #PB_Ascii), #PB_Cipher_SHA3, 256)
    FreeMemory(*Buffer)
    ProcedureReturn SHA3$
  EndIf

EndProcedure

ProcedureDLL.s SHA3_512( text$ )

  *Buffer = AllocateMemory( Len( text$ ) )
  If *Buffer
    PokeS(*Buffer, text$, -1, #PB_Ascii)
    SHA3$ = Fingerprint(*Buffer, MemoryStringLength(*Buffer, #PB_Ascii), #PB_Cipher_SHA3, 512)
    FreeMemory(*Buffer)
    ProcedureReturn SHA3$
  EndIf

EndProcedure


PureBasic test

If OpenLibrary(0, "SHA3Hash.dll")
  Test$ = "Houses Of Parliament"
  MessageRequester("SHA3_256", PeekS(CallFunction(0, "SHA3_256", @Test$) ))
  MessageRequester("SHA3_512", PeekS(CallFunction(0, "SHA3_512", @Test$) ))
EndIf


PowerBASIC

#Compile Exe
#Dim All

Declare Function SHA3_256 Lib "SHA3Hash.dll" ( ByVal strText As WString ) As WString
Declare Function SHA3_512 Lib "SHA3Hash.dll" ( ByVal strText As WString ) As WString

Function PBMain
Local sText As WString

  sText = "Houses Of Parliament"
  MsgBox SHA3_256( sText )
  MsgBox SHA3_512( sText )

End Function


The PureBasic test and the PowerBASIC exe gave the same results. Just to be sure all was well I went to https://emn178.github.io/online-tools/ and got a confirmation on both SHA3-256 and SHA3-512.

So, PowerBASIC now has SHA3 without getting my hands dirty building a SHA3 engine.

Having got that working the next step will be a PureBasic library to create a hash, hash one or more blocks in and then finalize the hash. PureBASIC has the procedures to do that.

I then wrote a simple PowerBASIC dll with a view to using it in PureBasic. However, I am getting an 'Invalid memory access. (read error at address 0).

Would you look at it, Bob?

If I can get it to work there are a few other procedures that could be added to PB_String_Crunches.dll to give PureBasic a bit more 'oomph' in the string department.

PowerBASIC

#Compile DLL "PB_String_Crunches.dll"
#Dim All

Function PB_Remove_Any( ByVal MainString As String, ByVal MatchString As String ) Export As String

  Function = Remove$( MainString, Any MatchString )

End Function


PureBasic

Prototype.s ProtoPB_Remove_Any( param1$, param2$ )
If OpenLibrary( 0, "PB_String_Crunches.dll" )
  PB_Remove_Any.ProtoPB_Remove_Any = GetFunction( 0, "PB_Remove_Any" )
  s1$ = "Lo38ok2 Ma, n6o nu1mbe78rs!"
  s2$ = "0123456789"
  s3$ = PB_Remove_Any( s1$, s2$ )
  CloseLibrary(0)
EndIf



Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: David Roberts on November 02, 2016, 03:00:16 AM
'Dependency Walker' says I should have used PB_REMOVE_ANY but I'm still getting a memory access violation.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: David Roberts on November 03, 2016, 12:18:10 AM
OK, I managed PowerBASIC to PureBasic

I have managed it.

PowerBASIC code

#Compile DLL "PB_String_Crunches.dll"
#Dim All

Function RemoveAny( ByVal MainString As String, ByVal MatchString As String ) Export As WString
Local sText As WString

  sText = Remove$( MainString, Any MatchString )
  Function = sText

End Function


PureBasic code

Prototype.l ProtoRemoveAny( param1.p-bstr, param2.p-bstr )
If OpenLibrary( 0, "PB_String_Crunches.dll" )
  RemoveAny.ProtoRemoveAny = GetFunction( 0, "REMOVEANY" )
  s1$ = "Lo38ok2 Ma, n6o nu1mbe78rs!"
  s2$ = "0123456789"
  MessageRequester("", PeekS(RemoveAny( s1$, s2$ ) ))
  CloseLibrary(0)
EndIf


Resulting in: "Look Ma, no numbers!"


Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: José Roca on November 03, 2016, 01:44:41 AM
> PeekS(RemoveAny( s1$, s2$ )

I smell memory leaks. When are the temporary BSTRings freed?
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: David Roberts on November 03, 2016, 02:12:22 AM
I certainly cannot answer that.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: José Roca on November 03, 2016, 02:18:37 AM
> There are no BSTRings in PeekS(RemoveAny( s1$, s2$ )

Yes, there are. THREE!

> RemoveAny( s1$, s2$ ) is a pointer to the PowerBASIC's Wstring export and PeekS simply reads it.

...and does not free it.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: David Roberts on November 03, 2016, 02:51:04 AM
I gave it further thought and edited my last post before your last post.  :)

The PowerBASIC export is unicode to unicode so we only have two string format conversions; the parameters.

The ideal time to free up the bstr's is on receipt of the export as they are no longer needed then but how PureBasic does that I have no idea.

Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: José Roca on November 03, 2016, 03:14:51 AM
In the code that you have posted it is not freed.

Rules for allocating and releasing memory allocated for BSTRs.

- When you call into a function that expects a BSTR argument, you must allocate the memory for the BSTR before the call and release it afterwards.

- When you call into a function that returns a BSTR, you must free the string yourself.

- When you implement a function that returns a BSTR, allocate the string but do not free it. The receiving the function releases the memory.

See: https://msdn.microsoft.com/en-us/library/xda6xzx7.aspx
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: José Roca on November 03, 2016, 03:22:25 AM
Don't know what kind of code will generate that compiler, but I don't think that PeekS will release the BSTR. If I were you, I would ask it in the Pure Basic forum.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: David Roberts on November 03, 2016, 03:47:01 AM
QuoteIn the code that you have posted it is not freed.

It certainly isn't freed by me. I have no idea what PureBasic does but I should imagine that rule #1 applies.

I got the tip on 'p-bstr' from the PureBasic forums and I have seen the main coder, Fred as Theo refers to him, recommend it. It was my idea to use 'Export As WString'

QuoteI don't think that PeekS will release the BSTR

No, that is simply a reading function.

It seems to me that RemoveAny( s1$, s2$ ) by virtue of being prototyped is probably 'bracketed' by a conversion to bstr before and then a freeing up after as opposed to no 'bracketing' with no prototyping; but I am only guessing.
Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: José Roca on November 03, 2016, 04:58:43 AM
Regarding the p-bstr pseudotype, I only have found that it does an automatic conversion, i.e. it creates a BSTR that is passed to the called function, but nothing about what happens with these temporary bstrings. Maybe it will generate code to release them, but I don't know.

If it is passed by reference:

Quote
When a method returns a string (typically a BSTR one), it asks you to provide a pointer into which it will fill the string. Here no automatic conversion is supported. What you need to do here is pass a pointer to a long variable, which will be filled with the BSTR pointer. Then you can use PeekS() to read the string. Then do not forget SysFreeString() of course.

Example:

If MyObject\SomeMethod(@bstr_sting) = #S_OK
   Debug PeekS (bstr_string ,  -1, #PB_Unicode)
   SysFreeString_(bstr_string)
EndIf

Regarding the BSTR returned by the PowerBasic function, your Pure Basic prototype


Prototype.l ProtoRemoveAny( param1.p-bstr, param2.p-bstr )


treats it as a long value, so it doesn't really know if it is a BSTR or not.

Probably you will have to do something like


<long variable> = RemoveAny( s1$, s2$ )
PeekS <long variable>
SysFreeString <long variable>

Title: Re: PureBasic vs. PowerBasic (Bob's Opinion)
Post by: David Roberts on November 03, 2016, 10:14:28 AM
Quotetreats it as a long value, so it doesn't really know if it is a BSTR or not.

But I do - it is a Wstring.

<long variable> = RemoveAny( s1$, s2$ )
PeekS <long variable>
SysFreeString <long variable>


If it was a BSTR then the above would cause an access violation because PeekS, defaulting to reading unicode, would attempt to read a BSTR.

However, I now take your point about a memory leak.

If I changed back to 'Export as String', instead of 'Export as Wstring', then this works.

ptr.l = RemoveAny( s1$, s2$ )
MessageRequester( "", PeekS( ptr.l, -1, #PB_Ascii ) )
SysFreeString_( ptr.l )


The BSTR is now being read as Ascii and is then freed.

Alternatively, we could have

ptr.l = RemoveAny( s1$, s2$ )
s3$ = PeekS( ptr.l, -1, #PB_Ascii )
SysFreeString_( ptr.l )


The BSTR is read correctly and then converted to unicode.

Thanks, José.