Interview Questions

How to pass parameters between WinRunner and the DLL function?

Mercury WinRunner FAQ


(Continued from previous question...)

How to pass parameters between WinRunner and the DLL function?

Passing Strings (a DLL function):
In WinRunner,
extern int WrTestFunction1( in string );
In the DLL,
WR_EXPORTED int WrTestFunction1( char *lcStringArg1 )
{
. . .
return( {some int value} ); }
And then to use it in WinRunner,
WrTestFunction1( "Fred" );
Receiving Strings:
In WinRunner,
extern int WrTestFunction1( out string <10>); #The <10> tells WinRunner how much space to use for a buffer for the returned string.
In the DLL,
WR_EXPORTED int WrTestFunction1( char *lcStringArg1 )
{
. . .
{some code that populates lcStringArg1};
. . .
return( {some int value} );
}
And then to use it in WinRunner,
WrTestFunction1( lcString1 );
# lcString1 now contains a value passed back from the DLL function

Passing Numbers (a DLL function)
In WinRunner,
extern int WrTestFunction1( in int );
In the DLL,
WR_EXPORTED int WrTestFunction1( int lnIntegerArg1 )
{
. . .
return( {some int value} );
}
And then to use it in WinRunner,
WrTestFunction1( 2 );
Recieving Numbers
In WinRunner,
extern int WrTestFunction1( out int );
In the DLL,
WR_EXPORTED int WrTestFunction1( int *lnIntegerArg1 )
{
. . .
*lnIntegerArg1 = {some number};
return( {some int value} );
}
And then to use it in WinRunner,
WrTestFunction1( lnNum );
# lnNum now contains a value passed back from the DLL function

Here are some example functions.
#define WR_EXPORTED extern "C" __stdcall __declspec(dllexport)
#define WR_SUCCESS 0
#define WR_FAILURE 100000
#define FAILURE 0
#define WR_STAGE_1 10000
#define WR_STAGE_2 20000
#define WR_STAGE_3 30000
#define WR_STAGE_4 40000
#define WR_STAGE_5 50000
#define WR_STAGE_6 60000
#define WR_STAGE_7 70000
#define WR_STAGE_8 80000
#define WR_STAGE_9 90000
#define MAX_USERNAME_LENGTH 256
#define HOST_NAME_SIZE 64
WR_EXPORTED UINT WrGetComputerName( LPTSTR lcComputerName )
{
BOOL lbResult;
DWORD lnNameSize = MAX_COMPUTERNAME_LENGTH + 1;
// Stage 1
lbResult = GetComputerName( lcComputerName, &lnNameSize );
if( lbResult == FAILURE )
return( WR_FAILURE + WR_STAGE_1 + GetLastError() );
return( WR_SUCCESS );
}
WR_EXPORTED UINT WrCopyFile( LPCTSTR lcSourceFile, LPCTSTR lcDestFile, BOOL lnFailIfExistsFlag )
{
BOOL lbResult;
// Stage 1
lbResult = CopyFile( lcSourceFile, lcDestFile, lnFailIfExistsFlag );
if( lbResult == FAILURE )
return( WR_FAILURE + WR_STAGE_1 + GetLastError() );
return( WR_SUCCESS );
}
WR_EXPORTED UINT WrGetDiskFreeSpace( LPCTSTR lcDirectoryName,
LPDWORD lnUserFreeBytesLo,
LPDWORD lnUserFreeBytesHi,
LPDWORD lnTotalBytesLo,
LPDWORD lnTotalBytesHi,
LPDWORD lnTotalFreeBytesLo,
LPDWORD lnTotalFreeBytesHi )
{
BOOL lbResult;
ULARGE_INTEGER lsUserFreeBytes,
lsTotalBytes,
lsTotalFreeBytes;
// Stage 1
lbResult = GetDiskFreeSpaceEx( lcDirectoryName,
&lsUserFreeBytes,
&lsTotalBytes,
&lsTotalFreeBytes );
if( lbResult == FAILURE )
return( WR_FAILURE + WR_STAGE_1 + GetLastError() );
*lnUserFreeBytesLo = lsUserFreeBytes.LowPart;
*lnUserFreeBytesHi = lsUserFreeBytes.HighPart;
*lnTotalBytesLo = lsTotalBytes.LowPart;
*lnTotalBytesHi = lsTotalBytes.HighPart;
*lnTotalFreeBytesLo = lsTotalFreeBytes.LowPart;
*lnTotalFreeBytesHi = lsTotalFreeBytes.HighPart;
return( WR_SUCCESS );
}

(Continued on next question...)

Other Interview Questions