473,476 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Passing String from C++ DLL to C#

1 New Member
Hi,

I've got a C++ DLL and a C# GUI. The DLL gets a value and then needs to pass it back to the C# program in the form of a string.

I know this is probably a glaringly simple thing to achieve but it's escaping me at the moment.

I want something simple like this, a function that I can call from the C# part of my program that returns a string that I can then print to file/messagebox or whatever:

extern "C" __declspec(dllexport)
string DataToReturn()
{
string test="TEST";
return test;
}

I've tried a few combinations of char/string etc but seem to always come accross access violation exceptions.

Anyone have any insight into this? :)
Nov 17 '08 #1
1 3548
weaknessforcats
9,208 Recognized Expert Moderator Expert
Read up on C++ /C# interoperability. There are many topics on this in MSDN.

The extern "C" only applies to making a C++ function callable from a C program. It does nothing to help with C#.

A C++ string is not a C# String.
Nov 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
3937
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
3
14898
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
1
5205
by: Steven Blair | last post by:
Hi, I am having problem passing a string by reference to some C++ code. Wondered if anyone could help me out. C# code: myFunc(str);
9
2285
by: Just Me | last post by:
PARAFORMAT2 is a structure that SendMessage will return stuff in. Is the "ref" correct or since only a pointer is being passed should it be by value? Suppose I was passing data rather then...
22
25541
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
61
3078
by: academic | last post by:
When I declare a reference variable I initialize it to Nothing. Now I'm wondering if that best for String variables - is "" better? With Nothing I assume no memory is set aside nor GC'ed But...
3
1967
by: James Robertson | last post by:
I am new to the ASP and VB thing so be kind. Question I have is that I have created an ASPX web site to use as an E-Mail page. But I want to use this for a lot of users. Can I create the link on...
22
3444
by: tshad | last post by:
If I am passing a variable by reference to another routine by reference, do I need to dereference first? string testString; .... FirstSub(ref firstString) { HandleString(ref firstString); ...
10
3898
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication...
6
3871
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper for a C++ DLL file, but am having problems with passing strings as parameters. How should I be writing my C# function call when the C header file is...
0
7026
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
6898
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
7015
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
7059
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...
0
5306
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,...
1
4754
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
2967
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
553
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.