ReadBinary - cRegistry
Reads a binary value from the currently open Key
Type: Function
Return Data Type: Boolean
Parameters
| Parameter | Type | Description |
|---|---|---|
| sValueName | String | The name of the Value to read data from |
| pValueData | Pointer | Address of the variable to receive the data into |
| iDataLength | Integer | The number of bytes to read |
Syntax
Function ReadBinary String sValueName Pointer pValueData Integer iDataLength Returns Boolean
Call Example
Get ReadBinary sValueName pValueData iDataLength to BooleanVariable
Description
Use ReadBinary to read binary data from a Windows Registry value.
| Col 1 | Col 2 |
|---|---|
| Note: | The reading and writing of binary data is a fairly advanced feature that will not be used very often. Usually, it is for storing the contents of structures, so that they can be written and read in single steps. |
Sample
This sample uses the Windows API function, SetWindowPlacement, to simultaneously set the size and location of a Window that was previously returned by a call to GetWindowPlacement. Both of these functions require a structure of type tWindowPlacement. By using WriteBinary and ReadBinary, we are able to store, and then retrieve, the whole structure very easily in a single step. Note that it would have also been possible to write the individual fields as Dword Values, but this would have required many more writes and reads, in addition to detailed knowledge of the structure.
Use cRegistry.pkg
Object oRegistry is a cRegistry
Procedure DoReadBinary
Boolean bSuccess
String sWindowPlacement sKey
Address aWindowPlacement
Handle hWnd
// Assume that oPanel is the name of the program's Panel object...
Get Window_Handle of oPanel To hWnd
// Assume this to be the Key to open to reetrieve the window Placement...
Move "Software\Data Access Worldwide\Examples\Contact\8.0;
\Contact\Windows\Contacts" To sKey
Get OpenKey sKey To bSuccess
If bSuccess Begin
// Prepare a structure of type tWindowPlacement...
ZeroType tWindowPlacement To sWindowPlacement
// and get its memory address...
Move (AddressOf(sWindowPlacement)) To aWindowPlacement
// read the binary data and store it at the address of the structure...
Get ReadBinary "Placement" ;
aWindowPlacement tWindowPlacement_size To bSuccess
// if the data was read successfully, then we can use it...
If bSuccess Move (SetWindowPlacement(hWnd, aWindowPlacement)) To bSuccess
// must close Keys that we open...
Send CloseKey
End
End_Procedure
End_Object
Send DoReadBinary of oRegistry
Return Value
If the data is successfully read, then the function returns True, otherwise it returns False.