SEな日々

「自分の時間を大切に」 を目標に活動します。ヽ(^o^)丿

SEな日々

すべて表示

Win32 RPCクライアントプログラム

お疲れさまです。
 
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
}

その他の最新記事

すべて表示

英語にはまっています。

2012/1/26(木) 午後 1:53

お疲れさまです。 今更なんですが、英語にはまっています。 今年中に英検2級合格を目標にしています。 昨年11月に、英検3級を受験、合格しました。 今年1月に、英検準2級を受験、 ...すべて表示すべて表示

武士道エイティーン

2011/4/4(月) 午前 10:15

お疲れさまです。 ジウ、ストロベリーナイトが代表作の誉田哲也さんの作品です。 青春ストーリとなっていて、シックスティーン、セブンティーンの続編です。 シックスティーン、セ ...すべて表示すべて表示

告白

2010/6/13(日) 午後 6:13

原作を読んでからの鑑賞です。 先ほど、1人(寂しい...)で、観てきました。 もう一度、原作を読みたくなりました。 リアルに怖いです..かも? ...すべて表示すべて表示


.
SE
SE
男性 / O型
人気度
Yahoo!ブログヘルプ - ブログ人気度について

ブログバナー

1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

標準グループ

Yahoo!からのお知らせ

よしもとブログランキング

もっと見る

プライバシー -  利用規約 -  メディアステートメント -  ガイドライン -  順守事項 -  ご意見・ご要望 -  ヘルプ・お問い合わせ

Copyright (C) 2019 Yahoo Japan Corporation. All Rights Reserved.

みんなの更新記事