Page 1 of 1

How to Get the Pointer of a Map to pass it to a Prototype

Posted: Mon Jan 12, 2026 6:03 pm
by SMaag
I try to use the PB SDK Functions from Map.h
But I can't get the Pointer of the Map correctly.

Here is the code what shows what I try to do! (It's just a proof of concept to learn what is possible!)

Code: Select all


EnableExplicit

Prototype Map_Hash(*Str)
Global Map_Hash.Map_Hash

Prototype Map_HashCaseInsensitive(*Str)
Global Map_HashCaseInsensitive.Map_HashCaseInsensitive

Prototype Map_FindNumericMapElement(*PB_Map, intKey)
Global Map_FindNumericMapElement.Map_FindNumericMapElement

Prototype AddNumericMapElement(*PB_Map, intKey);
Global AddNumericMapElement.AddNumericMapElement

; to find the defintions of this SDK Functions you have to 
; go to PureBasic\SDK\[C, ViusalC]\PureLibraries. There you
; can find the offical C-Header files!

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Import ""     
    ; Map.h
    PB_Map_Hash(*Str)
    PB_Map_HashCaseInsensitive(*Str)
    PB_FindNumericMapElement(*PB_Map, intKey)
    PB_AddNumericMapElement(*PB_Map, intKey);
  EndImport
  
CompilerElse
  ImportC ""      
    ; Map.h
    PB_Map_Hash(*Str)
    PB_Map_HashCaseInsensitive(*Str)
    PB_FindNumericMapElement(*PB_Map, intKey);
    PB_AddNumericMapElement(*PB_Map, intKey);
  EndImport
  
CompilerEndIf

Map_Hash = @PB_Map_Hash()
Map_HashCaseInsensitive = @PB_Map_HashCaseInsensitive()
Map_FindNumericMapElement = @PB_FindNumericMapElement()
AddNumericMapElement = @PB_AddNumericMapElement()


NewMap City.s()
; how to get the Map-Pointer correctly???

; Define *pCity = City()  ; Error "Trying to write a String into a numerical value"
Define *pCity = @City()   ; Error "The Map doesn't have a current Element!"

Define c1.s = "London"
Define c2.s = "Berlin"
Define c3.s = "Tokio"
Define c4.s = "Rom"
Define c5.s = "Barcelona"

City(c1) = c1 
City(c2) = c2
City(c3) = c3
City(c4) = c4
City(c5) = c5


ForEach City()
  Debug City()  
Next

Define hash
Define *res.String

hash = Map_HashCaseInsensitive(@c1)
Debug hash

; how to pass the Map-Pointer correctly???
*res = Map_FindNumericMapElement(*pCity, hash)    ; ???
*res = Map_FindNumericMapElement(City(), hash)    ; Don't work!!!
Debug *res\s	;  Expect to see "London"


Re: How to Get the Pointer of a Map to pass it to a Prototype

Posted: Mon Jan 12, 2026 9:01 pm
by idle
I did a numericmap here
viewtopic.php?t=74214
or you can use squint3
viewtopic.php?t=79453

Re: How to Get the Pointer of a Map to pass it to a Prototype

Posted: Mon Jan 12, 2026 9:43 pm
by SMaag
Tanks! Puuh! A lot to sudy!