46 lines
1.4 KiB
Markdown
46 lines
1.4 KiB
Markdown
|
#base62json
|
||
|
|
||
|
```
|
||
|
brew install mingw-w64
|
||
|
|
||
|
编译 32位 dll
|
||
|
CGO_ENABLED=1 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ GOOS=windows GOARCH=386 go build --buildmode=c-shared -ldflags="-s -w" -o main_x32.dll
|
||
|
|
||
|
编译 64位 dll
|
||
|
CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 go build --buildmode=c-shared -ldflags="-s -w" -o main_x64.dll
|
||
|
```
|
||
|
|
||
|
```c#
|
||
|
class Program
|
||
|
{
|
||
|
[DllImport("main", EntryPoint = "SetCharacters", CallingConvention = CallingConvention.Cdecl)]
|
||
|
extern static bool SetCharacters(byte[] a);
|
||
|
|
||
|
[DllImport("main", EntryPoint = "Encode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||
|
extern static IntPtr Encode(byte[] a);
|
||
|
|
||
|
[DllImport("main", EntryPoint = "Decode", CallingConvention = CallingConvention.Cdecl)]
|
||
|
extern static IntPtr Decode(byte[] test);
|
||
|
|
||
|
static void Main(string[] args)
|
||
|
{
|
||
|
byte[] k = Encoding.ASCII.GetBytes("vY1lKxmABkMeRhV5q2XIEfT4ojuJdzaPcNUCs7Ft8GZnOW3Hip0LQ9gywrD6bS");
|
||
|
|
||
|
bool bl = SetCharacters(k);
|
||
|
|
||
|
string tmp = "{\"a\":1}";
|
||
|
|
||
|
byte[] t = Encoding.ASCII.GetBytes(tmp);
|
||
|
|
||
|
var b = Encode(t);
|
||
|
|
||
|
tmp = Marshal.PtrToStringAnsi(b);
|
||
|
|
||
|
t = Encoding.ASCII.GetBytes("m1jD8rjX5vYUmTMFSR8AgRDdvWPD8vdckSDPO0yfYrnEStBvMJBifXy1kUfE28AlDK0bYy8TVjdK02GyyZ7ck");
|
||
|
|
||
|
var d = Decode(t);
|
||
|
|
||
|
Console.WriteLine(Marshal.PtrToStringAnsi(d));
|
||
|
}
|
||
|
}
|
||
|
```
|