Page 1 of 1

Structure/EndStructure and embedded ascii strings (.s{})

Posted: Tue Sep 30, 2014 11:59 pm
by essess
Hello,

When compiling in unicode mode and trying to interface to an ascii based .dll I have a problem where structure offsets are modified for me (due to character width adjustments). I settled on this solution, but it seems too ugly for me and I was hoping that someone else could point out a solution I've overlooked:

Code: Select all

  Structure FT_DEVICE_LIST_INFO_NODE Align #PB_Structure_AlignC
    Flags.l
    Type.l
    ID.l
    LocId.l
  CompilerIf #PB_Compiler_Unicode
    SerialNumber.s{16/2}
    Description.s{64/2}
  CompilerElse
    SerialNumber.s{16}
    Description.s{64}
  CompilerEndIf
    ftHandle.i
  EndStructure
I'd really like to have some kind of capability like the following:

Code: Select all

    SerialNumber.a{16}
    Description.a{64}        ; or .b{} is fine too
where I can control character width explicitly instead of having the compiler do it for me.

Re: Structure/EndStructure and embedded ascii strings (.s{})

Posted: Wed Oct 01, 2014 12:45 am
by skywalk
Since native strings will always be 2bytes/char in unicode mode, so will fixed length strings.
Just store them as fixed byte arrays and use PeekS/PokeS.

Code: Select all

Structure _ft_device_list_info_node Align #PB_Structure_AlignC  ;{
  Flags.i
  Type.i
  ID.i
  LocId.l
  SerialNumber.b[16]
  Description.b[64]
  ftHandle.l
EndStructure  ;} FT_DEVICE_LIST_INFO_NODE;
Define._ft_device_list_info_node myFT
PokeS(@myft\SerialNumber[0],"Hello World23456", -1, #PB_Ascii)
ShowMemoryViewer(@myft\SerialNumber[0], 64)
Debug PeekS(@myft\SerialNumber[0], -1, #PB_Ascii)
CallDebugger

Re: Structure/EndStructure and embedded ascii strings (.s{})

Posted: Wed Oct 01, 2014 1:29 am
by essess
hmm..
I thought the .b[] suffix indicated dynamic allocation of an array ?

I assumed the above based on the example in the help:

Code: Select all

    ....
    y.w
    Name.s[10]  ; 10 Names available (from 0 to 9)
  EndStructure
If not, I think you just helped a whole lot!
ShowMemoryViewer() is neat too! (I'm new to PB)

Also, is there a way to check if something is being allocated behind the scenes so I can just test an assumption ?

Re: Structure/EndStructure and embedded ascii strings (.s{})

Posted: Wed Oct 01, 2014 2:21 am
by skywalk
[n] are static arrays of '0 to n-1' contents.
(n) are dynamic arrays of '0 to n' contents. Use Dim/ReDim.
essess wrote:Also, is there a way to check if something is being allocated behind the scenes so I can just test an assumption ?
Do you mean you don't know the contents of your dll's return variable?

Re: Structure/EndStructure and embedded ascii strings (.s{})

Posted: Wed Oct 01, 2014 6:09 pm
by essess
I was looking for a way to see whats allocated behind the scenes for me in case I can't figure out from docs/examples. Something like valgrind in the C world. If I 'leak' something because of bad assumptions, I'd like to figure it out without spending tons of time searching
or posing questions that would probably be of little interest.

If I had something like that, I could see when/if to use all of the various things like AllocateStructure/InitializeStructure/AllocateMemory, etc .... There is 0 documentation on use cases for those things and I need to experiment to answer my own questions - but I don't want to do it willy nilly. I guess I could disassemble them to figure it out too. You might be able to tell that, my 'native tongue' is C/asm where you have lots of control over memory OR the ownership of such things is clearly communicated.

In any case, my questions have been answered fully, thanks for your help!