Golang中国
myfunc(byte Market[], char* Zqdm[], short& Count)这个函数的三个入参,如何用golang重新定义这个函数呢,

原来的调用是如下:
byte Market[] = {0,1}; char* Zqdm[] = {"000001","600030"}; short ZqdmCount = 2; bool1 = TdxHq_GetSecurityQuotes(Market, Zqdm, ZqdmCount, Result, ErrInfo); if (!bool1) { cout << ErrInfo << endl; return 0; } cout << Result << endl;
如何改成golang的代码呢?!

8 回复
xjjrocker
#1 xjjrocker • 2017-05-31 23:11

C的函数:

byte[] Market = { 0, 1, 1, 0 };
string[] Zqdm = { "000001", "600030", "600000", "000750" };

如何转换成go的定义啊?

xjjrocker
#2 xjjrocker • 2017-06-01 01:01

发现golang中,数组作为参数传递时, 需要被检查长度(或许有时候不报错,但必须带长度),如下方式比如 fun test_array(args [4]int){….}
数字4必须带上。

jimmykuu
#3 jimmykuu • 2017-06-01 14:18

你可以先理解下 ArraySlice 的区别。

xjjrocker
#4 xjjrocker • 2017-06-04 13:58
char xMarket[] = {0,1, 0, 1 };
const char* Zqdm[] = { "000001", "600030", "000002", "601288" };
short ZqdmCount = 4;
bool1 = TdxHq_GetSecurityQuotes(xMarket, Zqdm, &ZqdmCount, Result, ErrInfo);

这段代码我用go实现如下

arrmarket := [2]byte{1,0}
arrzqdm := [2]string{"601166","000001"}
Hq_GetSecurityQuotes(arrmarket, arrzqdm, 2)

其中函数实现如下
func Hq_GetSecurityQuotes(Market [2]byte, Zqdm [2]string, Count int) {
...//省略
ret, _, err := Hq_GetSecurityQuotes.Call(uintptr(unsafe.Pointer(&Market)),
        uintptr(unsafe.Pointer(&Zqdm)), uintptr(unsafe.Pointer(&zqdmCount)),
        uintptr(unsafe.Pointer(&Result[0])), uintptr(unsafe.Pointer(&ErrInfo[0])))
...//省略
}

我发现传入参数只有一条有效,明明两条,但似乎只传入了一条,因为返回也只有一条数据,这里用&Market难道不对,请大侠指点。

xjjrocker
#5 xjjrocker • 2017-06-10 13:36

@jimmykuu 能帮忙指点下吗

jimmykuu
#6 jimmykuu • 2017-06-10 14:03
package main

func TdxHq_GetSecurityQuotes(market []byte, zqdm []string, count int) {
    // ...
}

func main() {
    market := []byte{0, 1}
    zqdm := []string{"601166", "000001"}
    count := 2

    TdxHq_GetSecurityQuotes(market, zqdm, count)
}
xjjrocker
#7 xjjrocker • 2017-06-10 14:36

报错如下
@jimmykuu

Exception 0xc0000005 0x0 0x2 0x57755daa
PC=0x57755daa

syscall.Syscall6(0x577529c0, 0x5, 0x116c4490, 0x116c44a0, 0x116c446c, 0x11822000, 0x117c8200, 0x0, 0x0, 0x40af9f, ...)
        C:/Go/src/runtime/syscall_windows.go:174 +0x51
syscall.(*Proc).Call(0x116c44c0, 0x116a4b40, 0x5, 0x5, 0x100, 0x100, 0x116c43ec, 0x0)
        C:/Go/src/syscall/dll_windows.go:155 +0x4ae
main.Hq_GetSecurityQuotes(0x116c4468, 0x2, 0x2, 0x116c4480, 0x2, 0x2, 0x2)
        C:/mygo/testTdxHq/testdll.go:367 +0x1d1
main.main()
        C:/mygo/testTdxHq/testdll.go:40 +0xc2
eax     0x1
ebx     0x116c4444
ecx     0x3197c226
edx     0x2
edi     0x116c446c
esi     0x3197c208
ebp     0x8fe54
esp     0x8f8b0
eip     0x57755daa
eflags  0x10297
cs      0x1b
fs      0x3b
gs      0x0
exit status 2
xjjrocker
#8 xjjrocker • 2017-06-10 21:11

@xiongfei @ThoseFlowers ,请c和go底层都熟识的也能给予指导,多谢!

需要 登录 后方可回复, 如果你还没有账号你可以 注册 一个帐号。