Comments (4)
对,这是一个问题。我也正在尝试解决。
from goctp.
%typemap(gotype) (char **ppInstrumentID, int nCount) "[]string"
%typemap(in) (char *ppInstrumentID, int nCount)
%{
{
int i;
gostring a;
$2 = $input.len;
a = (_gostring_*) $input.array;
$1 = (char **) malloc (($2 + 1) * sizeof (char *));
for (i = 0; i < $2; i++) {
/* Not work */
//_gostring_ *ps = &a[i];
//$1[i] = (char *) ps->p;
//$1[i][ps->n] = '\0';
/*Work well*/
_gostring_ *ps = &a[i];
$1[i] = (char*) malloc(ps->n + 1);
memcpy($1[i], ps->p, ps->n);
$1[i][ps->n] = '\0';
}
$1[i] = NULL;
}
%}
%typemap(argout) (char *ppInstrumentID, int nCount) "" / override char *[] default */
%typemap(freearg) (char **ppInstrumentID, int nCount)
%{
{
int i;
for (i = 0; i < $2; i++)
{
free ($1[i]);
}
free($1);
}
%}
把这段代码改掉,参照下面的代码,用golang 实现应该就可以了,对swig 不太熟悉,不知道怎么更改这段
func Test(args[] string){
arg := make([](* Ctype_char), 0) //C语言char*指针创建切片
l := len(args)
for i, := range args{
char := C.CString(args[i])
defer C.free(unsafe.Pointer(char)) //释放内存
strptr := (_Ctype_char)(unsafe.Pointer(char))
arg = append(arg, strptr) //将char指针加入到arg切片
}
C.test(C.int(l), (_Ctype_char)(unsafe.Pointer(&arg[0]))) //即c语言的main(int argc,charargv)
}
from goctp.
///订阅行情
func (p *GoCThostFtdcMdSpi) SubscribeMarketData(name []string) {
arg := make([](*C.char), 0)
l := len(name)
for i, _ := range name {
char := C.CString(name[i])
defer C.free(unsafe.Pointer(char)) //释放内存
strptr := (*C.char)(unsafe.Pointer(char))
arg = append(arg, strptr) //将char指针加入到arg切片
}
iResult := p.Client.MdApi.SubscribeMarketData((*string)(unsafe.Pointer(&arg[0])), int(l))
if iResult != 0 {
log.Println("发送行情订阅请求: 失败.")
} else {
log.Println("发送行情订阅请求: 成功.")
}
}
这样就可以了
from goctp.
楼上正解 好牛
from goctp.
Related Issues (13)
- 你好,能不能麻烦你把window64的也弄一下,自己弄了好久。。。 HOT 5
- Linux下一个完整的问题总结! HOT 2
- 是否更新了穿透式 app_id 和authcode的相关内容?
- goctp_trader_example:发送用户登录请求: 失败: Bad format user system info HOT 1
- 大佬,最新版本还在引用6.3.11的库,编译会出问题,新的库只有linux,测试编译有点问题
- 交易登录报错:不合法的登录
- trade api main中 执行到 Join 有致命错误 HOT 11
- win64平台编译失败 HOT 7
- osx系统
- centos7下载更新后的的goctp编译失败 HOT 3
- GOCTP中的tradeApi调用主动函数总是连接失败(返回-1) HOT 2
- ubuntu x64下goctp编译失败 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goctp.