Struggling with Struct arrays

About Monkey 2 Forums Monkey 2 Programming Help Struggling with Struct arrays

This topic contains 6 replies, has 2 voices, and was last updated by  DruggedBunny 1 year, 3 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #12762

    DruggedBunny
    Participant

    Struct arrays are weird! Having to New them in the struct itself seems unintuitive (seems like more of a runtime thing), but although this seems to parse fine, it doesn’t run (“Failed to start process blah.exe”):

    (Tried hard-coding the value of MAX_PATH here — surprised that builds.)

    This was just me trying to figure out the Struct array syntax, but once I stick it into an Extern block, it fails to even parse, with “Error : Expecting string literal” on this line:

    My understanding is that just declaring the const in an Extern block will pick up the value from the .h imports, is that right?

    (Besides the syntax/apparent parse/run errors, do I need to declare an external struct like this, ie. am I going about this the right way?)

    #12763

    DruggedBunny
    Participant

    Oh, PROCESSENTRY32 — Short was my best guess for a TCHAR!

    MSDN

    #12766

    Mark Sibly
    Keymaster

    You can’t use mx2 arrays in an extern like that, because an mx2 array is NOT the same as a C array.

    The easiest way to handle C arrays is to use a Ptr instead of an array (in C, arrays ARE pointers), eg: change ‘int[32]’ to ‘Int Ptr’. You’ll still be able to access it via [] etc, but be aware that the compiler wont be able to sanity check static array sizes.

    As per the excellent unicode-for-all doc, I would suggest explicitly using Struct PROCESSENTRY32W, ie: the wide char version where TCHAR is ushort, something like…

    You don’t need to ‘New’ structs although it doesn’t really hurt.

    #12772

    DruggedBunny
    Participant

    OK, will give that a shot later. Didn’t even realise there were W versions of Win32 structs!

    #12783

    DruggedBunny
    Participant

    This revised version gives me “Translator.Trans() Internal Error”:

    This says…

    Turns out that’s the error the first version gave, it was just that the output was hidden.

    I get various different internal errors depending on what I do in Main with that last code…

    This builds OK, but obviously does nothing:

    New’ing produces a different error:

    Output for this is:

    … and adding the sizeof line gives the “Translator.Trans() Internal Error”:

    Tried without New as well, but assume that is needed… same Trans() error anyway…

    #12788

    Mark Sibly
    Keymaster

    The argument for sizeof  should be a value not a type, eg: libc.sizeof( proc ), but that error isn’t exactly helpful, will fix.

    #12789

    DruggedBunny
    Participant

    Cool, I had to not-New it, too (suspected so), but it’s working now with:

    Thanks!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.