converting string:array to tchar** , wchar_t**

  • Thread starter Thread starter diDE
  • Start date Start date
D

diDE

I want to convert a managed string array
f.e. array<string^>^ Texts; // Elements 0: "ABC", 1: "HJO"
to a TCHAR** or wchar_t**

any ideas?
 
diDE said:
I want to convert a managed string array
f.e. array<string^>^ Texts; // Elements 0: "ABC", 1: "HJO"
to a TCHAR** or wchar_t**

Why the double indirection? If you can settle for a simple pointer try this:

wchar_t __pin *pStr;

pStr = PtrToStringChars(s);

Otherwise, I _guess_ you'd have to copy the data to your own allocation if
you really need the double indirection.

Regards,
Will
 
Why the double indirection? If you can settle for a simple pointer try this:

a function from a dll is asking für this datatype
and i'm trying to write a wrapper in managed code.

the wrapper is called from c# code
with a string array
how would it work to put the data in an own allocation?
 
diDE said:
a function from a dll is asking für this datatype
and i'm trying to write a wrapper in managed code.

I see.
how would it work to put the data in an own allocation?

Like this, for example:

include <vcclr.h>
#include <iostream>
#using <mscorlib.dll>
using namespace System;

int main()
{
int len;
wchar_t *ps, **pps;
wchar_t __pin *p;

String *s = "This is my string.";

// Get a pointer to the string array
// Determine its length

p = PtrToStringChars(s);
len = s->Length;

// Allocate an array of wide characters

ps = new wchar_t[len + 1];

// Copy the string to the array

for (int i = 0; i < len; i++ )
ps = p;

ps[len] = 0;

// Just for fun

printf("%S\n", ps);

// Allocate a pointer to a pointer

pps = new wchar_t *;

// Make it point to something

pps = &ps;

return 0;
}

As always, do not forget to delete (or delete []) what you allocate.

Regards,
Will
 
Back
Top