Symantec logo

Example: Using C++ entry points on Windows

The example in this section shows how to build the FileOnOff agent using your own VCSAgStartup entry point and the C++ version of online, offline, and monitor entry points. This example implements the VCSAgStartup, online, offline, and monitor entry points only.


  Note   You must first install Visual C++ on the system on which the agent will be built.


Example: VCSAgStartup and C++ entry points

Create the following directory for the agent sources: %VCS_HOME%\src\agent\FileOnOff:

C:\> md %VCS_HOME%\src\agent\FileOnOff

  1. Copy the contents of the sample agnet directory to the directory you created in the previous step:

C:\> cp %VCS_HOME%\src\agent\Sample\* %VCS_HOME%\src\

agent\FileOnOff

  1. Change to the new directory:

C:\> cd %VCS_HOME%\src\agent\FileOnOff

  1. Edit the file sample.C and modify the VCSAgStartup() function
    (the last several lines) to match the following example:

void VCSAgStartup()

{

// This example implements online, offline, and

// monitor entry points using C++.

VCSAG_LOG_INIT("VCSAgStartup");

VCSAgSetLogCategory(10051);

VCSAgInitEntryPointStruct(V50);

VCSAgSetEntryPoint(VCSAgEPMonitor, res_monitor);

VCSAgSetEntryPoint(VCSAgEPOnline, res_online);

VCSAgSetEntryPoint(VCSAgEPOffline, res_offline);

}

  1. Modify res_online() and res_offline():

// This is a C++ implementation of the online entry

// point for the FileOnOff resource type.

// This function brings online a FileOnOff

// resource by creating the corresponding file.

// It is assumed that the complete pathname of the

// file will be passed as the first

// ArgList attribute.

unsigned int res_online(const char *res_name,

void **attr_val) {

WCHAR **new_args = NULL;

DWORD ret;

HANDLE hFile = NULL;

VCSAG_LOG_INIT("res_online");

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,

L"Inside online.");

ret = VCSAgGetEncodedArgList(VCSAgUTF8, attr_val, VCSAgUCS2,

(void ***)&new_args);

if (ret)

{

VCSAG_LOG_MSG(VCS_NOTICE, 1001, VCS_DEFAULT_FLAGS,

L"Unable to get the arguments");

goto exit;

}

hFile = CreateFile((WCHAR *)new_args[0], GENERIC_READ |

GENERIC_WRITE,0, NULL, OPEN_ALWAYS,

res_ATTRIBUTE_NORMAL, (HANDLE)NULL);

if (!hFile || hFile == INVALID_HANDLE_VALUE)

{

VCSAG_LOG_MSG(VCS_ERROR, 1002, VCS_DEFAULT_FLAGS,

L"Unable to create the file" );

}

else

{

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,

L"Online successful."); CloseHandle(hFile);

}

exit:

if(new_args)

VCSAgDelEncodedArgList((void**)new_args);

return 0;

}

// This is a C++ implementation of the offline

// entry point for the FileOnOff resource type.

// This function takes offline aFileOnOff

// resource by deleting the corresponding file. It

// is assumed that the complete pathname of the

// file will be passed as the first

// ArgList attribute.

unsigned int res_offline(const char *res_name,

void **attr_val)

{

WCHAR **new_args = NULL;

DWORD ret;

VCSAG_LOG_INIT("res_offline");

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,

L"Inside offline.");

ret = VCSAgGetEncodedArgList(VCSAgUTF8, attr_val,

VCSAgUCS2,(void ***)&new_args);

if (ret)

{

VCSAG_LOG_MSG(VCS_NOTICE, 1001, VCS_DEFAULT_FLAGS,

L"Unable to get the arguments");

goto exit;

}

if (!DeleteFile((WCHAR *)new_args[0]))

{

VCSAG_LOG_MSG(VCS_ERROR, 1003, VCS_DEFAULT_FLAGS,

L"Unable to delete the file" );

}

else

{

VCSAG_RES_LOG_MSG(VCS_DBG1, VCS_DEFAULT_FLAGS,

L"offline successful.");

}

exit:

if(new_args)

VCSAgDelEncodedArgList((void**)new_args);

return 0;

}

  1. Modify the res_monitor() function.

    See Example: Using VCSAgStartup() and script entry points on Windows.

  2. Compile sample.C and build the agent by invoking nmake. (Makefile is provided.)

C:\> nmake

  1. Create a directory for the agent binaries:

    %VCS_HOME%\bin\FileOnOff:

C:\> md %VCS_HOME%\bin\FileOnOff

  1. Place the sample.dll as the FileOnOff agent library.

C:\> copy sample.dll %VCS_HOME%\bin\FileOnOff\FileOnOff.dll