RecnumToRowId, with API << Back



Raveen has contributed a function for converting a recnum to a rowid. Check it out here. I posted a reply to show that there are some handy API functions that would do some grunt work for him. Let's take a look at those APIs.

Use UI
External_Function wvsprintf "wvsprintfA" USER32.DLL Pointer pResult String sTemplate Pointer pParam Returns Integer
External_Function htonl "htonl" Ws2_32.dll Uinteger u Returns UInteger
Function RecnumToRowId Global UInteger uDec Returns RowId
	Integer iVoid
	String sResult
	Move (htonl(uDec)) to uDec
	Move (Repeat(" ",9)) to sResult
	Move (wvsprintf(AddressOf(sResult), "%.8lx", AddressOf(uDec))) to iVoid
	Function_Return  (DeserializeRowID(Left(sResult,8))) 
End_Function

The API htonl was designed for converting an IP address's endianness cause Windows (or Intel x86 architecture) uses little endian. If you have a 32-bit unsigned integer (UInteger) |CI$12345678, "htonl" will convert that to |CI$78563412.

The API wvsprintf is similar to "sFormat" in VDF, except that it expects parameters in a array pointer format. One of the functions in "wvsprintf" is to allow you to convert an integer to hexdecimal format. If you are using DF 20.0+, you can use a similar function called wsprintf, which will take a parameter list just like "sFormat". "wsprintf" is not available to DF 19.1 and prior because "wsprintf" uses cdecl calling convention instead of stdcall calling convention.






Free Web Hosting