🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages Started by Maurice Anderson Wed, 21 Jun 2006 05:10
Dynamically allocating an Array of type LOCALGROUP_MEMBERS_INFO_3
#3412
Author: Maurice Anderson
Date: Wed, 21 Jun 2006 05:10
19 lines
1528 bytes
Hello, as you can see a I am adding two users to local group Test.  I have 
"info" defined as a array with two elements of type 
LOCALGROUP_MEMBERS_INFO_3.

I want to somehow allocate the number of elements dynamically depending on 
the amount of users I want to add to the group.

void __fastcall TMDIChild::Test1Click(TObject *Sender)
{
 int a = 0; LOCALGROUP_MEMBERS_INFO_3 info[2];

 info[0].lgrmi3_domainandname = L"Administrator";
 info[1].lgrmi3_domainandname = L"guest";

 Memo1->Lines->Add(String(NetLocalGroupAddMembers(NULL, L"Test", 3, 
(LPBYTE)&info2, 2)));
}

How could I do that? 
Re: Dynamically allocating an Array of type LOCALGROUP_MEMBERS_INFO_3
#3413
Author: Remy Lebeau (TeamB)
Date: Wed, 21 Jun 2006 06:38
54 lines
2497 bytes
"Maurice Anderson" <mauriceanderson@hotmail.com> wrote in message
news:4498d4d4@newsgroups.borland.com...

> Hello, as you can see a I am adding two users to local group Test.
> I have "info" defined as a array with two elements of type
> LOCALGROUP_MEMBERS_INFO_3.
>
> I want to somehow allocate the number of elements dynamically
> depending on the amount of users I want to add to the group.

Use the 'new[]' operator, ie:

    void __fastcall TMDIChild::Test1Click(TObject *Sender)
    {
        WideString members[] = {L"Administrator", L"guest"};
        AddGroupMembers("Test", members, 2);
    }

    void __fastcall TMDIChild::AddGroupMembers(const WideString &Group,
WideString *Members, int Count)
    {
        LOCALGROUP_MEMBERS_INFO_3 *info = new
LOCALGROUP_MEMBERS_INFO_3[Count];

        for(int i = 0; i < Count; ++i)
            info[i].lgrmi3_domainandname = Members[i];

        NetLocalGroupAddMembers(NULL, Group, 3, (LPBYTE)info, Count);
        delete[] info;
    }

Alternatively, the Win32 API approach is to use LocalAlloc() or
GlobalAlloc(), ie:

    void __fastcall TMDIChild::AddGroupMembers(const WideString &Group,
WideString *Members, int Count)
    {
        LOCALGROUP_MEMBERS_INFO_3 *info = (LOCALGROUP_MEMBERS_INFO_3*)
LocalAlloc(LMEM_FIXED, sizeof(LOCALGROUP_MEMBERS_INFO_3) * Count);

        if( info )
        {
            for(int i = 0; i < Count; ++i)
                info[i].lgrmi3_domainandname = Members[i];

            NetLocalGroupAddMembers(NULL, Group, 3, (LPBYTE)info, Count);

            LocalFree(info);
        }
    }


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads