By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,763 Members | 1,464 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,763 IT Pros & Developers. It's quick & easy.

what is wrong with this

P: n/a
gs
I want to pass a string array to C which uses ansi

in a test, I tried:
unsafe public int ctstAny1dp(String*[] strOut)
{
private string[] strMyC = {
"abcdef string 1",
"abcdef string 2",
"abcdef string 3",
"abcdef string 4",
"abcdef string 5"},
str2 = { "str2_1", "str2 2" };
// the above will be replaced by some other processing in production

// can't implicitly convert: strOut = strMyC;
for (int i = 0; i < strMyC.GetUpperBound(0); i++)
{
strOut[i] =
((Marshal.StringToHGlobalAnsi(strMyC[i])).ToPointer()); };
return strMyC.GetUpperBound(0) + 1;
}

the above won't compile: Error 1 Cannot implicitly convert type 'void*' to
'string*'. An explicit conversion exists (are you missing a cast?)
D:\data\Ieproj\dotnet\IeStringClass\C#\ieStringCS\ ieStringCS\ieString.cs 99
26 ieStringCS
I thought I am getting a pointer to the string.

Is there a better way
May 19 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> strOut[i] =
((Marshal.StringToHGlobalAnsi(strMyC[i])).ToPointer()); };


This:

((Marshal.StringToHGlobalAnsi(strMyC[i])).ToPointer());

returns a void* , you need to cast it to String*
May 19 '06 #2

P: n/a
gs
Thx
but if I do this
strOut[i] = (String*)
((Marshal.StringToHGlobalAnsi(strMyC[i])).ToPointer());

I get
Error 1 Cannot take the address of, get the size of, or declare a pointer to
a managed type ('string')
D:\data\Ieproj\dotnet\IeStringClass\C#\ieStringCS\ ieStringCS\ieString.cs 100
26 ieStringCS

"PIEBALD" <PI*****@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
strOut[i] =
((Marshal.StringToHGlobalAnsi(strMyC[i])).ToPointer()); };


This:

((Marshal.StringToHGlobalAnsi(strMyC[i])).ToPointer());

returns a void* , you need to cast it to String*

May 20 '06 #3

P: n/a
Then you'll need someone better at it than I. Chances are you shouldn't be
producing an array of string pointers.

What is it you're trying to accomplish anyway?
May 22 '06 #4

P: n/a
gs
I am just trying to find a way to pass via com interface to native
application caller a string array.

The desired native calling protocol is
// setup and connect muyoleobj to the c# com class..
// ...
string [] mystrArray[]
myoleobj.ctstAny1dp(mystrArray)

"PIEBALD" <PI*****@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
Then you'll need someone better at it than I. Chances are you shouldn't be
producing an array of string pointers.

What is it you're trying to accomplish anyway?

May 22 '06 #5

P: n/a
Well I don't do COM, but I expect what you want is one method that handles
both the converting and the calling.
May 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.