GetCustomLicenseField issues

Hi,

at the first we would like to thank you for provide us a Go SDK for Cryptlex.
But I got problem when accessing Custom License Field with Go, it seems GetCustomLicenseField only accept C.char type (for fieldValue parameter), with C.char it’s going well, but I only got the first character. for example the value should be "my@email.com" but I only got “m”. here’s my code

var fieldValue C.char
C. GetCustomLicenseField(C.CString(“300”), &fieldValue, 256)

result for fieldValue is “m”

When I used bytes.Buffer, it’s goes errors, here’s my code

fieldValue := new(bytes.Buffer)
C. GetCustomLicenseField(C.CString(“300”), &fieldValue, 256)

result for field value is “Cannot use &fieldValue (type **bytes.Buffer) as type *C.char in argument…”

any ideas?
thanks.

Hi,

You should pass a pointer to the char array and not a char.

Please refer to following post:

thanks for your answer, but your suggestion is not working.
anyway, I found another way to solve this.

Can you post your solution.

Hi,

I used C.GoString to get value from a pointer, like code below:

   var fieldValue C.char
   var fieldName = C.CString("300")
status = C.GetCustomLicenseField(fieldName,&fieldValue, 256)
if (C.LA_OK == status) {
	return C.GoString(&fieldValue)
} 

But, I found another problem, I can’t free the memory of fieldName and fieldValue, I got panic error like this below when I trying to get CustomFields many times:

unexpected fault address 0x0
fatal error: fatal

do you have any suggestion to free the memory?

I used this code below to free the memory (not worked):

defer C.free(unsafe.Pointer(&fieldValue))
defer C.free(unsafe.Pointer(fieldName))

thanks

Use following method:

for i := 0; i < 1000; i++ { // running thousand times no panic
var fieldName = C.CString(“300”)
var fieldValue = [256]C.char{}
status = C.GetCustomLicenseField(fieldName, &fieldValue[0], 256)
if (C.LA_OK == status) {
fmt.Println("300: ", C.GoString(&fieldValue[0]))
}
}

works fine, thanks