Click here to Skip to main content
16,007,885 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralManaged & Unmanaged type problem; Pin
Ahmet Orkun GEDiK19-Dec-02 10:06
sussAhmet Orkun GEDiK19-Dec-02 10:06 
GeneralRe: Managed & Unmanaged type problem; Pin
Jeff J19-Dec-02 14:42
Jeff J19-Dec-02 14:42 
GeneralRe: Managed & Unmanaged type problem; Pin
Ahmet Orkun GEDiK19-Dec-02 19:10
sussAhmet Orkun GEDiK19-Dec-02 19:10 
GeneralRe: Managed & Unmanaged type problem; Pin
Jeff J19-Dec-02 21:03
Jeff J19-Dec-02 21:03 
GeneralRe: Managed & Unmanaged type problem; Pin
Ahmet Orkun GEDiK19-Dec-02 23:13
sussAhmet Orkun GEDiK19-Dec-02 23:13 
GeneralRe: Managed & Unmanaged type problem; Pin
Jeff J20-Dec-02 10:06
Jeff J20-Dec-02 10:06 
GeneralRe: Managed & Unmanaged type problem; Pin
Ahmet Orkun GEDiK20-Dec-02 11:21
sussAhmet Orkun GEDiK20-Dec-02 11:21 
GeneralRe: Managed & Unmanaged type problem; Pin
Jeff J20-Dec-02 16:53
Jeff J20-Dec-02 16:53 
One way to do this would be to keep an unmanaged struct around for passing to RfcOpen() calls. I assume you will get your string data as CLR String types, so you might want to keep them around in a .Net/GC struct for convenience, as done here (see m_RfcConnopt). When m_RfcConnopt has been filled, its data can be copied into unmanaged data. In this example the CLR Strings are converted to char strings, and then copied into C++ strings for long-term keeping (optional).


using namespace System::Runtime::InteropServices;

//a GC struct to hold .Net version of the data, just for convenience here
__gc struct RFC_ConOpt
{
  String* sHostName;
  Int32 sysnr;
  String* sGatewayHost;
  String* sGatewayService;
};

RFC_ConOpt *m_RfcConnopt;  //the managed class that holds the connopt stuff
std::string sHostName, sGatewayHost, sGatewaySvc;  //can be kept in class for storage

//Before you call RfcOpen()...

IntPtr ptr = Marshal::StringToHGlobalAnsi(m_RfcConnopt->sHostName);
sHostName = (char*)ptr.ToPointer();    //store in C++ string (optional)
Marshal::FreeHGlobal(ptr);             //free temp char string

ptr = Marshal::StringToHGlobalAnsi(m_RfcConnopt->sGatewayHost);
sGatewayHost = (char*)ptr.ToPointer();
Marshal::FreeHGlobal(ptr);

ptr = Marshal::StringToHGlobalAnsi(m_RfcConnopt->sGatewayService);
sGatewaySvc = (char*)ptr.ToPointer();
Marshal::FreeHGlobal(ptr);

//get pointers to internal char arrays...
rfc_connopt.hostname        = &(*sHostName.begin());
rfc_connopt.gateway_host    = &(*sGatewayHost.begin());
rfc_connopt.gateway_service = &(*sGatewaySvc.begin());
rfc_connopt.sysnr           = m_RfcConnopt->sysnr;

rfc_option.connopt = &rfc_connopt;  //<--------



You could skip copying the char strings into the C++ strings here. I just did that to avoid having to remember to call Marshal::FreeHGlobal() later on. The important thing is that .Net's wchar_t strings need to be converted to unmanaged char strings, and that rfc_option.connopt needs to point to an unmanaged array.
GeneralRe: Managed & Unmanaged type problem; Pin
Ahmet Orkun GEDiK21-Dec-02 4:54
sussAhmet Orkun GEDiK21-Dec-02 4:54 
Generalu can help me!! i have a Simple Quiestion. Pin
Alex H 198319-Dec-02 9:17
Alex H 198319-Dec-02 9:17 
GeneralVery Hard Problem (help Me) Pin
duvaft19-Dec-02 3:21
duvaft19-Dec-02 3:21 
GeneralRe: Very Hard Problem (help Me) Pin
Ahmet Orkun GEDiK19-Dec-02 10:13
sussAhmet Orkun GEDiK19-Dec-02 10:13 
GeneralOpen File -- Very Hard Problem Pin
duvaft19-Dec-02 3:20
duvaft19-Dec-02 3:20 
GeneralRe: Open File -- Very Hard Problem Pin
stanley guan2-Jan-03 17:54
stanley guan2-Jan-03 17:54 
Generalhelp Pin
imran_rafique16-Dec-02 6:54
imran_rafique16-Dec-02 6:54 
GeneralRe: help Pin
Anders Molin20-Dec-02 12:06
professionalAnders Molin20-Dec-02 12:06 
GeneralConvertiong Managed Strings to Unmanaged Chars Pin
KBL14-Dec-02 18:37
KBL14-Dec-02 18:37 
GeneralRe: Convertiong Managed Strings to Unmanaged Chars Pin
Nish Nishant17-Dec-02 14:48
sitebuilderNish Nishant17-Dec-02 14:48 
GeneralConverting and Concatenating Strings Pin
KBL13-Dec-02 22:01
KBL13-Dec-02 22:01 
GeneralRe: Converting and Concatenating Strings Pin
Jeff J14-Dec-02 7:12
Jeff J14-Dec-02 7:12 
GeneralWindows Forms Open File Dialog Pin
KBL13-Dec-02 6:46
KBL13-Dec-02 6:46 
GeneralRe: Windows Forms Open File Dialog Pin
Nish Nishant17-Dec-02 14:50
sitebuilderNish Nishant17-Dec-02 14:50 
GeneralLooping sending me loopy! Pin
dyerstein13-Dec-02 3:04
dyerstein13-Dec-02 3:04 
GeneralRe: Looping sending me loopy! Pin
monrobot1313-Dec-02 4:09
monrobot1313-Dec-02 4:09 
GeneralRe: Looping sending me loopy! Pin
Jeff J13-Dec-02 10:07
Jeff J13-Dec-02 10:07 

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.