If OpenLibrary(0, "env.dll")
*env = CallFunction(0, "GetEnv", @n)
If *env
Dim env.s(n)
env() = *env
For i = 0 To n - 1
Debug env(i)
Next
EndIf
CloseLibrary(0) ; corrected
EndIf
here, everythings ok.
my question is (from the same DLL code) :
is the code below legal ? it works but is it really futur proof ?
Structure TABLE
s.s[0]
EndStructure
If OpenLibrary(0, "env.dll")
*env.TABLE = CallFunction(0, "GetEnv", @n)
If *env
For i = 0 To n - 1
Debug *env\s[i]
Next
EndIf
CloseLibrary(0)
EndIf
Last edited by Flype on Thu Jun 21, 2007 8:01 am, edited 1 time in total.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
but what if the memory is already allocated by using in the dll : 'Static Dim' it seems ok.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Running PB 4.10 B2 under Windows ME, the SECOND test code works perfectly, but the FIRST test, after outputting the results correctly, goes into a infinite loop with the last line (EndIf) repeatedly generating the error "Invalid memory access". This still happens even after adding the missing CloseLibrary(0) statement.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
as i can't see where this is the fault of the final programmer...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
You should consider the string array to be readonly though.
Because the Dll and main program will use different heaps for their string allocation,
modifying the strings from the main program could be trouble.
;DLL:
ProcedureDLL AttachProcess(instance)
Global Dim Array.s(5)
EndProcedure
ProcedureDLL.l CreateArray()
For i=0 To 5
Array(i)="Line "+Str(i)
Next
MessageRequester("dll point to:",Hex(@Array()))
ProcedureReturn @Array()
EndProcedure
;EXE:
Structure array
item.s[0]
EndStructure
If OpenLibrary(0,"dll_test.dll")
*var.array=CallFunction(0,"CreateArray")
MessageRequester("exe point to:",Hex(*var))
For i=0 To 5
MessageRequester("hi",*var.array\item[i])
Next
CloseLibrary(0)
EndIf
why 'env() = *env' is compiled without error if this is forbidden ?
what's the use... it's pretty dangerous to let guys like us to allow playing forbidden games
a debugger warning, or compiler error might be added.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
so i understood, and it's ok : env() = *env is not legal between pb-dll<-->pb-prog
but is it ok inside a standalone pb-prog (no dll stuff) ?
no legal in all case ?
(i'm wondering because 'it works' like a charm on the provided sample and on winxp).
Last edited by Flype on Thu Jun 21, 2007 8:25 pm, edited 1 time in total.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
why 'env() = *env' is compiled without error if this is forbidden ?
what's the use... it's pretty dangerous to let guys like us to allow playing forbidden games
a debugger warning, or compiler error might be added.
It's appears to be legal but it surely will cause you tons of problems.
Edit: Like, in real life it's not illegal to cut off your arm, but often you'll find yourself lacking an arm afterwards.