Use c# dll in c++

Hi i want use a c# dll in my c++ dll
I create a class library and add the dll to refrence and use from base code:

1
2
3
4
5
6
7
8
extern "C" __declspec(dllexport) char* SomeFunction() 
{
System::String ^str = MyNamespace::MyClass::MyMethod();

char* chp = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);

return chp; 
}


My dll have 4 parameter ,i tryed to set parameters but i dont know i display the error in each try...

I have error to this line

System::String ^str = MyNamespace::MyClass::MyMethod();

how can set the #4 string parameter to this line of code?

Last edited on
I have error to this line
What's the error?
this is the my errors with i see compile codes:
http://forums.winamp.com/attachment.php?attachmentid=54414&stc=1&d=1554457808

i do not know how can set the parameters
i tryed but not work

1
2
3
4
5
6
7
8
extern "C" __declspec(dllexport) char* FTPMakeDir(string ServerAddress, string ServerDIR, string FTPUsername, string FTPPassword)
{
System::String ^str = FTPCityToolkit::FTPCityToolkitClass::FTPMakeDir(ServerAddress, ServerDIR, FTPUsername, FTPPassword);

char* chp = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);

return chp;
}



how can set the FTPCityToolkit::FTPCityToolkitClass::FTPMakeDir argument list?


the errors:

function "FTPCityToolkit::FTPCityToolkitClass::FTPMakeDir" cannot be called with the given argument list



Error	C2664	'System::String ^FTPCityToolkit::FTPCityToolkitClass::FTPMakeDir(System::String ^,System::String ^,System::String ^,System::String ^)': cannot convert argument 1 from 'std::string' to 'System::String ^'

Last edited on
https://docs.microsoft.com/en-us/cpp/dotnet/how-to-convert-standard-string-to-system-string?view=vs-2019

Also, I'm not sure if this is correct:
char* chp = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
To me it looks like it at least leaks memory.
Topic archived. No new replies allowed.