Jump to content


Photo

Zabezpieczenie przed podwójnym uruchomieniem - krótki opis


  • Please log in to reply
No replies to this topic

#1 OFFLINE   mc_kibel

mc_kibel

    Proud Member of Sony.yt Community

  • User
  • 26 posts
    • Time Online: 1h 1m

Posted 29 October 2011 - 01:29

Witam!

Pokażę Wam, jak dodać zabezpieczenie przed kilkukrotnym uruchomieniem jednego elfa.
Dodamy więc tą opcję do HelloWorld (oczyszczony przeze mnie ze zbędnego stuffu)

Otwieramy więc main.c:
#include "..\includeLib_Clara.h"
#include "..\includeDir.h"

BOOK * HWBook;

int TerminateElf(void * ,BOOK* book)
{
  FreeBook(book);
  return(1);
}

typedef struct
{
  BOOK * book;
}MSG;

int ShowAuthorInfo(void *mess ,BOOK* book)
{
  MSG * msg = (MSG*)mess;
  MessageBox(0x6fFFFFFF,STR("Hello Wordl!nnExample elf.."),0, 1 ,5000,msg->book);
  return(1);
}

const PAGE_MSG HW_PageEvents[]@ "DYN_PAGE" ={
  ELF_TERMINATE_EVENT , TerminateElf,
  ELF_SHOW_INFO_EVENT  , ShowAuthorInfo,
  0,0
};

PAGE_DESC base_page ={"HW_BasePage",0,HW_PageEvents};


void elf_exit(void)

{
  kill_data(&ELF_BEGIN, (void(*)(void*))mfree_adr());
}

void onCloseHWBook(BOOK * book)
{
  if (book)
  {
    StatusIndication_ShowNotes(0x6FFFFFFF);
    SUBPROC(elf_exit);
  }
}

BOOK * CreateHWBook()
{
  HWBook= new BOOK;
  CreateBook(HWBook,onCloseHWBook,&base_page,"Example",-1,0);
  return(HWBook);
}

int main (void)
{
  CreateHWBook();
  StatusIndication_ShowNotes(STR("Hello World!"));
  return(0);
}


Przede wszystkim interesuje nas tutaj to:
#include "..\includeLib_Clara.h"
#include "..\includeDir.h"

BOOK * HWBook;

int TerminateElf(void * ,BOOK* book)
{
  FreeBook(book);
  return(1);
}

typedef struct
{
  BOOK * book;
}MSG;

int ShowAuthorInfo(void *mess ,BOOK* book)
{
  MSG * msg = (MSG*)mess;
  MessageBox(0x6fFFFFFF,STR("Hello Wordl!nnExample elf.."),0, 1 ,5000,msg->book);
  return(1);
}

const PAGE_MSG HW_PageEvents[]@ "DYN_PAGE" ={
  ELF_TERMINATE_EVENT , TerminateElf,
  ELF_SHOW_INFO_EVENT  , ShowAuthorInfo,
  0,0
};

PAGE_DESC base_page ={"HW_BasePage",0,HW_PageEvents};


void elf_exit(void)

{
  kill_data(&ELF_BEGIN, (void(*)(void*))mfree_adr());
}

void onCloseHWBook(BOOK * book)
{
  if (book)
  {
    StatusIndication_ShowNotes(0x6FFFFFFF);
    SUBPROC(elf_exit);
  }
}

BOOK * CreateHWBook()
{
  HWBook= new BOOK;
  CreateBook(HWBook,onCloseHWBook,&base_page,"Example",-1,0);
  return(HWBook);
}

int isRunned(BOOK * book)
{
  if(!strcmp(book->xbook->name,"Example")) return 1; // nazwa z Bookmanagera
  return 0;
}

int main (void)
{
  if (FindBook(isRunned)) //Gdy zakładka "Example" zostanie wykryta...
  {
    MessageBox(0x6fFFFFFF,STR("Elf HelloWorld jest juz uruchomiony!"),0, 1 ,5000,0); // ...wyświetl okienko z info.
  } else { // Jeśli jednak jest inaczej...
  CreateHWBook(); //...utwórz zakładkę "Example"
  StatusIndication_ShowNotes(STR("Hello World!")); //... i pokaż notatkę na ekranie.
  }
  return(0);
}

  • 0
Sony Ericsson X8 || GingerDX v017 Android 2.3.7 || Sense Theme


1 user(s) are reading this topic