0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++ Builder 10.2 Tokyo > psapi.hを使う > #pragma comment(lib, "psapi.lib")は追加不要 (XE4から10.2Tokyoへの移行)

Posted at
動作環境
RAD Studio 10.2 Tokyo Update 2

関連

XE4ではpaspi.hで定義されたGetProcessMemoryInfo()などを使うときにエラーが出ていた(上記リンク参照)。
そのエラー対策として#pragma comment(lib, "psapi.lib")を追加するようにしていた。

10.2 Tokyoでは#pragma comment(lib, "psapi.lib")を追加しなくても実行時エラーは出ないようだ。

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <psapi.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    int LSize;
    PPROCESS_MEMORY_COUNTERS LProcessMem;
    int LMemUsed;

    LSize = sizeof(PPROCESS_MEMORY_COUNTERS);

    bool res = GetProcessMemoryInfo(GetCurrentProcess(), LProcessMem, LSize);
    if (res) {
        LMemUsed = LProcessMem->WorkingSetSize;
    }

    LMemUsed = LMemUsed / 1024; // to KB
    LMemUsed = LMemUsed / 1024; // to MB

    String msg = IntToStr(LMemUsed) + L" used";
	OutputDebugString(msg.c_str());
}
//---------------------------------------------------------------------------
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?