-
Notifications
You must be signed in to change notification settings - Fork 14
/
NativeCombineString.cs
51 lines (42 loc) · 1014 Bytes
/
NativeCombineString.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* C++ DLL code:
#include <string>
#define DllExport __declspec(dllexport)
extern "C"
{
DllExport char* CombineStrings(char* s1,char* s2);
char* faststrcat( char* dest, char* src )
{
while (*dest) dest++;
while (*dest++ = *src++);
return --dest;
}
char* CombineStrings( char* s1, char* s2 )
{
char* s3 = (char*) malloc(1+strlen(s1)+strlen(s2));
strcpy(s3, s1);
faststrcat(s3, s2);
return s3;
}
}
*/
using System;
using UnityEngine;
using System.Runtime.InteropServices;
public class NativeCombineString : MonoBehaviour
{
public string A;
public string B;
[DllImport("CombineString", EntryPoint = "CombineStrings")]
static extern IntPtr CombineStrings([MarshalAs(UnmanagedType.LPStr)] string x, [MarshalAs(UnmanagedType.LPStr)] string y);
IntPtr handle;
String caption;
void Update()
{
handle = CombineStrings (A, B);
caption = Marshal.PtrToStringAnsi (handle);
}
void OnGUI()
{
GUILayout.Label (caption);
}
}