PB Strings from OBJ/LIB
Posted: Sat Dec 31, 2016 5:21 pm
Hi to all,
I'm not often here because I think that my use of PureBasic is not very interesting as you will see below.
In most of my projects I use helper functions compiled in an object file (C language).
Sometimes I need to return a PB String from a function but I do not want to write a UserLib for it, as this functions are project specific.
So, I'm using this PB code: (the C code is almost the same as for an UserLib)
When PureBasic calls a function that returns a string from my conventional UserLibs, this is the ASM code:
When PureBasic calls a function that returns a string from a .LIB/.OBJ file, this is the ASM code:
So, I have to add the line '!PUSH dword [_PB_StringBasePosition]' and all is OK.
Is it normal or is it a PB bug?
I'm not often here because I think that my use of PureBasic is not very interesting as you will see below.
In most of my projects I use helper functions compiled in an object file (C language).
Sometimes I need to return a PB String from a function but I do not want to write a UserLib for it, as this functions are project specific.
So, I'm using this PB code: (the C code is almost the same as for an UserLib)
Code: Select all
EnableExplicit
Prototype.s ProtoGetString()
Import "CUtils.obj"
GetString(a.l) ; 'a.l' is here for the 'PrevPosition' parameter
EndImport
Global StrTest.ProtoGetString, s1.s
StrTest = @GetString()
!PUSH dword [_PB_StringBasePosition] ; without this I get a memoty access error (see below).
s1 = StrTest()
Debug s1
Code: Select all
; s1 = StrTest()
MOV edx,[_PB_StringBasePosition]
PUSH edx
PUSH edx
CALL _PB_StrTest_UNICODE@4
PUSH dword v_s1
CALL _SYS_AllocateString4@8
Code: Select all
; s1 = StrTest()
PUSH dword [_PB_StringBasePosition]
CALL dword [v_StrTest]
PUSH dword v_s1
CALL _SYS_AllocateString4@8
Is it normal or is it a PB bug?