Jump to content

WpRestoreString: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
Line 6: Line 6:


==Parameters==
==Parameters==
;''somSelf'' ([[WPObject]] *) - input
;''somSelf'' (WPObject *) - input:Pointer to the object on which the method is being invoked.
:Pointer to the object on which the method is being invoked.
:Points to an object of class [[WPObject]].
:Points to an object of class [[WPObject]].
 
;''pszClass'' ([[PSZ]]) - input:Pointer to the class name.
;''pszClass'' ([[PSZ]]) - input
:Pointer to the class name.
:A pointer to a zero-terminated string that contains any unique string. The class name is recommended but not enforced.
:A pointer to a zero-terminated string that contains any unique string. The class name is recommended but not enforced.
 
;''ulKey'' ([[ULONG]]) - input:Class-defined identifier.
;''ulKey'' ([[ULONG]]) - input
:Class-defined identifier.
:A class-defined identifier that correlates to a particular instance data variable.
:A class-defined identifier that correlates to a particular instance data variable.
 
;''pszValue'' (PSZ) - in/out:Address of the string to be restored.
;''pszValue'' ([[PSZ]]) - in/out
;''pcbValue'' (PULONG) - in/out:Size of string to be restored.
:Address of the string to be restored.
 
;''pcbValue'' ([[PULONG]]) - in/out
:Size of string to be restored.
:If ''pszValue'' is NULL, the actual size is returned in ''pcbValue''.
:If ''pszValue'' is NULL, the actual size is returned in ''pcbValue''.


==Returns==
==Returns==
;''rc'' ([[BOOL]]) - returns
;''rc'' ([[BOOL]]) - returns:Success indicator.
:Success indicator.
::TRUE: Successful completion.
::TRUE: Successful completion.
::FALSE: Error occurred.
::FALSE: Error occurred.
Line 41: Line 31:


==Example Code==
==Example Code==
Declaration:
<PRE>
#define INCL_WINWORKPLACE
#include <os2.h>
WPObject      somSelf;    / Pointer to the object on which the method is being invoked. /
PSZ          pszClass;  / Pointer to the class name. /
ULONG        ulKey;    / Class-defined identifier. /
PSZ          pszValue;  / Address of the string to be restored. /
PULONG        pcbValue;  / Size of string to be restored. /
BOOL          rc;        / Success indicator. */
rc = _wpRestoreString(somSelf, pszClass, ulKey, pszValue, pcbValue);
</PRE>
This example demonstrates an override of wpRestoreState method to save string data.
This example demonstrates an override of wpRestoreState method to save string data.
<PRE>
<PRE>
SOM_Scope BOOL    SOMLINK wpRestoreState(nbk  somSelf,
SOM_Scope BOOL    SOMLINK wpRestoreState(nbk  somSelf,
ULONG ulReserved)
ULONG ulReserved)
{
{
BOOL fSuccess;      / Success flag /
BOOL fSuccess;      /* Success flag */
ULONG ulCount;      / Length of title string /
ULONG ulCount;      /* Length of title string */
UCHAR uchName[40];  / Buffer for title */
UCHAR uchName[40];  /* Buffer for title */


nbkData *somThis = nbkGetData(somSelf);
nbkData *somThis = nbkGetData(somSelf);
nbkMethodDebug(&quot;nbk&quot;,&quot;wpRestoreState&quot;);
nbkMethodDebug("nbk","wpRestoreState");


ulCount = 40L;                                     /* Size of input buffer */
ulCount = 40L;                                   /* Size of input buffer */
fSuccess = _wpRestoreString ( somSelf               /* Self pointer */
fSuccess = _wpRestoreString ( somSelf             /* Self pointer */
                             , (PSZ) &quot;nbk&quot;              /* Class name */
                             , (PSZ) "nbk"        /* Class name */
                             , WPNBK_KEY               /* Key for data */
                             , WPNBK_KEY           /* Key for data */
                             , &amp;uchName                 /* String to receive data */
                             , &uchName           /* String to receive data */
                             , &amp;ulCount  );           /* Amount of data returned */
                             , &ulCount  );       /* Amount of data returned */


if ( !fSuccess ) {  /* First time object is being restored */
if ( !fSuccess ) {  /* First time object is being restored */


     // initialize string to NULL
     // initialize string to NULL
     strcpy ( uchName, &quot;&quot; );
     strcpy ( uchName, "" );


     // save initial string to ini file
     // save initial string to ini file
     _wpSaveString ( somSelf                /* Self pointer */
     _wpSaveString ( somSelf                /* Self pointer */
                   , (PSZ) &quot;nbk&quot;                /* Class name */
                   , (PSZ) "nbk"            /* Class name */
                   , WPNBK_KEY                 /* Key of data */
                   , WPNBK_KEY               /* Key of data */
                   , uchName  );             /* String to write */
                   , uchName  );           /* String to write */
}
}


Line 92: Line 65:


return (parent_wpRestoreState(somSelf,ulReserved));
return (parent_wpRestoreState(somSelf,ulReserved));
}
}
</PRE>
</PRE>

Latest revision as of 22:52, 16 November 2025

This instance method is called to allow the object to restore an ASCIIZ instance data string.

Syntax

_wpRestoreString(somSelf, pszClass, ulKey, pszValue, pcbValue)

Parameters

somSelf (WPObject *) - input
Pointer to the object on which the method is being invoked.
Points to an object of class WPObject.
pszClass (PSZ) - input
Pointer to the class name.
A pointer to a zero-terminated string that contains any unique string. The class name is recommended but not enforced.
ulKey (ULONG) - input
Class-defined identifier.
A class-defined identifier that correlates to a particular instance data variable.
pszValue (PSZ) - in/out
Address of the string to be restored.
pcbValue (PULONG) - in/out
Size of string to be restored.
If pszValue is NULL, the actual size is returned in pcbValue.

Returns

rc (BOOL) - returns
Success indicator.
TRUE: Successful completion.
FALSE: Error occurred.

Remarks

This method restores an ASCIIZ string that was saved by a call to wpSaveString.

Usage

This method can be called only during the processing of the wpRestoreState method.

How to Override

This method is generally not overridden.

Example Code

This example demonstrates an override of wpRestoreState method to save string data.

SOM_Scope BOOL    SOMLINK wpRestoreState(nbk   somSelf,
ULONG ulReserved)
{
BOOL fSuccess;       /* Success flag */
ULONG ulCount;       /* Length of title string */
UCHAR uchName[40];   /* Buffer for title */

nbkData *somThis = nbkGetData(somSelf);
nbkMethodDebug("nbk","wpRestoreState");

ulCount = 40L;                                    /* Size of input buffer */
fSuccess = _wpRestoreString ( somSelf             /* Self pointer */
                            , (PSZ) "nbk"         /* Class name */
                            , WPNBK_KEY           /* Key for data */
                            , &uchName            /* String to receive data */
                            , &ulCount   );       /* Amount of data returned */

if ( !fSuccess ) {   /* First time object is being restored */

    // initialize string to NULL
    strcpy ( uchName, "" );

    // save initial string to ini file
    _wpSaveString ( somSelf                 /* Self pointer */
                  , (PSZ) "nbk"             /* Class name */
                  , WPNBK_KEY               /* Key of data */
                  , uchName   );            /* String to write */
}

_UserSetTitle ( somSelf, uchName );   /* Set an instance variable */

return (parent_wpRestoreState(somSelf,ulReserved));
}

Related Methods