Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Managed class to unmanaged class

Status
Not open for further replies.

jjknack

Programmer
May 17, 2004
9
US
I have a class that is using a managed object to get information from a database. Specifically OracleClient and DataTables/DataRows. I am able to get the information through this class ok, but I must pass it back to a C application that has an unmanaged C++ interface between the two.

Long story short, I need to convert a managed System::String _gc * to a char * to pass back. Is there a way to do this?
 
you can't mix managed code with unmanaged however you can use them both in the same program. But you can try do declare some function with extern "C", I haven't tried that and don't know if it is possible.

Ion Filipski
1c.bmp
 
Found it:

//using namespace System::Runtime::InteropServices;
System::String * str = S"Hello world\n";
char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(str);
printf(str2);
Marshal::FreeHGlobal(str2);


Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top