動作環境
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()
などを処理できない (ビルド時にエラーとなる)。そのためインスタンスありでのメンバ関数として実装することになる。