home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,739 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: C API needs array of C strings, what   
   13 Dec 11 21:31:49   
   
   From: daniel.kruegler@googlemail.com   
      
   Am 13.12.2011 22:41, schrieb Fredrik Staxeng:   
   > WWSAPI represents an array of strings as (WCHAR **array, int count).   
      
   For non-Windows users: WCHAR is a typedef for wchar_t   
      
   > I need to allocate temporary storage for the array, and for the converted   
   > strings. Like this:   
   >   
   >           array = new WCHAR *[count];   
      
   OK, this creates an array of wchar_t pointers. Written as std::vector,   
   this would be std::vector of size equal to 'count' (lets name   
   it v for the moment). Assuming that 'count' is different from zero,   
   &v.front() has type wchar_t**.   
      
   >           for(int i = 0; i<  n; ++i)   
   >                   array[i] = widen(get_input(i));   
      
   I don't understand what is going on here: What is the semantics of   
   widen? Note that this is important to understand, because the actual   
   array does not provide the storage for the wchar_t elements, it only has   
   room to store address values. So widen must return a valid address value   
   - where is the storage allocated? I must assume that somehow there must   
   exist the moral equivalent of an object of std::vector which   
   contains the actual values.   
      
   > What data structure should I use? I can use std::vector for the array,   
   > but what do i put in it? Note that it is passed to C, so the memory   
   > layout has to be the same.   
      
   It seems as if your problem is unreleated to std::vector. Irrespective   
   of what (sequential) container you use for holding the wchar_t* values,   
   you need some further storage room for the actual wchar_t objects that   
   are referenced by the former container. For simplicity we can think of a   
   further std::vector to hold these, but different storage rooms   
   are possible.   
      
   > I can use the subset of C++11 supported by Visual 2010, and boost.   
      
   With the information that you provided us, there is not much to say more:   
      
   1) Ensure that memory exists for 'count' objects of wchar_t, e.g.   
   create an object std::vector w of size 'count' and fill that   
   with the   
   corresponding values.   
      
   2) Create an object std::vector v of size 'count' that points   
   to the 'count' wchar_t objects within the former container w.   
      
   3) Provide &v.front() as argument to you C function.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca