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

Just starting out? Need help? Post your questions and find answers here.
essess
New User
New User
Posts: 9
Joined: Wed Jan 15, 2014 4:07 am

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

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 4303
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
essess
New User
New User
Posts: 9
Joined: Wed Jan 15, 2014 4:07 am

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

Post 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 ?
User avatar
skywalk
Addict
Addict
Posts: 4303
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post 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?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
essess
New User
New User
Posts: 9
Joined: Wed Jan 15, 2014 4:07 am

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

Post 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!
Post Reply