GO 调用C++ dll,报 is not a valid Win32 application.

issueQRCode 有两个参数,carddata,cdata cdata需要回调 上代码

package main

import (
    "fmt"  
    "syscall"
    "unsafe"
)

func IntPtr(n int) uintptr {
    return uintptr(n)
}

func StrPtr(s string) uintptr {
    return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
}

var (
    qrcio=syscall.MustLoadDLL("qrcio.dll")
    issueQRCode=qrcio.MustFindProc("issueQRCode")
)

func IssueQRCode(cdata,carddata string) (result uintptr) {
   ret,_,_:=issueQRCode.Call(StrPtr(carddata),StrPtr(cdata))

   return ret

}

func main() { 

    var cdata,carddata string
    carddata="C0|Y0|S140101000000|I160910121212|O181231235959|J181231235959|B1|F1|R1|X0|V2|D9999888877776666"

   var result= IssueQRCode(carddata,cdata)
    fmt.Println(result) 
}
已邀请:

astaxie - 创造、获取、分享、传播和应用Go

赞同来自: Richard

https://github.com/golang/go/issues/12293

Windows returns you ERROR_BAD_EXE_FORMAT. The error message for it (https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx) is "%1 is not a valid Win32 application.". So that is what Go prints.

It is unfortunate, but I don't see how we can improve this situation.

Alex

snail - 90后程序猿

赞同来自:

请问这个问题如何解决,我在 windows 64 位下调用 .dll 正确,但是在 windows 32 位下调用 .dll 报:Failed to load ./xxx.dll: %1 is not a valid Win32 application.

plain

赞同来自:

64位系统调用64位的dll,32位调用32位dll

要回复问题请先登录注册