• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

System::String to standard::string ?

Lazy8s

Golden Member
Ok, so I used

array<String^>^drives = Environment::GetLogicalDrives();

and I'm trying to pass it into my function

deliver(string thisDir)

but simply typing

for(int i=0; i < drives->Length; i++)
drliver(drives);

does not work. Obviously the simple thing to do would be to allow deliver() to take a managed string but on theother side I am doing all kinds of string manipulation so that's an option but only if I can convert from managed to standard string on the other side....

I tried

char* str = (char*)(void*)Marshal::StringToHGlobalAnsi(drives);

but it gives me all kinds of errors. I'm using Microsoft Visual Studio 2005 pro. Any help would be REALLY appreciated. Thanks in advance.
 
That gave me a managed char array, but I can find even less info about how to turn the managed char array into standard chars...


array<String^>^drives = Environment::GetLogicalDrives();
array<Char>^charDrives;
for(int i=0; i<drives->Length; i++){
charDrives=drives->ToCharArray();
deliver(charDrives[0]+":");
}


Still gives the error: error C2664: 'deliver' : cannot convert parameter 1 from 'System::String ^' to 'std::string'
 
Originally posted by: Lazy8s
That gave me a managed char array, but I can find even less info about how to turn the managed char array into standard chars...


array<String^>^drives = Environment::GetLogicalDrives();
array<Char>^charDrives;
for(int i=0; i<drives->Length; i++){
charDrives=drives->ToCharArray();
deliver(charDrives[0]+":");
}


Still gives the error: error C2664: 'deliver' : cannot convert parameter 1 from 'System::String ^' to 'std::string'


You're right. Bad suggestion, sorry 🙂. Hopefully this isn't another one. Take a look at System.Runtime.InteropServices.Marshall.StringToBSTR or .StringToPtr. I think either of these might get you closer to what you need.
 
Back
Top