1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PLUGININFO question

Discussion in 'Plugins' started by vefatica, Oct 3, 2009.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    Does it matter if PLUGININFO::pszFunctions ends with a comma?

    Thanks.
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    Isn't that cute!
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    Leading or trailing commas are ignored.

    But why would you want to?

    Rex Conn
    JP Software
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    On Sat, 03 Oct 2009 12:22:32 -0500, rconn <> wrote:

    |---Quote---
    |> Does it matter if PLUGININFO::pszFunctions ends with a comma?
    |---End Quote---
    |Leading or trailing commas are ignored.
    |
    |But why would you want to?

    I build the list dynamically. Without having to treat the first or last
    function name specially, I can do it with a simple loop.

    WCHAR *p = pluginfo.pszFunctions;
    for ( INT i=0; i<NUMBER_OF_ITEMS; i++ )
    p += Sprintf(p, L"%s,", item.Name);
    --
    - Vince
     
  5. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    You could do this instead:
    WCHAR *p = pluginfo.pszFunctions;
    for ( INT i=0; i<NUMBER_OF_ITEMS-1; i++ )
    p += Sprintf(p, L"%s,", item.Name);
    p += Sprintf(p, L"%s", item.Name);

    -Scott

    vefatica <> wrote on 10/03/2009 03:54:08 PM:


     
  6. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    Or alternatively:
    WCHAR *p = pluginfo.pszFunctions;
    p += Sprintf(p, L"%s", item[0].Name);
    for ( INT i=1; i<NUMBER_OF_ITEMS; i++ )
    p += Sprintf(p, L",%s", item.Name);

    -Scott

    samintz <> wrote on 10/05/2009 11:59:31 AM:



    last

     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    On Mon, 05 Oct 2009 10:59:34 -0500, samintz <> wrote:

    |You could do this instead:
    | WCHAR *p = pluginfo.pszFunctions;
    | for ( INT i=0; i<NUMBER_OF_ITEMS-1; i++ )
    | p += Sprintf(p, L"%s,", item.Name);
    | p += Sprintf(p, L"%s", item.Name);
    |

    Or even,

    WCHAR *p = pluginfo.pszFunctions;
    for ( INT i=0; i<NUMBER_OF_ITEMS; i++ )
    p += Sprintf(p, L"%s,", item.Name);
    *(p-1) == 0;

    But not having to bother saves 16 bytes of code (in either case).
    --
    - Vince
     
  8. Jim Cook

    Joined:
    May 20, 2008
    Messages:
    604
    Likes Received:
    0
    Although it is more code than nothing, this hack might be what you want as well

    WCHAR *p = pluginfo.pszFunctions;
    for ( INT i=0; i<NUMBER_OF_ITEMS; i++ )
    p += Sprintf(p, L"%s%c", item.Name, i==NUMBER_OF_ITEMS-1 ? '\0', ',');

    Or, perhaps more gawdawful, assuming TRUE/FALSE are 1/0:
    WCHAR *p = pluginfo.pszFunctions;
    for ( INT i=0; i<NUMBER_OF_ITEMS; i++ )
    p += Sprintf(p, L"%s%c", item.Name, ","[i>=NUMBER_OF_ITEMS-1]);


    On Mon, Oct 5, 2009 at 10:08 AM, vefatica <> wrote:





    --
    Jim Cook
    2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
    Next year they're Sunday.
     
  9. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    Here's an even simpler approach.

    Create your string by appending ",name" each time and when finished
    reference ptr[1] instead of ptr[0] as the start of the string.

    How does your code work? pszFunctions is a pointer not an array. Does
    Sprintf() allocate memory? If not, then you're writing over memory
    somewhere.

    You need to have an area of memory that gtes filled in by your routine.

    e.g.

    WCHAR names[500]; //room for 500 characters worth of names (roughly
    62 fcns x 8 chars)
    WCHAR *p = &names[0];
    for ( INT i=0; i<NUMBER_OF_ITEMS; i++ )
    p += Sprintf(p, L",%s", item.Name);
    pluginfo.pszFunctions = &names[1];

    -Scott


    Jim Cook <> wrote on 10/05/2009 01:53:15 PM:


     
  10. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    On Mon, 05 Oct 2009 13:18:40 -0500, samintz <> wrote:

    |Here's an even simpler approach.
    |
    |Create your string by appending ",name" each time and when finished
    |reference ptr[1] instead of ptr[0] as the start of the string.

    I like that.

    |How does your code work? pszFunctions is a pointer not an array. Does
    |Sprintf() allocate memory? If not, then you're writing over memory
    |somewhere.

    I allocate memory for pszFunctions (free it in ShutdownPlugin()). I didn't post
    that line.

    --
    - Vince
     

Share This Page