ここでは、以下の処理をするプログラムを説明します。
保管フォルダ内の帳票一覧を取得します。
取得した帳票名が「2000年度」で前方一致するかを比較します。
前方一致した場合、その帳票を削除します。
Windows版の場合
32bit版の場合
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "lvsvapi.h"
typedef int (WINAPI* LPSTARTSVAPI)();
typedef int (WINAPI* LPENDSVAPI)(int);
typedef int (WINAPI* LPGETSERVERERRCODE)(int);
typedef int (WINAPI* LPGETSERVERERRMSG)(int, char*);
typedef int (WINAPI* LPSTARTKEEPFOLDER)(int, char*, int);
typedef int (WINAPI* LPENDKEEPFOLDER)(int, int);
typedef int (WINAPI* LPGETKEEPFOLDERCOUNT)(int, int, int*);
typedef int (WINAPI* LPGETKEEPFOLDERITEM)(int, int, int, LPKPFINFO);
typedef int (WINAPI* LPSTARTKEEPLIST)(int, char*);
typedef int (WINAPI* LPENDKEEPLIST)(int, int);
typedef int (WINAPI* LPGETKEEPLISTCOUNT)(int, int, int*);
typedef int (WINAPI* LPGETKEEPLISTITEM)(int, int, int, LPKPLINFO);
typedef int (WINAPI* LPDELETEKEEPFILE)(int, char*);
/******************************************************************************/
/* 1.機能概要 */
/* 1) 保管フォルダの一覧を取得する。 */
/* 2) 保管フォルダ内の帳票一覧を取得する。 */
/* 3) 取得した帳票名が、「2000年度」で前方一致するか比較する。 */
/* 比較した結果、前方一致したら、その帳票を削除する。 */
/******************************************************************************/
void main(int iArgc, char* cArgv[])
{
HINSTANCE hinSvAPi = NULL;
int iRetCode = 0 ; /* 関数復帰値 */
int iLwSvApiH = 0; /* サーバAPIハンドル */
int iLwSvKpFH = 0; /* 保管フォルダ一覧ハンドル */
int iLwSvKpLH = 0; /* 保管フォルダ帳票一覧ハンドル */
int iKpFCount = 0; /* 保管フォルダ数 */
KPFINFO KpFInfo; /* 保管フォルダ情報構造体 */
LPKPFINFO lpKpFInfo = &KpFInfo;
KPLINFO KpLInfo; /* 帳票一覧情報構造体 */
LPKPLINFO lpKpLInfo = &KpLInfo;
int iKpLCount = 0; /* 帳票一覧数 */
int ie_ErrCode = 0; /* エラーコード */
char ce_ErrMsg[1024]; /* エラーメッセージ格納域 */
int iKpFIndex = 0; /* フォルダカウンタ */
int iKpLIndex = 0; /* 帳票カウンタ */
int iFindFlg = 0; /* フラグ */
char ceDeleteFile[260+4]; /* 削除対象ファイル */
/****************************************************************************/
/* サーバAPI関数宣言 */
/****************************************************************************/
int (WINAPI* fp_StartSvApi)();
int (WINAPI* fp_EndSvApi)(int);
int (WINAPI* fp_GetServerApiErrCode)(int);
int (WINAPI* fp_GetServerApiErrMsg)(int, char*);
int (WINAPI* fp_StartKeepFolder)(int, char*, int);
int (WINAPI* fp_EndKeepFolder)(int, int);
int (WINAPI* fp_GetKeepFolderCount)(int, int, int*);
int (WINAPI* fp_GetKeepFolderItem)(int, int, int, LPKPFINFO);
int (WINAPI* fp_StartKeepList)(int, char*);
int (WINAPI* fp_EndKeepList)(int, int);
int (WINAPI* fp_GetKeepListCount)(int, int, int*);
int (WINAPI* fp_GetKeepListItem)(int, int, int, LPKPLINFO);
int (WINAPI* fp_DeleteKeepFile)(int, char*);
/****************************************************************************/
/* 初期化処理 */
/****************************************************************************/
memset(ceDeleteFile, 0, 260+4);
/****************************************************************************/
/* サーバAPIライブラリ(F5cwsapi.dll)のロード */
/****************************************************************************/
hinSvAPi = LoadLibrary("F5cwsapi.dll");
if(hinSvAPi == NULL)
{
printf("ライブラリF5cwsapi.dllのロードに失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* 関数アドレスを取得 */
/****************************************************************************/
fp_StartSvApi = (LPSTARTSVAPI)GetProcAddress(hinSvAPi, "LW_StartServerApi");
if(fp_StartSvApi == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndSvApi = (LPENDSVAPI)GetProcAddress(hinSvAPi, "LW_EndServerApi");
if(fp_EndSvApi == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetServerApiErrCode = (LPGETSERVERERRCODE)GetProcAddress(hinSvAPi,"LW_GetServerApiErrCode");
if(fp_GetServerApiErrCode == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetServerApiErrMsg = (LPGETSERVERERRMSG)GetProcAddress(hinSvAPi,"LW_GetServerApiErrMsg");
if(fp_GetServerApiErrMsg == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_StartKeepFolder = (LPSTARTKEEPFOLDER)GetProcAddress(hinSvAPi,"LW_StartKeepFolder");
if(fp_StartKeepFolder == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndKeepFolder = (LPENDKEEPFOLDER)GetProcAddress(hinSvAPi,"LW_EndKeepFolder");
if(fp_EndKeepFolder == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepFolderCount = (LPGETKEEPFOLDERCOUNT)GetProcAddress(hinSvAPi,"LW_GetKeepFolderCount");
if(fp_GetKeepFolderCount == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepFolderItem = (LPGETKEEPFOLDERITEM)GetProcAddress(hinSvAPi,"LW_GetKeepFolderItem");
if(fp_GetKeepFolderItem == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_StartKeepList = (LPSTARTKEEPLIST)GetProcAddress(hinSvAPi,"LW_StartKeepList");
if(fp_StartKeepList == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndKeepList = (LPENDKEEPLIST)GetProcAddress(hinSvAPi, "LW_EndKeepList");
if(fp_EndKeepList == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepListCount = (LPGETKEEPLISTCOUNT)GetProcAddress(hinSvAPi,"LW_GetKeepListCount");
if(fp_GetKeepListCount == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepListItem = (LPGETKEEPLISTITEM)GetProcAddress(hinSvAPi,"LW_GetKeepListItem");
if(fp_GetKeepListItem == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_DeleteKeepFile = (LPDELETEKEEPFILE)GetProcAddress(hinSvAPi,"LW_DeleteKeepFile");
if(fp_DeleteKeepFile == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* サーバAPI開始 */
/****************************************************************************/
iLwSvApiH = (*fp_StartSvApi)();
if(iLwSvApiH == 0)
{
printf("サーバAPIの開始(LW_StartServerApi)に失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ一覧開始 */
/****************************************************************************/
iLwSvKpFH = (*fp_StartKeepFolder)(iLwSvApiH, NULL, 0);
if(iLwSvKpFH == 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ数取得 */
/****************************************************************************/
iRetCode = (*fp_GetKeepFolderCount)(iLwSvApiH, iLwSvKpFH, &iKpFCount);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ数分ループする */
/****************************************************************************/
for(iKpFIndex = 0; iKpFIndex < iKpFCount; iKpFIndex ++)
{
/************************************************************************/
/* 保管フォルダ一覧情報を取得 */
/************************************************************************/
memset(lpKpFInfo, 0x00, sizeof(KPFINFO)); /* 初期化処理 */
lpKpFInfo->usf_Length = sizeof(KPFINFO); /* 構造体サイズ */
iRetCode = (*fp_GetKeepFolderItem)(iLwSvApiH, iLwSvKpFH, iKpFIndex,
lpKpFInfo);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧開始 */
/************************************************************************/
iLwSvKpLH = (*fp_StartKeepList)(iLwSvApiH, lpKpFInfo->cf_PathName);
if(iLwSvKpLH == 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
continue;
}
/************************************************************************/
/* 保管フォルダ内の帳票数取得 */
/************************************************************************/
iRetCode = (*fp_GetKeepListCount)(iLwSvApiH, iLwSvKpLH, &iKpLCount);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧数分ループする */
/************************************************************************/
for(iKpLIndex = 0; iKpLIndex < iKpLCount; iKpLIndex ++)
{
/********************************************************************/
/* 保管フォルダ内の帳票一覧情報の取得 */
/********************************************************************/
memset(lpKpLInfo, 0x00, sizeof(KPLINFO)); /* 初期化処理 */
lpKpLInfo->usl_Length = sizeof(KPLINFO); /* 構造体の長さ */
iRetCode = (*fp_GetKeepListItem)(iLwSvApiH, iLwSvKpLH, iKpLIndex,
lpKpLInfo);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
break;
}
/* 取得した帳票名が、"2000年度"か比較する */
iRetCode = memcmp(lpKpLInfo->cl_Title, "2000年度", 8);
if (iRetCode == 0)
{
/* 帳票の論理パス名を取得する */
iFindFlg = 1;
memcpy(ceDeleteFile, lpKpLInfo->cl_SplFile,264);
break;
}
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧終了 */
/************************************************************************/
if(iLwSvKpLH != 0)
{
(*fp_EndKeepList)(iLwSvApiH, iLwSvKpLH);
iLwSvKpLH = 0;
}
/* 該当する帳票が見つかったため、ループ処理を抜ける */
if (iFindFlg == 1)
break;
}
/****************************************************************************/
/* 保管フォルダ終了 */
/****************************************************************************/
if(iLwSvKpFH != 0)
{
(*fp_EndKeepFolder)(iLwSvApiH, iLwSvKpFH);
iLwSvKpFH = 0;
}
/****************************************************************************/
/* 保管フォルダ内の帳票の削除 */
/****************************************************************************/
if (iFindFlg == 1)
{
iRetCode = (*fp_DeleteKeepFile)(iLwSvApiH, ceDeleteFile);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
}
/****************************************************************************/
/* 終了処理 */
/****************************************************************************/
EXIT:
if(iLwSvKpLH != 0)
(*fp_EndKeepList)(iLwSvApiH, iLwSvKpLH);
if(iLwSvKpFH != 0)
(*fp_EndKeepFolder)(iLwSvApiH, iLwSvKpFH);
if(iLwSvApiH != 0)
(*fp_EndSvApi)(iLwSvApiH);
if(hinSvAPi != NULL)
FreeLibrary(hinSvAPi);
return;
}64bit版の場合
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "lvsvapi.h"
typedef INT_PTR (WINAPI* LPSTARTSVAPI)();
typedef int (WINAPI* LPENDSVAPI)(INT_PTR);
typedef int (WINAPI* LPGETSERVERERRCODE)(INT_PTR);
typedef int (WINAPI* LPGETSERVERERRMSG)(INT_PTR, char*);
typedef INT_PTR (WINAPI* LPSTARTKEEPFOLDER)(INT_PTR, char*, int);
typedef int (WINAPI* LPENDKEEPFOLDER)(INT_PTR, INT_PTR);
typedef int (WINAPI* LPGETKEEPFOLDERCOUNT)(INT_PTR, INT_PTR, int*);
typedef int (WINAPI* LPGETKEEPFOLDERITEM)(INT_PTR, INT_PTR, int, LPKPFINFO);
typedef INT_PTR(WINAPI* LPSTARTKEEPLIST)(INT_PTR, char*);
typedef int (WINAPI* LPENDKEEPLIST)(INT_PTR, INT_PTR);
typedef int (WINAPI* LPGETKEEPLISTCOUNT)(INT_PTR, INT_PTR, int*);
typedef int (WINAPI* LPGETKEEPLISTITEM)(INT_PTR, INT_PTR, int, LPKPLINFO);
typedef int (WINAPI* LPDELETEKEEPFILE)(INT_PTR, char*);
/******************************************************************************/
/* 1.機能概要 */
/* 1) 保管フォルダの一覧を取得する。 */
/* 2) 保管フォルダ内の帳票一覧を取得する。 */
/* 3) 取得した帳票名が、「2000年度」で前方一致するか比較する。 */
/* 比較した結果、前方一致したら、その帳票を削除する。 */
/******************************************************************************/
void main(int iArgc, char* cArgv[])
{
HINSTANCE hinSvAPi = NULL;
int iRetCode = 0; /* 関数復帰値 */
INT_PTR iLwSvApiH = 0; /* サーバAPIハンドル */
INT_PTR iLwSvKpFH = 0; /* 保管フォルダ一覧ハンドル */
INT_PTR iLwSvKpLH = 0; /* 保管フォルダ帳票一覧ハンドル */
int iKpFCount = 0; /* 保管フォルダ数 */
KPFINFO KpFInfo; /* 保管フォルダ情報構造体 */
LPKPFINFO lpKpFInfo = &KpFInfo;
KPLINFO KpLInfo; /* 帳票一覧情報構造体 */
LPKPLINFO lpKpLInfo = &KpLInfo;
int iKpLCount = 0; /* 帳票一覧数 */
int ie_ErrCode = 0; /* エラーコード */
char ce_ErrMsg[1024]; /* エラーメッセージ格納域 */
int iKpFIndex = 0; /* フォルダカウンタ */
int iKpLIndex = 0; /* 帳票カウンタ */
int iFindFlg = 0; /* フラグ */
char ceDeleteFile[260+4]; /* 削除対象ファイル */
/****************************************************************************/
/* サーバAPI関数宣言 */
/****************************************************************************/
INT_PTR(WINAPI* fp_StartSvApi)() = NULL;
int (WINAPI* fp_EndSvApi)(INT_PTR) = NULL;
int (WINAPI* fp_GetServerApiErrCode)(INT_PTR) = NULL;
int (WINAPI* fp_GetServerApiErrMsg)(INT_PTR, char*) = NULL;
INT_PTR(WINAPI* fp_StartKeepFolder)(INT_PTR, char*, int) = NULL;
int (WINAPI* fp_EndKeepFolder)(INT_PTR, INT_PTR) = NULL;
int (WINAPI* fp_GetKeepFolderCount)(INT_PTR, INT_PTR, int*) = NULL;
int (WINAPI* fp_GetKeepFolderItem)(INT_PTR, INT_PTR, int, LPKPFINFO) = NULL;
INT_PTR(WINAPI* fp_StartKeepList)(INT_PTR, char*) = NULL;
int (WINAPI* fp_EndKeepList)(INT_PTR, INT_PTR) = NULL;
int (WINAPI* fp_GetKeepListCount)(INT_PTR, INT_PTR, int*) = NULL;
int (WINAPI* fp_GetKeepListItem)(INT_PTR, INT_PTR, int, LPKPLINFO) = NULL;
int (WINAPI* fp_DeleteKeepFile)(INT_PTR, char*) = NULL;
/****************************************************************************/
/* 初期化処理 */
/****************************************************************************/
memset(ceDeleteFile, 0, 260+4);
/****************************************************************************/
/* サーバAPIライブラリ(F4cwsapi.dll)のロード */
/****************************************************************************/
hinSvAPi = LoadLibrary("F4cwsapi.dll");
if(hinSvAPi == NULL)
{
printf("ライブラリF4cwsapi.dllのロードに失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* 関数アドレスを取得 */
/****************************************************************************/
fp_StartSvApi = (LPSTARTSVAPI)GetProcAddress(hinSvAPi, "LW_StartServerApi");
if(fp_StartSvApi == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndSvApi = (LPENDSVAPI)GetProcAddress(hinSvAPi, "LW_EndServerApi");
if(fp_EndSvApi == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetServerApiErrCode = (LPGETSERVERERRCODE)GetProcAddress(hinSvAPi, "LW_GetServerApiErrCode");
if(fp_GetServerApiErrCode == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetServerApiErrMsg = (LPGETSERVERERRMSG)GetProcAddress(hinSvAPi, "LW_GetServerApiErrMsg");
if(fp_GetServerApiErrMsg == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_StartKeepFolder = (LPSTARTKEEPFOLDER)GetProcAddress(hinSvAPi, "LW_StartKeepFolder");
if(fp_StartKeepFolder == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndKeepFolder = (LPENDKEEPFOLDER)GetProcAddress(hinSvAPi, "LW_EndKeepFolder");
if(fp_EndKeepFolder == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepFolderCount = (LPGETKEEPFOLDERCOUNT)GetProcAddress(hinSvAPi, "LW_GetKeepFolderCount");
if(fp_GetKeepFolderCount == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepFolderItem = (LPGETKEEPFOLDERITEM)GetProcAddress(hinSvAPi, "LW_GetKeepFolderItem");
if(fp_GetKeepFolderItem == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_StartKeepList = (LPSTARTKEEPLIST)GetProcAddress(hinSvAPi, "LW_StartKeepList");
if(fp_StartKeepList == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndKeepList = (LPENDKEEPLIST)GetProcAddress(hinSvAPi, "LW_EndKeepList");
if(fp_EndKeepList == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepListCount = (LPGETKEEPLISTCOUNT)GetProcAddress(hinSvAPi, "LW_GetKeepListCount");
if(fp_GetKeepListCount == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepListItem = (LPGETKEEPLISTITEM)GetProcAddress(hinSvAPi, "LW_GetKeepListItem");
if(fp_GetKeepListItem == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_DeleteKeepFile = (LPDELETEKEEPFILE)GetProcAddress(hinSvAPi, "LW_DeleteKeepFile");
if(fp_DeleteKeepFile == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* サーバAPI開始 */
/****************************************************************************/
iLwSvApiH = (*fp_StartSvApi)();
if(iLwSvApiH == 0)
{
printf("サーバAPIの開始(LW_StartServerApi)に失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ一覧開始 */
/****************************************************************************/
iLwSvKpFH = (*fp_StartKeepFolder)(iLwSvApiH, NULL, 0);
if(iLwSvKpFH == 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ数取得 */
/****************************************************************************/
iRetCode = (*fp_GetKeepFolderCount)(iLwSvApiH, iLwSvKpFH, &iKpFCount);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ数分ループする */
/****************************************************************************/
for(iKpFIndex = 0; iKpFIndex < iKpFCount; iKpFIndex ++)
{
/************************************************************************/
/* 保管フォルダ一覧情報を取得 */
/************************************************************************/
memset(lpKpFInfo, 0x00, sizeof(KPFINFO)); /* 初期化処理 */
lpKpFInfo->usf_Length = sizeof(KPFINFO); /* 構造体サイズ */
iRetCode = (*fp_GetKeepFolderItem)(iLwSvApiH, iLwSvKpFH, iKpFIndex, lpKpFInfo);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧開始 */
/************************************************************************/
iLwSvKpLH = (*fp_StartKeepList)(iLwSvApiH, lpKpFInfo->cf_PathName);
if(iLwSvKpLH == 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
continue;
}
/************************************************************************/
/* 保管フォルダ内の帳票数取得 */
/************************************************************************/
iRetCode = (*fp_GetKeepListCount)(iLwSvApiH, iLwSvKpLH, &iKpLCount);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧数分ループする */
/************************************************************************/
for(iKpLIndex = 0; iKpLIndex < iKpLCount; iKpLIndex ++)
{
/********************************************************************/
/* 保管フォルダ内の帳票一覧情報の取得 */
/********************************************************************/
memset(lpKpLInfo, 0x00, sizeof(KPLINFO)); /* 初期化処理 */
lpKpLInfo->usl_Length = sizeof(KPLINFO); /* 構造体の長さ */
iRetCode = (*fp_GetKeepListItem)(iLwSvApiH, iLwSvKpLH, iKpLIndex, lpKpLInfo);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
break;
}
/* 取得した帳票名が、"2000年度"か比較する */
iRetCode = memcmp(lpKpLInfo->cl_Title, "2000年度", 8);
if (iRetCode == 0)
{
/* 帳票の論理パス名を取得する */
iFindFlg = 1;
memcpy(ceDeleteFile, lpKpLInfo->cl_SplFile, 264);
break;
}
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧終了 */
/************************************************************************/
if(iLwSvKpLH != 0)
{
(*fp_EndKeepList)(iLwSvApiH, iLwSvKpLH);
iLwSvKpLH = 0;
}
/* 該当する帳票が見つかったため、ループ処理を抜ける */
if (iFindFlg == 1)
break;
}
/****************************************************************************/
/* 保管フォルダ終了 */
/****************************************************************************/
if(iLwSvKpFH != 0)
{
(*fp_EndKeepFolder)(iLwSvApiH, iLwSvKpFH);
iLwSvKpFH = 0;
}
/****************************************************************************/
/* 保管フォルダ内の帳票の削除 */
/****************************************************************************/
if (iFindFlg == 1)
{
iRetCode = (*fp_DeleteKeepFile)(iLwSvApiH, ceDeleteFile);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
}
/******************************************************************************/
/* 終了処理 */
/******************************************************************************/
EXIT:
if(iLwSvKpLH != 0)
(*fp_EndKeepList)(iLwSvApiH, iLwSvKpLH);
if(iLwSvKpFH != 0)
(*fp_EndKeepFolder)(iLwSvApiH, iLwSvKpFH);
if(iLwSvApiH != 0)
(*fp_EndSvApi)(iLwSvApiH);
FreeLibrary(hinSvAPi);
return;
}Solaris版の場合
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include "lvsvapi.h"
typedef int (*LPSTARTSVAPI)();
typedef int (*LPENDSVAPI)(int);
typedef int (*LPGETSERVERERRCODE)(int);
typedef int (*LPGETSERVERERRMSG)(int, char*);
typedef int (*LPSTARTKEEPFOLDER)(int, char*, int);
typedef int (*LPENDKEEPFOLDER)(int, int);
typedef int (*LPGETKEEPFOLDERCOUNT)(int, int, int*);
typedef int (*LPGETKEEPFOLDERITEM)(int, int, int, LPKPFINFO);
typedef int (*LPSTARTKEEPLIST)(int, char*);
typedef int (*LPENDKEEPLIST)(int, int);
typedef int (*LPGETKEEPLISTCOUNT)(int, int, int*);
typedef int (*LPGETKEEPLISTITEM)(int, int, int, LPKPLINFO);
typedef int (*LPDELETEKEEPFILE)(int, char*);
/******************************************************************************/
/* 1.機能概要 */
/* 1) 保管フォルダの一覧を取得する。 */
/* 2) 保管フォルダ内の帳票一覧を取得する。 */
/* 3) 取得した帳票名が、「2000年度」で前方一致するか比較する。 */
/* 比較した結果、前方一致したら、その帳票を削除する。 */
/******************************************************************************/
void main(int iArgc, char* cArgv[])
{
void *hinSvAPi = NULL;
int iRetCode = 0; /* 関数復帰値 */
int iLwSvApiH = 0; /* サーバAPIハンドル */
int iLwSvKpFH = 0; /* 保管フォルダ一覧ハンドル */
int iLwSvKpLH = 0; /* 保管フォルダ帳票一覧ハンドル*/
int iKpFCount = 0; /* 保管フォルダ数 */
KPFINFO KpFInfo; /* 保管フォルダ情報構造体 */
LPKPFINFO lpKpFInfo = &KpFInfo;
KPLINFO KpLInfo; /* 帳票一覧情報構造体 */
LPKPLINFO lpKpLInfo = &KpLInfo;
int iKpLCount = 0; /* 帳票一覧数 */
int ie_ErrCode = 0; /* エラーコード */
char ce_ErrMsg[1024]; /* エラーメッセージ格納域 */
int iKpFIndex = 0; /* フォルダカウンタ */
int iKpLIndex = 0; /* 帳票カウンタ */
int iFindFlg = 0; /* フラグ */
char ceDeleteFile[260+4]; /* 削除対象ファイル */
/****************************************************************************/
/* サーバAPI関数宣言 */
/****************************************************************************/
int (*fp_StartSvApi)();
int (*fp_EndSvApi)(int);
int (*fp_GetServerApiErrCode)(int);
int (*fp_GetServerApiErrMsg)(int, char*);
int (*fp_StartKeepFolder)(int, char*, int);
int (*fp_EndKeepFolder)(int, int);
int (*fp_GetKeepFolderCount)(int, int, int*);
int (*fp_GetKeepFolderItem)(int, int, int, LPKPFINFO);
int (*fp_StartKeepList)(int, char*);
int (*fp_EndKeepList)(int, int);
int (*fp_GetKeepListCount)(int, int, int*);
int (*fp_GetKeepListItem)(int, int, int, LPKPLINFO);
int (*fp_DeleteKeepFile)(int, char*);
/****************************************************************************/
/* 初期化処理 */
/****************************************************************************/
memset(ceDeleteFile, 0, 260+4);
/****************************************************************************/
/* サーバAPIライブラリ(liblwapi.so)のロード */
/****************************************************************************/
hinSvAPi = dlopen("/usr/lib/liblwapi.so", RTLD_LAZY);
if(hinSvAPi == NULL)
{
printf("ライブラリliblwapi.soのロードに失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* 関数アドレスを取得 */
/****************************************************************************/
fp_StartSvApi = (LPSTARTSVAPI)dlsym(hinSvAPi, "LW_StartServerApi");
if(fp_StartSvApi == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndSvApi = (LPENDSVAPI)dlsym(hinSvAPi, "LW_EndServerApi");
if(fp_EndSvApi == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetServerApiErrCode = (LPGETSERVERERRCODE)dlsym(hinSvAPi,"LW_GetServerApiErrCode");
if(fp_GetServerApiErrCode == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetServerApiErrMsg = (LPGETSERVERERRMSG)dlsym(hinSvAPi,"LW_GetServerApiErrMsg");
if(fp_GetServerApiErrMsg == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_StartKeepFolder = (LPSTARTKEEPFOLDER)dlsym(hinSvAPi,"LW_StartKeepFolder");
if(fp_StartKeepFolder == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndKeepFolder = (LPENDKEEPFOLDER)dlsym(hinSvAPi, "LW_EndKeepFolder");
if(fp_EndKeepFolder == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepFolderCount = (LPGETKEEPFOLDERCOUNT)dlsym(hinSvAPi,"LW_GetKeepFolderCount");
if(fp_GetKeepFolderCount == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepFolderItem = (LPGETKEEPFOLDERITEM)dlsym(hinSvAPi,"LW_GetKeepFolderItem");
if(fp_GetKeepFolderItem == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_StartKeepList = (LPSTARTKEEPLIST)dlsym(hinSvAPi, "LW_StartKeepList");
if(fp_StartKeepList == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_EndKeepList = (LPENDKEEPLIST)dlsym(hinSvAPi, "LW_EndKeepList");
if(fp_EndKeepList == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepListCount = (LPGETKEEPLISTCOUNT)dlsym(hinSvAPi,"LW_GetKeepListCount");
if(fp_GetKeepListCount == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_GetKeepListItem = (LPGETKEEPLISTITEM)dlsym(hinSvAPi,"LW_GetKeepListItem");
if(fp_GetKeepListItem == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
fp_DeleteKeepFile = (LPDELETEKEEPFILE)dlsym(hinSvAPi,"LW_DeleteKeepFile");
if(fp_DeleteKeepFile == NULL)
{
printf("関数アドレスの取得に失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* サーバAPI開始 */
/****************************************************************************/
iLwSvApiH = (*fp_StartSvApi)();
if(iLwSvApiH == 0)
{
printf("サーバAPIの開始(LW_StartServerApi)に失敗しました。\n");
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ一覧開始 */
/****************************************************************************/
iLwSvKpFH = (*fp_StartKeepFolder)(iLwSvApiH, NULL, 0);
if(iLwSvKpFH == 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ数取得 */
/****************************************************************************/
iRetCode = (*fp_GetKeepFolderCount)(iLwSvApiH, iLwSvKpFH, &iKpFCount);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/****************************************************************************/
/* 保管フォルダ数分ループする */
/****************************************************************************/
for(iKpFIndex = 0; iKpFIndex < iKpFCount; iKpFIndex ++)
{
/************************************************************************/
/* 保管フォルダ一覧情報を取得 */
/************************************************************************/
memset(lpKpFInfo, 0, sizeof(KPFINFO));/* 初期化処理 */
lpKpFInfo->usf_Length = sizeof(KPFINFO) ;/* 構造体サイズ */
iRetCode = (*fp_GetKeepFolderItem)(iLwSvApiH, iLwSvKpFH,
iKpFIndex, lpKpFInfo);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧開始 */
/************************************************************************/
iLwSvKpLH = (*fp_StartKeepList)(iLwSvApiH,
lpKpFInfo->cf_PathName);
if(iLwSvKpLH == 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
continue;
}
/************************************************************************/
/* 保管フォルダ内の帳票数取得 */
/************************************************************************/
iRetCode = (*fp_GetKeepListCount)(iLwSvApiH, iLwSvKpLH, &iKpLCount);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧数分ループする */
/************************************************************************/
for(iKpLIndex = 0; iKpLIndex < iKpLCount; iKpLIndex ++)
{
/********************************************************************/
/* 保管フォルダ内の帳票一覧情報の取得 */
/********************************************************************/
memset(lpKpLInfo, 0, sizeof(KPLINFO));/* 初期化処理 */
lpKpLInfo->usl_Length = sizeof(KPLINFO); /* 構造体の長さ */
iRetCode = (*fp_GetKeepListItem)(iLwSvApiH, iLwSvKpLH, iKpLIndex,
lpKpLInfo);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
break;
}
/* 取得した帳票名が、"2000年度"か比較する */
iRetCode = memcmp(lpKpLInfo->cl_Title, "2000年度", 8);
if(iRetCode == 0)
{
/* 帳票の論理パス名を取得する */
iFindFlg = 1;
strcpy(ceDeleteFile, lpKpLInfo->cl_SplFile);
break;
}
}
/************************************************************************/
/* 保管フォルダ内の帳票一覧終了 */
/************************************************************************/
if(iLwSvKpLH != 0)
{
(*fp_EndKeepList)(iLwSvApiH, iLwSvKpLH);
iLwSvKpLH = 0;
}
/* 該当する帳票が見つかったため、ループ処理を抜ける */
if(iFindFlg == 1)
break;
}
/****************************************************************************/
/* 保管フォルダ終了 */
/****************************************************************************/
if(iLwSvKpFH != 0)
{
(*fp_EndKeepFolder)(iLwSvApiH, iLwSvKpFH);
iLwSvKpFH = 0;
}
/****************************************************************************/
/* 保管フォルダ内の帳票の削除(論理パス指定) */
/****************************************************************************/
if(iFindFlg == 1)
{
iRetCode = (*fp_DeleteKeepFile)(iLwSvApiH, ceDeleteFile);
if(iRetCode != 0)
{
(*fp_GetServerApiErrMsg)(iLwSvApiH, ce_ErrMsg);
ie_ErrCode = (*fp_GetServerApiErrCode)(iLwSvApiH);
printf("%s RC=%d", ce_ErrMsg, ie_ErrCode);
goto EXIT;
}
}
/****************************************************************************/
/* 終了処理 */
/****************************************************************************/
EXIT:
if(iLwSvKpLH != 0)
(*fp_EndKeepList)(iLwSvApiH, iLwSvKpLH);
if(iLwSvKpFH != 0)
(*fp_EndKeepFolder)(iLwSvApiH, iLwSvKpFH);
if(iLwSvApiH != 0)
(*fp_EndSvApi)(iLwSvApiH);
if(hinSvAPi != NULL)
dlclose(hinSvAPi);
return;
}