473,466 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C# - C Interop

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
Nov 16 '05 #1
4 1533
Hi Germic,

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

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

"Germic" <sy**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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

Nov 16 '05 #2

"Germic" <sy**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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.

Nov 16 '05 #3
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?
Nov 16 '05 #4
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.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: roy | last post by:
I try to call com written in VB 6.0. When I use VS.net Studio to do the debuging, some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation'...
0
by: roy | last post by:
I try to call com written in VB 6.0., some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation' Application....
0
by: keefah | last post by:
Hi, I'm writing a C# web app that uses Outlook to send email. I use a reference to the Microsoft Outlook 11.0 Object Library, but it's giving me problems. I tracked down some stuff on the Net...
0
by: lacour | last post by:
I can't seem to figure out the difference between adding a COM dll reference in VS2003 and by using TLBIMP. I have a COM dll that references another COM dll, and I want the syntax of my...
1
by: Nadav | last post by:
Hi, Introduction *************** I have a system build of a collection of 'Native COM objects' and '.NET COM interop' objects, all of the COM objects are managed through a 'Native COM' layer,...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
7
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
2
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
0
by: Tina | last post by:
I've gotten this before where it says there is a problem with Interop.MSDASC but I can't remember what causes this. This is a 1.1 app I'm trying to debug in vs2005. It was running yesterday just...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.