Re: dynamically allocate array variable of type LPWSTR



Trups wrote:
I want to dynamically allocate array variable of type LPWSTR.

Two things here:
1. LPWSTR is not a standard type but part of the win32 API.
2. LPWSTR is a pointer type, hence the 'P'. In fact it's a typedef for
wchar_t*.

Code looks like this...


main() {

Well, check the FAQ on this one.

LPWSTR *wstr;
int count = Foo (wstr);

You are passing the value of an uninitialised variable to a function. If you
want the function to init the variable, you need to pass its address.

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 ++;
}

This looks as if you wanted to allocate an array of wchar_t strings.
However, I have actually no clue what it is that you really want.

Where should I do delete?

'delete' is a C++ thing, in C you would use malloc() and free().

Sorry, but there is too little to start with. I would suggest you get a good
book or some other tutorial that introduces you step by step to C. If
you're not familiar with programming at all, I would further suggest using
a language with less pitfalls, like e.g. Python.

Uli

.



Relevant Pages

  • Exception EntryPointNotFoundException
    ... BOOL BROWSE_API BrowseForData(HWND hwndOwner, LPWSTR defaultComment, LPWSTR ... public static extern int BrowseForData(IntPtr hwndOwner, ... defaultComment, string intialDir, StringBuilder path, int length); ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Cstring to Int conversions?
    ... standard type 'std::string' instead: ... struct three_ints ... int one; ... Complete, unambiguous specifications are critical. ...
    (comp.lang.cpp)
  • Re: dynamically allocate array variable of type LPWSTR
    ... int Foo(LPWSTR *wstr) ... Make sure you genuinely want a pointer to an LPWSTR. ... However pointers to pointers are often useful. ...
    (comp.lang.c)
  • Re: dynamically allocate array variable of type LPWSTR
    ... where WSTR is whatever an LPWSTR points to, M is the number of them you want ... in your array. ...
    (comp.lang.c)
  • Re: "(unsigned)" with long/int
    ... strip the signedness from the variable? ... 'long int', and 'signed long int' are all equivalent. ... implementations are identical. ...
    (comp.lang.c)