Hi all!
How to use this class in a Static Library with multiple modules?
Here I am creating 2 modules:
1.bas:#Include "header.bi"
sub one(s as CWSTR)
? s
End Sub2.bas:#Include "header.bi"
sub two(s as CWSTR)
? s
End SubAnd also the header file
header.bi #Include Once "AFX/CWSTR.INC"
declare sub one(s as CWSTR)
declare sub two(s as CWSTR)I compile to a static library:
Quotefbc -lib 1.bas 2.bas
Next, I run the example:
#Include "header.bi"
#inclib "1"
one("one")
two("two")
sleepAnd I get errors:
Quote./lib1.a(1.o):fake:(.text+0x0): multiple definition of `AFX::CBSTR_ISBSTR(void*)@4'
G:\test\FBTEMP.o:fake:(.text+0x0): first defined here
./lib1.a(2.o):fake:(.text+0x0): multiple definition of `AFX::CBSTR_ISBSTR(void*)@4'
G:\test\FBTEMP.o:fake:(.text+0x0): first defined here
As I understand it, a class is assigned to each module (including the executable), and the compiler does not like duplicate definition. I've already broken my whole head :)
-----------------------------
If I take create the same files, but simplified:
1.bas:#Include "header.bi"
sub one(s as CWSTR)
? "One"
s.ws = "One String"
End Sub2.bas:#Include "header.bi"
sub two(s as CWSTR)
? "Two"
s.ws = "Two String"
End Subheader.bi:Type CWSTR extends WSTRING
ws as wstring*40
End Type
declare sub one(s as CWSTR)
declare sub two(s as CWSTR)example:#Include "header.bi"
#inclib "1"
dim as CWSTR sz
one(sz)
? Sz.ws
two(sz)
? Sz.ws
sleepEverything works here.
No idea. I never work with modules. My framework has been designed to work with source code and all the procedures are prefixed with the keywork PRIVATE, as it is the only way to have dead code removal with FreeBasic.
Quote from: José Roca on January 27, 2021, 08:48:59 AM
all the procedures are prefixed with the keywork PRIVATE
Not all. Here is an excerpt from the code:
' ========================================================================================
' // Checks if the passed pointer is a BSTR.
' // Will return FALSE if it is a null pointer.
' // If it is an OLE string it must have a descriptor; otherwise, don't.
' // Get the length in bytes looking at the descriptor and divide by 2 to get the number of
' // unicode characters, that is the value returned by the FreeBASIC LEN operator.
' // If the retrieved length if the same that the returned by LEN, then it must be an OLE string.
' ========================================================================================
FUNCTION CBSTR_IsBstr (BYVAL pv aS ANY PTR) AS BOOLEAN
IF pv = NULL THEN RETURN FALSE
DIM res AS DWORD = PEEK(DWORD, pv - 4) \ 2
IF res = LEN(*cast(WSTRING PTR, pv)) THEN RETURN TRUE
END FUNCTION
' ========================================================================================José! Can I edit the original CWStr.inc file and then use it in my project?
1) I need to remove the code of the CBSTR class that I do not need and leave only CWSTR
2) Rename file extension inc-> bi
------------------------------------
Of course, I'll leave the authorship reference in the code unchanged.
> Not all.
I will add to it.
> José! Can I edit the original CWStr.inc file and then use it in my project?
> 1) I need to remove the code of the CBSTR class that I do not need and leave only CWSTR
> 2) Rename file extension inc-> bi
Yes, as long as you don't make it incompatible with mine.