mirror of
https://github.com/guilhermewerner/rust-ffi
synced 2025-06-16 05:44:19 +00:00
Add String Conversion Function
This commit is contained in:
@ -4,6 +4,16 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
// Hello
|
||||
|
||||
char *result = Hello("C");
|
||||
|
||||
printf("%s\n", result);
|
||||
|
||||
DeallocString(result);
|
||||
|
||||
// Operations
|
||||
|
||||
int num1 = 1;
|
||||
int num2 = 2;
|
||||
|
||||
|
@ -11,6 +11,9 @@ namespace CSharp
|
||||
const string Library = "libLibrary";
|
||||
#endif
|
||||
|
||||
[DllImport(Library)]
|
||||
static extern string Hello(string input);
|
||||
|
||||
[DllImport(Library)]
|
||||
static extern float Add(float Num1, float Num2);
|
||||
|
||||
@ -25,6 +28,14 @@ namespace CSharp
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Hello
|
||||
|
||||
string result = Hello("C#");
|
||||
|
||||
Console.WriteLine(result);
|
||||
|
||||
// Operations
|
||||
|
||||
int num1 = 1;
|
||||
int num2 = 2;
|
||||
|
||||
|
@ -6,6 +6,15 @@ using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Hello
|
||||
char *result = Library::Hello("C++");
|
||||
|
||||
cout << result << "\n";
|
||||
|
||||
Library::DeallocString(result);
|
||||
|
||||
// Operations
|
||||
|
||||
int num1 = 1;
|
||||
int num2 = 2;
|
||||
|
||||
|
Reference in New Issue
Block a user