how to tell if BSTR var has been freed ?

General FreeBASIC programming questions.
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: how to tell if BSTR var has been freed ?

Post by deltarho[1859] »

A pity you couldn't bring across PowerBASIC macro capabilities.
It is, especially macro functions with local variables and return values. Once they are working they are amazing but they are not the easiest of constructs to debug.
Use wstring and zstring as parameters instead of Any Pointer.
Easier to read as opposed to @ all over the place.

Added: Looks like a FBIde formatting. For some reason wstring and zstring don't get caught. They are in a kw2 list rather than the main kw1 list. Don't know why. The poseidonFB method, Options>Tools>Convert Keyword Case>Mixedcase, captures everything and uses a similar method to FBIde with keyword0 to keyword3.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: how to tell if BSTR var has been freed ?

Post by Josep Roca »

In my WinFBX framework I have written classes to add dynamic unicode string support to FreeBasic: CWSTR and CBSTR.

CWSTR uses string builder techniques for speed and is the best option for general purpose.

CBSTR uses SysAllocString and I use it when I have to work with COM.

Example:

Code: Select all

'#CONSOLE ON
#include once "Afx/CWStr.inc"

DIM cbs AS CBSTR = "Дмитрий Дмитриевич Шостакович"

DIM f AS LONG = FREEFILE
OPEN "test.txt" FOR OUTPUT ENCODING "utf16" AS #f
PRINT #f, cbs
CLOSE #f

PRINT
PRINT "Press any key..."
SLEEP
Will also work if you change DIM cbs AS CBSTR to DIM cbs AS CWSTR.
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: how to tell if BSTR var has been freed ?

Post by deltarho[1859] »

Other: Have you read all the Windows APIs yet?
Me: No.
Other: How long will it take you, do you reckon?
Me: I will need to live to 185.
Other: Have you read all the classes in José Roca's WinFBX yet?
Me: No.
Other: How long will it take you, do you reckon?
Me: I will need to live to 143.
Other: And both?
Me: Haven't worked that one out.
Other: A team wrote the Windows APIs. Did a team write WinFBX?
Me: No, José wrote that on his own. There is a team at Microsoft trying to figure how the blazes he managed to do that. They have not come up with an answer yet.
Other: I understand that there is a WinFBX for both PowerBASIC and FreeBASIC.
Me: Correct. If I could write code at 5% of the speed of José I would be more than happy.
Other: If you could write code that fast you would leave me standing.
Me: I'd probably leave most people standing.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: how to tell if BSTR var has been freed ?

Post by dodicat »

Me: Er.. why do I have these huge feet?
Other: For walking through the desert, you can walk on the softest sand and not sink one inch, you can walk over the sharp desert stones and you won't feel anything.
Me: Why do I have these big long eyelashes?
Other: For the dust storms. You can walk through any dust storm, your eyes will be protected. others must seek shelter.
Me: Why do I have this big hump on my back?
Other: Stores and provisions. You can walk without food or water for a month easily, others would perish.
Me: Why are we in Calderpark zoo?
Other: Er ... ,I wonder if BSTR var has been freed??
Me: I really really hope so.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: how to tell if BSTR var has been freed ?

Post by Josep Roca »

> Other: Er ... ,I wonder if BSTR var has been freed??

Sure. The destructor of the class frees it (if that is what you're asking).
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: how to tell if BSTR var has been freed ?

Post by deltarho[1859] »

I am sorry to be the bearer of bad news but Calderpark Zoo closed in August 2003.

Humpy, as the camel was affectionately known as, was transferred to Edinburgh Zoo. It was not a happy move because Humpy's Glaswegian accent was so strong that the Edinburgh lot could not understand a word he said. Humpy passed away in March 2011.
Post Reply