[Solved] AddFontMemResource confuses string functions

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

[Solved] AddFontMemResource confuses string functions

Post by Michael Vogel »

Used the AddFontMemRsource already a while ago, but didn't know about side effects...
...let's have a look at the output here, completely wrong results after loading the font!

----------
150
10010110
4
*00*0**0
----------
----------
150
10010110
0
10010110
----------


How to repair the following code that it will do the right thing?

Code: Select all

Global zlist.q
Global n


#InternalFont=1
#InternalFontFile="C:\windows\fonts\wingding.ttf"


zlist=16+128+6
Debug "----------"
Debug zlist
Debug Bin(zlist)
n=CountString(Bin(zlist),"1")
Debug n
Debug ReplaceString(Bin(zlist),"1","*")
Debug "----------"
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

CompilerIf #InternalFont

	Global HuiiFont=AddFontMemResourceEx_(?FontDataStart,?FontDataEnd-?FontDataStart,0,@"1")

	DataSection
		FontDataStart:
		IncludeBinary(#InternalFontFile)
		FontDataEnd:
	EndDataSection

CompilerEndIf

zlist=16+128+6
Debug "----------"
Debug zlist
Debug Bin(zlist)
n=CountString(Bin(zlist),"1")
Debug n
Debug ReplaceString(Bin(zlist),"1","*")
Debug "----------"
Last edited by Michael Vogel on Tue Jan 19, 2021 7:08 pm, edited 1 time in total.
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: AddFontMemResource confuses string functions

Post by fryquez »

AddFontMemResourceEx_(?FontDataStart,?FontDataEnd-?FontDataStart,0,@"1")

What are you doing with the last parameter :shock:
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: AddFontMemResource confuses string functions

Post by Michael Vogel »

Good question, typical copy and paste error :)
I thought, it's the number of the fonts which should be added, instead it's an *integer to show the number of successfully added fonts.
Changing that doesn't confuse the system anymore. Anyhow weird, isn't it?
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: [Solved] AddFontMemResource confuses string functions

Post by fryquez »

Actually bad thing is that PB store these strings in a write able section of the program.
If it would do it correctly, a simple crash would happen and no wired things would show up at some other place in the program.
infratec
Always Here
Always Here
Posts: 6869
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [Solved] AddFontMemResource confuses string functions

Post by infratec »

According to this:
https://docs.microsoft.com/en-us/window ... resourceex

I would do it like this:

Code: Select all

Define NumFonts.l = 1
Global HuiiFont=AddFontMemResourceEx_(?FontDataStart,?FontDataEnd-?FontDataStart,0,@NumFonts)
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: [Solved] AddFontMemResource confuses string functions

Post by Michael Vogel »

infratec wrote:

Code: Select all

Define NumFonts.l = 1
Global HuiiFont=AddFontMemResourceEx_(?FontDataStart,?FontDataEnd-?FontDataStart,0,@NumFonts)
Nearly what I do now, but without initializing NumFonts which will get the result of added resources.
fryquez wrote:Actually bad thing is that PB store these strings in a write able section of the program.[...]
That's why I did the post - wrote a program which controls all lights in my house and a certain function failed to work yesterday. Took some time to find that n=CountString(Bin(app\run\watchdog),"1") has been zero, took much more time to see that the error in line 6984 is connected to the font part which is done at the program start (around line 400)...
...and here's where I must have copied the code line some years ago...
Post Reply