test c_wrapper

This commit is contained in:
yejian 2023-08-30 09:25:08 +08:00 committed by Gordon
parent 7404a54683
commit 5dace36823
10 changed files with 36 additions and 60 deletions

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"files.associations": {
"stdio.h": "c",
"c_wrapper.h": "c"
}
}

1
c_wrapper/build_dll.bat Normal file
View File

@ -0,0 +1 @@
go build -buildmode=c-shared -o c_wrapper.dll export.go

View File

@ -0,0 +1,2 @@
gcc -o test.exe -L. c_wrapper.dll test.c
test.exe

1
c_wrapper/build_test.bat Normal file
View File

@ -0,0 +1 @@
gcc -o test.exe -L. c_wrapper.dll test.c

View File

@ -36,9 +36,9 @@ func init_sdk(onConnecting C.base_func,
callback := NewConnCallback(onConnecting, onConnectSuccess, onKickedOffline, onUserTokenExpired, onConnectFailed)
return open_im_sdk.InitSDK(callback, C.GoString(operationID), C.GoString(config))
}
func main() {
// func main() {
}
// }
type ConnCallback struct {
onConnecting C.base_func

Binary file not shown.

View File

@ -19,28 +19,6 @@ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
/* Start of preamble from import "C" comments. */
#line 3 "c_init_login.go"
#include <stdio.h>
typedef void (*base_func)();
typedef void (*err_func)(int,void *);
extern base_func _onConnecting;
extern base_func _onConnectSuccess;
extern base_func _onKickedOffline;
extern base_func _onUserTokenExpired;
extern err_func _onConnectFailed;
extern void c_onConnecting();
extern void c_onConnectSuccess();
extern void c_onKickedOffline();
extern void c_onUserTokenExpired();
extern void c_onConnectFailed(int ,void*);
#line 1 "cgo-generated-wrapper"
/* End of preamble from import "C" comments. */
@ -96,7 +74,7 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
extern "C" {
#endif
extern __declspec(dllexport) GoUint8 init_sdk(base_func onConnecting, base_func onConnectSuccess, base_func onKickedOffline, base_func onUserTokenExpired, err_func onConnectFailed, char* operationID, char* config);
extern __declspec(dllexport) void Init_SDK();
#ifdef __cplusplus
}

13
c_wrapper/export.go Normal file
View File

@ -0,0 +1,13 @@
package main
import "C"
import "fmt"
//export Init_SDK
func Init_SDK() {
fmt.Println("Init SDK")
}
func main() {
}

10
c_wrapper/test.c Normal file
View File

@ -0,0 +1,10 @@
// gcc -o test.exe -lc_wrapper.dll test.c
#include <stdio.h>
#include "c_wrapper.h"
void main(int argc, char **argv)
{
Init_SDK();
}

View File

@ -1,35 +0,0 @@
package main
/*
#include <stdio.h>
typedef void (*base_func)();
typedef void (*err_func)(int,void *);
base_func _onConnecting;
base_func _onConnectSuccess;
base_func _onKickedOffline;
base_func _onUserTokenExpired;
err_func _onConnectFailed;
void c_onConnecting()
{
_onConnecting();
}
void c_onConnectSuccess()
{
_onConnectSuccess();
}
void c_onKickedOffline()
{
_onKickedOffline();
}
void c_onUserTokenExpired()
{
_onUserTokenExpired();
}
void c_onConnectFailed(int errCode,void* errMsg)
{
_onConnectFailed(errCode,errMsg);
}
*/
import "C"