Export PB functions in DLL with array input
Posted: Fri Jul 22, 2016 2:16 pm
I am playing around with writing some functions in PB and using them in LabVIEW. I keep crashing when accessing the functions that have have arrays in the prototype.
My guess is that arrays are not handled just as pointers in PB.
I get the following warnings but not much to go on in terms of documentation.
[08:31:03] [COMPILER] Line 1: Warning: List, Array and Map parameters can cause issue when exported with ProcedureDLL.
[08:31:03] [COMPILER] Line 1: Warning: List, Array and Map parameters can cause issue when exported with ProcedureDLL.
[08:31:03] [COMPILER] Line 1: Warning: List, Array and Map parameters can cause issue when exported with ProcedureDLL.
[08:31:03] Compilation succeeded with 3 warning(s).
I seen the DLLsample.pb and the part about "The declaration of arrays, lists or map with Dim, NewList or NewMap must always be done inside the procedure AttachProcess." I feel I am missing some key part of information.
I seen some code here http://forums.purebasic.com/english/vie ... p?p=201276 for accessing a point as an array. Would the correct procedure be to bring in the pointer and use a structure with an array element of correct bit size set to the size?
Hmmm this works just fine. I am toying around as I write this.
Is this the correct way to do this or a hack?
My guess is that arrays are not handled just as pointers in PB.
Code: Select all
ProcedureDLL Maskfunction(Array Image.u(1), Array mask.a(1), Array Result.i(1),count.i)
For x = 0 To count.i
If mask.a(x) & 1 > 0
Result.i(0) = Result.i(0) + Image.u(x)
EndIf
If mask.a(x) & 2 > 0
Result.i(1) = Result.i(1) + Image.u(x)
EndIf
If mask.a(x) & 4 > 0
Result.i(2) = Result.i(2) + Image.u(x)
EndIf
If mask.a(x) & 8 > 0
Result.i(3) = Result.i(3) + Image.u(x)
EndIf
If mask.a(x) & 16 > 0
Result.i(4) = Result.i(4) + Image.u(x)
EndIf
If mask.a(x) & 32 > 0
Result.i(5) = Result.i(5) + Image.u(x)
EndIf
Result.i(6) = Result.i(6) + Image.u(x)
Next
EndProcedure
[08:31:03] [COMPILER] Line 1: Warning: List, Array and Map parameters can cause issue when exported with ProcedureDLL.
[08:31:03] [COMPILER] Line 1: Warning: List, Array and Map parameters can cause issue when exported with ProcedureDLL.
[08:31:03] [COMPILER] Line 1: Warning: List, Array and Map parameters can cause issue when exported with ProcedureDLL.
[08:31:03] Compilation succeeded with 3 warning(s).
I seen the DLLsample.pb and the part about "The declaration of arrays, lists or map with Dim, NewList or NewMap must always be done inside the procedure AttachProcess." I feel I am missing some key part of information.
I seen some code here http://forums.purebasic.com/english/vie ... p?p=201276 for accessing a point as an array. Would the correct procedure be to bring in the pointer and use a structure with an array element of correct bit size set to the size?
Hmmm this works just fine. I am toying around as I write this.
Code: Select all
ProcedureDLL.i SumArray(*Array_ptr ,count.i)
sum.i
Structure MemoryArray
StructureUnion
Byte.b[0]
EndStructureUnion
EndStructure
*Array.MemoryArray = *Array_ptr
For x = 0 To count - 1
sum = sum + *Array\Byte[x]
Next
ProcedureReturn sum
EndProcedure