[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: varptr to structs returns bad pointer value


Oh yes, the problem confirmed.

This raises the error correctly:

Dim a As New myStruct
Print VarPtr(a)

The interpreter is confused, because there is a public declaration, which
is overdriven locally.


Jussi

On Mon, Mar 3, 2025 at 2:44 AM Jussi Lahtinen <jussi.lahtinen@xxxxxxxxx>
wrote:

> If I remember correctly structures cannot be declared locally, they must
> be at least private... so "mydata = new myStruct" might not be valid. And
> as Vuott said there is a missing keyword, which isn't even accepted within
> a function. So... maybe this just creates object instead of structure.
>
> Anyway, some error should be raised.
>
>
> Jussi
>
>
> On Mon, Mar 3, 2025 at 2:24 AM <vuott@xxxxxxxxxxxx> wrote:
>
>> He should try:
>>
>>
>> Private Extern myFunction(data As Pointer) In "mylib"
>>
>> Public Struct myStruct
>>     result As Long
>>     msg As String
>> End Struct
>>
>> Private myData As Struct Mystruct
>>
>> Public Sub doit2()
>>
>>   myFunction(VarPtr(myData))
>>
>> End
>>
>>
>> ----------------------------------------------------------------------------------
>>
>>
>>
>>
>>
>> 2 mar 2025, 22:43 da jussi.lahtinen@xxxxxxxxx:
>>
>>
>> No this does not pass the correct pointer, I am trying to pass a generic
>> structure, I want to use pointers.
>>
>> I see, it wasn't clear from the example code you gave.  I agree with your
>> implementation plan.
>>
>>
>> I am sorry but varptr(xxx)    should return a pointer to the actual
>> memory containing the structure.
>>
>> I agree, but this isn't in the documentation and it seems it is not
>> implemented [cannot find it under void SUBR_varptr(ushort code)
>> ]. For the reasons Benoit knows, this is not raising error either. I
>> don't know enough about the implementation details to say more.
>> Maybe this can be added.
>>
>> Jussi
>>
>>
>>
>>

References:
Re: varptr to structs returns bad pointer valueBrian G <brian@xxxxxxxxxxxxxxxx>
Re: varptr to structs returns bad pointer valueJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>
Re: varptr to structs returns bad pointer valuevuott@xxxxxxxxxxxx
Re: varptr to structs returns bad pointer valueJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>