Convert System::String^ (C# string) to C++ std::string [duplicate] - c#

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
C++/CLI Converting from System::String^ to std::string
I am using a C# DLL in my C++ code (Visual Studio 2010). How do I convert a System::String^ to a C++ std::string?

System.Runtime.InteropServices.Marshal has several methods that convert a string to an array of characters, which you could then use any manner of methods to get a std::string.
I believe the recommendation is to use StringToBSTR eventually calling FreeBSTR once you have copied the data to a different object.
The question I linked to as a comment recommends StringToCoTaskMemUni.

Related

Call native C++ function from C# [duplicate]

This question already has answers here:
Is it possible to embed C code in a C# project?
(4 answers)
Closed 6 years ago.
I have C++ legacy code with functions in the form:
double func(double)
I have this as a source file - it isnt in the form of a DLL although it could be turned into one if necessary
How can I call func in my C# code (maybe over managed C++)? I heard of Marshalling and DllImport but I did not find MSDN very helpful.
You have to compile C++ code as DLL library and then DllImport is way to go.
I don't know what problem you have with it. On MSDN I found this https://msdn.microsoft.com/en-us/library/e59b22c5.aspx
And also this article: http://www.mono-project.com/docs/advanced/pinvoke/ seems to be quite useful.

DllImport parameters char *TagIDs[] [duplicate]

This question already exists:
c# static extern function [duplicate]
Closed 6 years ago.
Hi Im trying to import c++ library in c# code
his definition:
void IRFR_GetUIDs(char *reply, char *TagIDs[], CString *TagNum);
how my function Should look like
Thanks
This function cannot be imported with p/invoke. It has a CString parameter which is a native C++ class and thus inaccessible to p/invoke. Either wrap the DLL with a other DLL exposing a p/invoke friendly interface, or wrap the DLL with a C++/CLI assembly.

How can I call C# DLL from C? [duplicate]

This question already has answers here:
Can you call a C# DLL from a C DLL?
(3 answers)
Calling C# from C
(4 answers)
Closed 9 years ago.
I am trying to use this solution. I can successfully create a C# DLL, but I have no idea how I can call it from C (no experience with this language). Can somebody help me please?
I have already seen similar questions, but they do not provide an answer to my one. I already know how I can create an unmanaged DLL with C#. The thing I do not know - how can I use it in C code?

Is it possible to use D from C# via P/Invoke? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Using D programming language in a .NET context
Just curious, is it possible to use D from C# via P/Invoke? And if not, what other mechanisms are there to pass data between the two?
http://www.d-programming-language.org/dll.html
If you can have it in win32 dll, you should be able to P/Invoke. Never tried it though...

Equivalence of String and string in C# test [duplicate]

This question already exists:
Closed 11 years ago.
Possible Duplicate:
String vs string in C#
I have a test in C# code I'm reading:
if (variable is string)
I am wondering if this is strictly equivalent to:
if (variable is String)
or if some esoteric behavior of C# autoboxing may cause these tests to behave differently.
They are exactly the same - string is an alias for System.String.

Categories