|
お疲れさまです。
RPCプログラムのクライアント編です。
■RPCクライアントサンプル
#include "rpcservice.h" // MIDLより生成するヘッダファイル(RPC関数定義)
DWORD WINAPI dwRpcFileProc ( LPVOID lpv )
{ RPC_STATUS lngStatus;
unsigned char szProtocol[13] = "ncacn_ip_tcp"; //TCPを利用するコネクションサービス unsigned char szEndpoint[6] = "10200"; //ポート番号 unsigned char *pszStringBinding = NULL; char *IPaddress="172.18.5.145"; static TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1] = _T(""); DWORD dwNameLength = sizeof(szComputerName); ::GetComputerName(szComputerName, &dwNameLength);
//#RPC接続に必要なバインドハンドル文字列を編集する lngStatus = RpcStringBindingCompose ( NULL, szProtocol, (unsigned char *)IPaddress, /*(unsigned char *)szComputerName,*/ szEndpoint, NULL, &pszStringBinding ); //#正常処理の場合
if ( lngStatus == RPC_S_OK ) { //#RPCサーバと接続する lngStatus = RpcBindingFromStringBinding ( pszStringBinding,
&hRpcService ); ☛ ACFファイルで定義したバインドハンドル
//#サーバのエンドポイントを認識できない場合 if ( lngStatus != RPC_S_OK ) { //#バインドハンドル文字列を解放する RpcStringFree ( &pszStringBinding ); return FALSE; } } else //#エラーが発生した場合 { //#エラーメッセージを出力する ...省略 return FALSE;
} //dwAuthLevel = RPC_C_AUTHN_LEVEL_NONE;
DWORD dwAuthLevel = RPC_C_AUTHN_LEVEL_CALL; lngStatus = ::RpcBindingSetAuthInfo ( hRpcService, ☛ ACFファイルで定義したバインドハンドル
NULL, dwAuthLevel, RPC_C_AUTHN_WINNT, NULL, 0 ); RpcTryExcept //#RPCサービスを実行する { RpcMgmtSetComTimeout ( hRpcService, RPC_C_BINDING_DEFAULT_TIMEOUT ); //#RPCサービス(intRpcFileUpload関数)を実行する
int intRes; WCHAR szFileName[4096]; intRes = intRpcFileUpload ( (unsigned char*)lstRpc->rstrDraftFileName ); ☟
RPC提供関数
if ( !intRes ) { //#エラーメッセージを出力する ....省略 return FALSE; } } RpcExcept(1) //#RPC例外処理 { //#エラーメッセージを出力する ....省略 return FALSE; } RpcEndExcept eturn TRUE;
} /**************************************************************************** FUNCTION: midl_user_allocate(size_t)
PURPOSE: Allocate memory as needed by the RPC runtime library
COMMENTS: The stubs or runtime libraries may need to allocate memory.
By convention, they call a user-specified function named midl_user_allocate. In this application, no memory management is needed, so a dummy function is provided. ****************************************************************************/
void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
{ UNREFERENCED_PARAMETER(len); return(NULL); // no memory management required } /****************************************************************************
FUNCTION: midl_user_free(void *)
PURPOSE: Free memory as needed by the RPC runtime library
COMMENTS: The stubs or runtime libraries may need to free memory.
By convention, they call a user-specified function named midl_user_free. In this application, no memory allocation is needed so a dummy function is provided. ****************************************************************************/
void __RPC_API midl_user_free(void __RPC_FAR * ptr)
{ UNREFERENCED_PARAMETER(ptr); return; // no memory management required } |

- >
- コンピュータとインターネット
- >
- コンピュータ
- >
- ソフトウェア


