Re: dynamically allocate array variable of type LPWSTR
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Fri, 31 Oct 2008 21:49:58 -0000
"Trups" <Samant.Trupti@xxxxxxxxx> wrote in message news:
Make sure you genuinely want a pointer to an LPWSTR. The LP is Microsoft's way of indicating that the type is already a pointer.
I want to dynamically allocate array variable of type LPWSTR.
Code looks like this...
main() {
LPWSTR *wstr;
int count = Foo (wstr);
for (int i = 0; i < count; i++)
//print each element;
}
int Foo(LPWSTR *wstr)
{
int count = 0;
while (!done){
//Here I need to allocate "wstr" one element by one element.
How
to do that?
// I don't know the count
count ++;
}
Where should I do delete?
However pointers to pointers are often useful. You use them for a list of strings, for example.
In C arrays decay into pointers when you pass them to functions. Pointers contain no size information. So you need to pass the buffer size separately.
There is no point passing an uninitialised pointer to a fucntion. C is call by value, so you are just passing garbage.
I can't determine exactly what you want to do from your code. However it looks like
int Foo(LPWSTR *ptr, int N)
{
int i;
for(i=0;i<N;i++)
ptr[i]= malloc(M * sizeof(WSTR));
}
where WSTR is whatever an LPWSTR points to, M is the number of them you want in your array.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
.
- References:
- Prev by Date: Re: opening jpeg file in c++
- Next by Date: Re: Doubts about free()
- Previous by thread: Re: dynamically allocate array variable of type LPWSTR
- Next by thread: (part 6) Han from China answers your C questions
- Index(es):
Relevant Pages
|