gtpc2mfc | C/C++ Language Support User's Guide |
This function searches the specified collection for the specified current key and, if found, returns the associated element value in the specified buffer. This differs from the TO2_keyWithBuffer function, which will always return the primary key. The TO2_getCurrentKeyWithBuffer function returns either the primary key (if the primary key path is in use) or the appropriate key if an alternate key path is being used to access the data element.
Format
#include <c$to2.h> TO2_BUF_PTR TO2_getCurrentKeyWithBuffer (const TO2_PID_PTR cursorPid_ptr, TO2_ENV_PTR env_ptr, const long *bufferLength, TO2_BUF_PTR buffer);
Normal Return
The normal return is a pointer (TO2_BUF_PTR) to a structure (buffer) of type TO2_BUF_HDR (see Type Definitions).
Error Return
An error return is indicated by a zero. When zero is returned, use the TO2_getErrorCode function to determine the specific error code. For more information, see Error Handling.
The following error codes are common for this function:
TO2_ERROR_ENV
TO2_ERROR_LOCATOR_LGH
TO2_ERROR_METHOD
TO2_ERROR_NOT_INIT
TO2_ERROR_PID
TO2_ERROR_ZERO_PID
Programming Considerations
Examples
The following example retrieves the current active key value of the current data element.
#include <c$to2.h> /* Needed for TO2 API Functions */ #include <stdio.h> /* APIs for standard I/O functions */ #define KEY_SIZE 16 TO2_PID cursor; TO2_ENV_PTR env_ptr; TO2_BUF_PTR buffer_ptr; /* Pointer to TO2 environment */ u_char *key=NULL; /* The key of the element */ long buffer_length;
·
·
·
/**********************************************************************/ /* Retrieve the key from the item pointed to by the cursor */ /* and return it in the supplied buffer. */ /**********************************************************************/ buffer_length = KEY_SIZE + sizeof(TO2_BUF_HDR); if ((buffer_ptr=malloc(buffer_length)) == NULL) { printf("malloc() failed!\n"); return(0); } if ((buffer_ptr=TO2_getCurrentKeyWithBuffer(&cursor, env_ptr, &buffer_length, buffer_ptr)) == NULL) { printf("TO2_getCurrentkeyWithBuffer failed!\n"); process_error(env_ptr); } else { key = buffer_ptr->data; printf("TO2_getCurrentKeyWithBuffer successful!\n"); }
·
·
·
free (buffer_ptr);
Related Information