PLUGININFO question

May 20, 2008
12,167
133
Syracuse, NY, USA
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
 

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
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:


> 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
>
>
>
>
 

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
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:


> 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:
>
>
>
> ---Quote---
> > 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
> >
> >
> >
> >
> ---End Quote---
>
>
>
 
May 20, 2008
12,167
133
Syracuse, NY, USA
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
 
May 20, 2008
603
0
Sammamish, WA
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:

> 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
>
>
>
>
>




--
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.
 

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
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:


> 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:
>
>
> ---Quote---
> > 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
> >
> >
> >
> >
> >
> ---End Quote---
>
>
> --
> 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.
>
>
>
>
 
May 20, 2008
12,167
133
Syracuse, NY, USA
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
 

Similar threads