PC Review


Reply
Thread Tools Rate Thread

C# - C Interop

 
 
Germic
Guest
Posts: n/a
 
      6th Jan 2005
Hi,

I need to pass a reference to a string between a C and C# library.

I declare the string in C# function as ref String xyz and the corresponding
C code would refer to it as BSTR *xyzz. However i get an error as i feel the
string is not marshalled properly.

What is the correct way to do this?

Thanks


 
Reply With Quote
 
 
 
 
Joe Mayo
Guest
Posts: n/a
 
      6th Jan 2005
Hi Germic,

Try using a System.Text.StringBuilder instead of ref string.

Joe
--
http://www.csharp-station.com

"Germic" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I need to pass a reference to a string between a C and C# library.
>
> I declare the string in C# function as ref String xyz and the
> corresponding
> C code would refer to it as BSTR *xyzz. However i get an error as i feel
> the
> string is not marshalled properly.
>
> What is the correct way to do this?
>
> Thanks
>
>



 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      6th Jan 2005

"Germic" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I need to pass a reference to a string between a C and C# library.
>
> I declare the string in C# function as ref String xyz and the
> corresponding
> C code would refer to it as BSTR *xyzz. However i get an error as i feel
> the
> string is not marshalled properly.
>
> What is the correct way to do this?
>
> Thanks
>
>

If the function is not a COM interface method you have to tag the argument
with a MarshalAs attribute:

[MarshalAs(UnmanagedType.BStr)]ref string s

Willy.



 
Reply With Quote
 
Germic
Guest
Posts: n/a
 
      7th Jan 2005
I've been trying to find a solution for quite sometime. Hope this time
someone could help.

I query a webservice from a C DLL through a C# Library. The webservice
returns an XML file which contains an array of array. Now, my C DLL can
consume only 1 array at a time. So the first hit from the C DLL to the C#
Library gets the whole bunch of data from the webservice and gives the C DLL
just the first array of data. On the next call from the C DLL to the C#
library, the C# library has to give the next array of data from the XML
string it has previously received from the webservice.

I've tried parsing the XML and putting it in a hashtable, but i am not able
to pass the address of the hashtable between the C and C# functions as a
parameter (&, ref). How can I create a reference to hashtable in C???

I'm trying to pass the whole XML string back and forth. Object at C# end and
VARIANT at C end. Then i parse the XML string into a dataset and put it into
a foreach loop everytime, get the hit-number from the C DLL and run a
counter within the foreach loop till it matches and then put the data in the
array onto a structure to be returned to the C DLL.

Is there any better way to do it?


 
Reply With Quote
 
Germic
Guest
Posts: n/a
 
      10th Jan 2005
never mind.. tried using VARIANT at the C end and OBJECT at the C# end,
seems to work fine!

Thanks anyway. Any other suggestions is welcomed.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interop.CDO uses Interop.ADODB which has a higher version... muriwai Microsoft C# .NET 7 27th Oct 2011 08:00 PM
Interop Ira Davis Microsoft Dot NET 1 29th Oct 2008 09:46 PM
Using .NET 1.1 via interop from .Net 2.0 schaf Microsoft C# .NET 0 9th Jun 2008 12:07 PM
Is there a published COM Interop Wrapper for Interop.MSDASC.dll? Burton G. Wilkins Microsoft ADO .NET 0 10th Nov 2003 01:57 AM
COM Interop Abhi Microsoft C# .NET 1 25th Sep 2003 08:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:25 AM.