User Tag List

Results 1 to 8 of 8

Thread: String properties in extensions

  1. #1
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    String properties in extensions

    I'm trying to understand the code in the SDK help for the SetPropValue function:
    Code:
    case PROPID_TEXT:
            {
                // Gets the string
                LPSTR pStr = (LPSTR)((CPropDataValue*)pValue)->m_pData;
    
                // You can simply poke the string if your EDITDATA structure has a fixed size,
                // or have an adaptive size of structure like below
    
                // If the length is different
                if (strlen(pStr)!=strlen(edPtr->text))
                {
                    // Asks MMF to reallocate the structure with the new size
                    LPEDATA pNewPtr = (LPEDATA)mvReAllocEditData(mV, edPtr, sizeof(EDITDATA)+strlen(pStr));
                   
                    // If reallocation worked
                    if (pNewPtr!=NULL)
                    {
                        // Copy the string
                        edPtr=pNewPtr;
                        strcpy(edPtr->text, pStr);
                    }
                }
                else
                {    
                    // Same size : simply copy
                    strcpy(edPtr->text, pStr);
                }
            }
            break;
    What's specifically bothering me is how it reallocates the entire edit data structure for one string...what about the other values in there, and what if I have multiple strings (and I do)? I'm not sure what to do here because either reallocation deletes the old edit data structure so I can't copy the old stuff from it, or it doesn't and I can but then this code doesn't ever delete the old edit data structure.

    And either way, I'm still very confused about how this works - for instance, how does MMF2 know what to save and load with the MFA and how to do it? I've been looking through the way properties work and I still haven't figured out anything in terms of strings and other dynamic memory...
    Working as fast as I can on Fusion 3

  2. #2
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: String properties in extensions

    ReAlloc copies the old memory into the new one, and deletes the old one.

  3. #3
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: String properties in extensions

    And I think MMF just binary dumps the whole editdata struct (by default?), which is why this code reallocates the editdata of the object to include the string, and stores the string directly in the edit data.

  4. #4
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: String properties in extensions

    Eh, ok, that makes things more complicated, but I can manage it. Thanks for confirming my fears, Dynasoft
    Working as fast as I can on Fusion 3

  5. #5
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: String properties in extensions

    The editdata structure is indeed a nightmare when you introduce variable data. Especially when you introduce multiple sources of variable data.

  6. #6
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Oct 2016
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Resurrecting an old thread... I've been searching for a way to have multiple dynamic strings in my EDITDATA structure. Every attempt I've made ends up a mess or crashing CF. Does anyone have a working example of multiple dynamic strings in the EDITDATA structure and code in SetPropValue that works correctly?

  7. #7
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    @Rocnostic yes, for dynamically sized editdata I created an abstraction in EDIF:
    https://github.com/LB--/windows-edif...e/EditData.hpp
    https://github.com/LB--/windows-edif...Stream.hpp#L95
    https://github.com/LB--/windows-edif...if.h#L263-L294

    The basic idea is that you serialize everything somewhere (like a vector of int8_t) and then once you know the size, you ask Fusion to resize the editdata appropriately and then copy the data there. Your EDITDATA struct then just contains a dummy array, and the real data is in a class with design of your choice (see EditData.hpp).

    For multiple dynamic strings, you could have your class simply contain a vector of std::string objects, and then serialize and deserialize with whatever method you prefer (e.g. length terminated strings or null terminated strings).
    Working as fast as I can on Fusion 3

  8. #8
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Oct 2016
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so very much LB, I'm looking forward to seeing your solution. Once again, thank you for getting rid of that "brick wall" that I ran into.

Similar Threads

  1. Unable to change a string with the list obect if string contains three periods in row
    By redpandagames in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 4th January 2013, 03:01 PM
  2. Properties in Extensions
    By Jaffob in forum Extension Development
    Replies: 6
    Last Post: 1st February 2009, 11:47 AM
  3. Help with properties
    By z33z in forum Extension Developers Lobby
    Replies: 4
    Last Post: 1st March 2008, 01:26 PM
  4. Quick question about string extensions
    By Dines in forum Extension Development
    Replies: 21
    Last Post: 8th January 2008, 12:46 PM
  5. why cant i open the app properties
    By falkon in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 6th July 2006, 07:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •