ホーム » Mac » Objective-C から C++ の呼び出し

2012年8月
 1234
567891011
12131415161718
19202122232425
262728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,419 アクセス



Objective-C から C++ の呼び出し

先日作成した MemStat.hxx を「iOS」−「Single View Application」から利用してみた.
ViewController.m の拡張子を mm に変更.
ボタンと UITextView を貼付けて,変数を定義,ボタンの Action を追加.
以下はそれに対して,C++ の呼出しを加えたコード.


//  ViewController.mm
 
#import “ViewController.h”
#include “MemStat.hxx”   // これでいいの?
 
@interface ViewController ()
 
@end
 
@implementation ViewController
@synthesize TextView;
 
– (void)viewDidLoad
{
  [super viewDidLoad];
  {
    MemoryStatus    ms ;
    NSString*    str = [[NSString alloc]initWithFormat:@”%8.2f MB  /  %8.2f MB \n”,
            ms.GetPhysFree()/1024/1024.,ms.GetPhysTotal()/1024/1024. ] ;
    TextView.text = str ;
    }

  }
– (void)viewDidUnload
{
  [self setTextView:nil];
  [super viewDidUnload];
  }
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  }
– (IBAction)Refresh:(id)sender {
  {
    MemoryStatus    ms ;
    NSString*    str = [[NSString alloc]initWithFormat:@”%8.2f MB  /  %8.2f MB \n”,
            ms.GetPhysFree()/1024/1024.,ms.GetPhysTotal()/1024/1024. ] ;
    TextView.text = [TextView.text    stringByAppendingString:str ] ;
    }

  }
@end
 

メモリ状態の画面のコピー

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。