473,388 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

what is wrong with this

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
5 1425
> 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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike Henley | last post by:
I first came across rebol a while ago; it seemed interesting but then i was put off by its proprietary nature, although the core of the language is a free download. Recently however, i can't...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
28
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr();...
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
3
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
20
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
24
by: MU | last post by:
Hello I have some code that sets a dropdownlist control with a parameter from the querystring. However, when the querystring is empty, I get an error. Here is my code: Protected Sub...
2
by: mingke | last post by:
Hi... So I have problem with my if condition..I don't know what's wrong but it keeps resulting the wrong answer.... So here's the part of my code I have problem with: for (i=0; i<size2;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.