Page 1 of 1

List, Array and Map parameters can cause issue when exported

Posted: Fri Jun 04, 2010 11:37 pm
by luis
"List, Array and Map parameters can cause issue when exported with ProcedureDLL"

This is a warning from the compiler, at least in 4.50RC2

The procedure is declared as:

Code: Select all

ProcedureDLL .i DummyProcName (Array DummyArray(1)) 
Can anyone please explain what the warning means ?

Has this to do only with the following remark from the manual ?
HELPFILE wrote: - The declaration of arrays, linked lists or map with Dim, NewList or NewMap must always be done inside the procedure AttachProcess
or there is more ?

Is there a problem in declaring an Array() in a PB client program and pass it to a DLL procedure as in the declaration above ?

Thanks.

Re: List, Array and Map parameters can cause issue when expo

Posted: Sun Jun 06, 2010 6:38 pm
by Trond
From what I can understand, it's related to memory allocation. The dll and the main program have separate string and memory heaps. If you try to resize the array, or reassign strings/map elements in it, things will not be ok. So they are all read-only except for the modification of numeric values. But that's only the theory, I don't know if there any practical issues in the implementation that would make reading troublesome too.

Re: List, Array and Map parameters can cause issue when expo

Posted: Sun Jun 06, 2010 7:27 pm
by Josh
i think, array, lists and maps are pb-specific. any other programm, not written in pb will have problems with this parameters, when using your dll.

Re: List, Array and Map parameters can cause issue when expo

Posted: Sun Jun 06, 2010 8:34 pm
by luis
@trond

I tried to pass back and forth a global array from/to a client/dll and it seem to work ok.

As you wrote, the problem arise if it try to modify the array contents.

I hope this is what the warning from the compiler was about.

If Fred / freak can clarify this beyond any doubt would be nice...

Thanks.

@josh

Yes, I was talking from a PB-only point of view... certainly another language cannot be expected to understand specific PB data structures.

Re: List, Array and Map parameters can cause issue when expo

Posted: Thu Feb 24, 2011 6:00 pm
by TO7
I know it's an old thread, but how replace

Code: Select all

ProcedureDLL TheFunction(Array Tablo.DirectoryEntry(1))
and

Code: Select all

ProcedureDLL TheFunction(Array Tablo.s(1))
if obviously, it's not the same thing

Thanks

Re: List, Array and Map parameters can cause issue when expo

Posted: Mon Aug 10, 2020 5:42 pm
by Little John
I've got a similar question as luis had about 10 years ago. :-)

PB 5.72 LTS still raises the same compiler warning in this context.

I would like to create a DLL with PB 5.72 that contains a procedure with a linked list as parameter. The main EXE program (also compiled with PB 5.72) should call the procedure in the DLL, that procedure should create elements in the linked list and populate them. Then the main program should read the contens of the linked list.

Something that essentially works like this:

Code: Select all

; PB 5.72 LTS

; ----------------------------------------------
;-- DLL

ProcedureDLL Foo (List myList$())
   ClearList(myList$())
   AddElement(myList$()) : myList$() = "one" 
   AddElement(myList$()) : myList$() = "two" 
   AddElement(myList$()) : myList$() = "three" 
EndProcedure
; ----------------------------------------------


; ----------------------------------------------
;-- Main program

NewList bar$()

Foo(bar$())
ForEach bar$()
   Debug bar$()
Next   
; ----------------------------------------------
Is that possible?

What does the compiler warning
List, Array and Map parameters can cause issue when exported with ProcedureDLL
exactly mean?
luis wrote:If Fred / freak can clarify this beyond any doubt would be nice...
Yes, please. :-)

Re: List, Array and Map parameters can cause issue when expo

Posted: Mon Aug 10, 2020 10:12 pm
by netmaestro
I suspect the potential issue would appear in the event that a PB coder makes a dll that exports lists arrays or maps and the calling program is not PureBasic. Apart from that I see nothing to worry about.

Re: List, Array and Map parameters can cause issue when expo

Posted: Wed Aug 12, 2020 11:11 am
by Little John
Hello netmaestro,

thank you for your answer!
The tests I did went well, but because of the warning I thought I just might have been lucky so far.
That statement from you as someone who has very profound knowledge in computer programming and also specifically with PureBasic gives me more trust.
Many thanks again!