Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 2

VB.NET 2.0, lc_get_attr, lc_set_attr, String Values

I am integrating FLEXnet 11.6 into a VB.NET 2.0 code base. I have defined lc_get_attr() and lc_set_attr() as follows:

Private Shared Function lc_get_attr(ByVal job As IntPtr, ByVal attr As Integer, ByRef value As Short) As Int32
End Function

Private Shared Function lc_set_attr(ByVal job As IntPtr, ByVal key As Integer, ByVal value As IntPtr) As Int32
End Function

This works well for the attributes whose values are based on integers, such as LM_A_CHECK_BADDATE.

However, I am not sure that the same process is working for values based on strings. I am working particularly with LM_A_BORROW_EXPIRE. I can call lc_set_attr() with the following code:

ValueAsIntPtr = Marshal.StringToHGlobalAnsi(Value)
ReturnCode = lc_set_attr(thisJob, Key, ValueAsIntPtr)

The value of ReturnCode is 0 and the call is successful. But I am getting NULL returned from the followup call to lc_get_attr():

Dim ExpirationDateStringPointer As IntPtr

ReturnCode = lc_get_attr(thisJob, LM_A_BORROW_EXPIRE, ExpirationDateStringPointer)
ExpirationDateString = Marshal.PtrToStringAnsi(ExpirationDateStringPointer)

Here, the return code is 0, but the ExpirationDateStringPointer parameter is also 0 -- NULL, even after I have set LM_A_BORROW_EXPIRE to a value.

Has anyone done this? Can anyone offer any suggestions?
Labels (1)
0 Kudos
(1) Reply
Flexera Alumni

I'm not very comfortable with VB.NET, but you're right about handling strings differently; from the docs for the C API (FuncRef-c.pdf), there's this note for lc_get_attr:
Types of char * are handled a little differently than other types. Types of int or short are declared, and a pointer to the declared variable is passed as an argument. Types of char * are declared as char *, and the variable itself is passed.
Does any other function that works with char * (such as lc_hostid) work with similar code?
0 Kudos