golang 调用dll 返回 如何获取返回的内容

目前中测试了返回字符串的内容,其它的结构体后再再测试


lib := syscall.NewLazyDLL("./lib/iTapTradeAPI_64.dll")
fmt.Println("dll:", lib.Name)
add := lib.NewProc("GetITapTradeAPIVersion")
fmt.Println("+++++++NewProc:", add, "+++++++")


ret, b, err := add.Call()
if err != nil {
   errGet := err.(syscall.Errno)
   if (errGet == 0) {
      fmt.Println("ret:", uintptr(ret))
      fmt.Println("b:", uintptr(b))

      p := (*byte)(unsafe.Pointer(ret))
      data := make([]byte, 0)

      for *p != 0 {
         data = append(data, *p)
         ret += unsafe.Sizeof(byte(0))
         p = (*byte)(unsafe.Pointer(ret))
      }
      ss := string(data)
      println(ss)

   } else {
      fmt.Println("错误:", err.Error())
   }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GdiPlus是一个Windows图形库,可以用于处理图形、图像的显示、打印等操作。使用Golang调用GdiPlus dll打印可以按照以下步骤进行: 1. 导入"syscall"包,使用"LoadLibrary"函数加载GdiPlus.dll库文件。 ```go import ( "syscall" ) var ( gdiplus = syscall.NewLazyDLL("GdiPlus.dll") ) ``` 2. 使用"GetProcAddress"函数获取所需函数的地址。 ```go var ( gdiplusStartup = gdiplus.NewProc("GdiplusStartup") gdiplusShutdown = gdiplus.NewProc("GdiplusShutdown") gdiplusCreateFont = gdiplus.NewProc("GdipCreateFontFamilyFromName") gdiplusGetDC = gdiplus.NewProc("GdipGetDC") gdiplusReleaseDC = gdiplus.NewProc("GdipReleaseDC") gdiplusPrint = gdiplus.NewProc("GdipPrint") // 其他函数... ) ``` 3. 调用"GdiplusStartup"函数初始化GdiPlus,传入指针类型的"ULONG_PTR"变量作为输出参数。 ```go var token uintptr gdiplusStartup.Call(uintptr(unsafe.Pointer(&token)), 0, 0) defer gdiplusShutdown.Call(token) ``` 4. 使用"GdipCreateFontFamilyFromName"函数创建字体,该函数需要传入字体名称、语言、字体句柄等参数。 ```go var ( fontName = "Arial" lang = "en-US" fontHdc uintptr fontPtr uintptr ) gdiplusCreateFont.Call( uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(fontName))), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lang))), uintptr(unsafe.Pointer(&fontPtr)), ) defer gdiplusReleaseFont.Call(fontPtr) ``` 5. 使用"GdipGetDC"函数获取打印机设备上下文句柄。 ```go var printerName = "Microsoft Print to PDF" var hdc uintptr gdiplusGetDC.Call( uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(printerName))), uintptr(unsafe.Pointer(&hdc)), ) defer gdiplusReleaseDC.Call(hdc) ``` 6. 使用"GdipPrint"函数将图像打印到指定设备上下文。 ```go gdiplusPrint.Call( hdc, uintptr(unsafe.Pointer(&image)), uintptr(width), uintptr(height), uintptr(x), uintptr(y), ) ``` 以上步骤仅供参考,具体操作需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值