Article View: borland.public.cppbuilder.nativeapi
Article #3413Re: Dynamically allocating an Array of type LOCALGROUP_MEMBERS_INFO_3
From: Remy Lebeau (TeamB)
Date: Wed, 21 Jun 2006 06:38
Date: Wed, 21 Jun 2006 06:38
54 lines
2497 bytes
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
Technical Details
Message-ID:
<4498eab1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4498d4d4@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,724ecf1877cbb66c X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4498d4d4@newsgroups.borland.com> Subject: Re: Dynamically allocating an Array of type LOCALGROUP_MEMBERS_INFO_3 Date: Tue, 20 Jun 2006 23:38:56 -0700 Lines: 56 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4498eab1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1150872241 68.69.17.41 (20 Jun 2006 23:44:01 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail