I don't know Ruby, but it all looks about right. If I were you I would attach a debugger and step through 1 line at a time to see exactly what is causing the problem.
Hi,We are on a Plus plan and have 5 custom fields for a product version. We are using Ruby-C interface to query the feature values in a loop. Most of the time, only 2 of 5 values return TA_OK while 3 of the 5 fail. Sometimes, it works but it is not consistent. Is there something wrong I am doing.
getFeatureValue = Fiddle::Function.new( ta_dll['GetFeatureValue'], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT], Fiddle::TYPE_INT )
license_fields = ['companyname', 'emailid', 'firstname', 'lastname', 'isexternal'] ##dll_path is set properly ta_dll = Fiddle.dlopen(dll_path) getFeatureValue = Fiddle::Function.new( ta_dll['GetFeatureValue'], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT], Fiddle::TYPE_INT ) license_fields.each { |field| wchar_key = field.encode('UTF-16LE') response_buf = "\0"*256 size = 256 ret_value = getFeatureValue.call(wchar_key, response_buf, size) #ret_value does not consistently return TA_OK. it most times returns TA_FAIL for some of the fields. }
RaviPS : How do i enable code formatting in the forum.. It shows BBCode is OFF
I don't know Ruby, but it all looks about right. If I were you I would attach a debugger and step through 1 line at a time to see exactly what is causing the problem.
Yep, I did that. I have a question to the team. Is GetFeatureValue making a remote api call or is there a timeout issue. If we make the same calls at different times, a different set of fields are populated correctly, but we are have never been able to get all 5 fields returned with TA_OK. Is there a prerequisite to the call, or does the backend limit GetFeatureValue to one per sec type of query.
Another option is, is there a different way of getting the 5 custom fields through some other API or even web api. I could change the code to accommodate it.
Is GetFeatureValue making a remote api call
No, never. It always gets the field data from the downloaded, cryptographically signed activation data.
The problem is either in your code (step through line-by-line) or in the underlying Ruby API that calls dlls.
One place to start is to make sure you're not hard-coding field value lengths (the field value may or may not be under 127 characters long (remember we're dealing with double-byte characters on Windows). Use GetFeatureValue() to actually get the size of the buffer needed to store the custom license field value before you actually trying to retrieve the value.
Sam, thanks for the reply. You are correct the issue was in the ruby fiddle code. The custom field name which needs to be sent as windows wide character had issues. I did not pass a big enough buffer, which caused the field name not getting terminated properly in some cases. that is why the behavior was erratic. Thanks
I'm needing to do this in C++ where I get all the features from a license file via a loop. I know how to get a single feature based on the C example code provided by your SDK, but I'm not sure how to get ALL the features in a loop using C++. Can you provide a rudimentary example?
Thanks,Arie
So I've been successful in retrieving the feature "first_name" from my license file using the sample code in the SDK, but when I try to create an array of features and iterate through it, I always get fail.
Here's what I've tried and it doesn't work:
TCHAR * featureValue; std::string features[] = { "first_name", "last_name" }; for (unsigned int i = 0; i < sizeof(features)/sizeof(features[0]); i = i + 1) { const char * featureName = features.c_str(); printf("Getting feature: %s\n", featureName); hr = GetFeatureValue(_T(featureName), 0, 0); featureValue = (TCHAR *)malloc(hr * sizeof(TCHAR)); hr = GetFeatureValue(_T(featureName), featureValue, hr); if (hr == TA_OK) { #ifdef _WIN32 wprintf(L"Feature value: %s\n", featureValue); #else printf("Feature value: %s\n", featureValue); #endif } else { printf("Getting feature failed: %d\n", hr); return 1; } free(featureValue); } return 0;
I just discovered the key I was testing on wasn't activated, so it wasn't returning anything. It looks like that code works after I activated the key I was testing with.