LoginSignup
0
1

More than 5 years have passed since last update.

C++ Builder XE4, 10.2 Tokyo > Indy > 自分のIPアドレスを取得する実装

Last updated at Posted at 2016-12-14
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/28)

自分のIPアドレスを取得する方法を調べた。

Delphi実装は見つかった。
http://embarcadero.newsgroups.archived.at/public.delphi.vcl.components.using/200905/0905052027.html

C++ Builder実装にしてみた。

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <IdComponent.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TIdStack::IncUsage();

    String res = GStack->LocalAddress;
    OutputDebugString(res.c_str());

    TIdStack::DecUsage();
}
//---------------------------------------------------------------------------
デバッグ出力(Button1押下後)
デバッグ出力: 192.168.79.31 プロセス Project1.exe (1128)

TIdStackのIncUsage()を実行しているのは、上記のリンクで以下の記載があるため。

Call the TIdStack.IncUsage() class
method to ensure GStack is intialized before accessing it, ie:

このあたりの処理はまだまだ自分の知らないことばかり。



(追記 2016/12/15)
「静的メンバ関数」ではTIdStack::IncUsage()などを処理できない (ビルド時にエラーとなる)。
そのためインスタンスありでのメンバ関数として実装することになる。
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1