PDA

View Full Version : VB.NET 2.0, lc_get_attr, lc_set_attr, String Values



JeffFerguson
08-07-2008, 12:32 PM
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:



<DllImport("C:\i86_32Bit_V11.6\i86_n3\lmgr11.dll", CharSet:=CharSet.Ansi, SetLastError:=True)> _
Private Shared Function lc_get_attr(ByVal job As IntPtr, ByVal attr As Integer, ByRef value As Short) As Int32
End Function




<DllImport("C:\i86_32Bit_V11.6\i86_n3\lmgr11.dll", CharSet:=CharSet.Ansi, SetLastError:=True)> _
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?

RobertDickau
08-08-2008, 01:11 PM
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?