Click here to Skip to main content
15,942,699 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: conversion from tchar* to string^ Pin
Richard MacCutchan3-Apr-13 5:13
mveRichard MacCutchan3-Apr-13 5:13 
QuestionCreating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 11:30
Douglas Kirk31-Mar-13 11:30 
AnswerRe: Creating a global array of labels at runtime Pin
NotPolitcallyCorrect31-Mar-13 14:10
NotPolitcallyCorrect31-Mar-13 14:10 
GeneralRe: Creating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 14:38
Douglas Kirk31-Mar-13 14:38 
GeneralRe: Creating a global array of labels at runtime Pin
NotPolitcallyCorrect31-Mar-13 15:22
NotPolitcallyCorrect31-Mar-13 15:22 
GeneralRe: Creating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 15:56
Douglas Kirk31-Mar-13 15:56 
GeneralRe: Creating a global array of labels at runtime Pin
NotPolitcallyCorrect31-Mar-13 16:26
NotPolitcallyCorrect31-Mar-13 16:26 
QuestionPassing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG26-Mar-13 0:24
SujayG26-Mar-13 0:24 
Hi There ,

I want to call a C# function from C++ , via CLI/C++.

C# code
C#
private string _text = "";

public void setText(string text)
{
   // _text = text;
   _text = "HI World";
   Console.WriteLine("C# settext - {0}", _text);
}

public string getText()
{
  return _text;
}


C++/CLI code

Header :

C#
//virtual void setText(System::String^ text);
//virtual System::String^ getText();

virtual void setText(std::string text);
virtual std::string getText();


CPP file

cplusplus
std::string CStringBridge::getText()
{
   _managedObject = gcnew Bridge();
   return (marshal_as<std::string>(_managedObject->getText()));
}

void CStringBridge::setText(std::string text)
{
   _managedObject = gcnew Bridge();
   _managedObject->setText(gcnew      System::String(text.c_str()));
}


Note : When I use the following code

C++
<pre lang="cpluscplus">virtual void setText(System::String^ text);
virtual System::String^ getText();


I get the following error 3395
__declspec(dllexport) cannot be applied to a function with the __clrcall calling convention

, and so I stuck to std::string

When I use the library from the C++/CLI code, and call from my C++ program, "Hi World" should be printed ; instead nothing gets printed

C++ console application

IStringBridgeWrapper *pBridge = IStringBridgeWrapper::CreateInstance();
pBridge->setText(std::string("I am here"));
	
try{

    pBridge->getText();
}
catch(exception& e) 
{
   cout << e.what() << endl;
}



I think the string is not being properly passed .

Any ideas to solve it shall be appreicated.

AnswerRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
David Knechtges26-Mar-13 8:50
David Knechtges26-Mar-13 8:50 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG26-Mar-13 21:33
SujayG26-Mar-13 21:33 
AnswerRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan26-Mar-13 22:59
mveRichard MacCutchan26-Mar-13 22:59 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG27-Mar-13 3:54
SujayG27-Mar-13 3:54 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan27-Mar-13 3:58
mveRichard MacCutchan27-Mar-13 3:58 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG27-Mar-13 4:11
SujayG27-Mar-13 4:11 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan27-Mar-13 4:19
mveRichard MacCutchan27-Mar-13 4:19 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG27-Mar-13 4:52
SujayG27-Mar-13 4:52 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan27-Mar-13 5:03
mveRichard MacCutchan27-Mar-13 5:03 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG29-Mar-13 19:09
SujayG29-Mar-13 19:09 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan29-Mar-13 23:00
mveRichard MacCutchan29-Mar-13 23:00 
AnswerRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
jschell30-Mar-13 13:33
jschell30-Mar-13 13:33 
QuestionDidn't Understand to logic of calculation of this program.? Pin
Taqi_Shah11-Mar-13 7:26
Taqi_Shah11-Mar-13 7:26 
AnswerRe: Didn't Understand to logic of calculation of this program.? Pin
NotPolitcallyCorrect11-Mar-13 7:55
NotPolitcallyCorrect11-Mar-13 7:55 
SuggestionRe: Didn't Understand to logic of calculation of this program.? Pin
MicroVirus13-Mar-13 12:16
MicroVirus13-Mar-13 12:16 
QuestionNeed Urgent Help!! Pin
Member 933160011-Mar-13 2:18
Member 933160011-Mar-13 2:18 
AnswerRe: Need Urgent Help!! Pin
Marco Bertschi14-Mar-13 10:36
protectorMarco Bertschi14-Mar-13 10:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.