//---------------------------------------------------------------------------

#pragma hdrstop

#include "uData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)

static const char *MMFileName = "DG_SMAP";
//---------------------------------------------------------------------------
// 훅 용 DLL에서 메모리 맵에 데이터를 적을 때 사용.
int  GetData(int tdID)
{
   HANDLE hFileMapObj;
   TTransData *DataPointer;
   int Result = 0;

   hFileMapObj =
      CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0,
      sizeof(TTransData), MMFileName);
   try
   {
      DataPointer = (TTransData *)MapViewOfFile(hFileMapObj, FILE_MAP_WRITE, 0, 0, 0);
      if(DataPointer){
         switch (tdID)
         {
           case tdRHandle:
            Result = (int)DataPointer->RHandle;
            break;
           case tdKeybdHookID:
            Result = (int)DataPointer->KeybdHookID;
            break;
           case tdWndHookID:
            Result = (int)DataPointer->WndHookID;
            break;
           default:
            UnmapViewOfFile(DataPointer);
            break;
         }
         UnmapViewOfFile(DataPointer);
      }
   }
   __finally
   {
      CloseHandle(hFileMapObj);
   }
   return Result;
}
//---------------------------------------------------------------------------
// 훅 용 DLL에서 메모리 맵에 데이터를 읽을 때 사용.
void SetData(int tdID, int Value)
{
   HANDLE hFileMapObj;
   TTransData *DataPointer;

   hFileMapObj =
      CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0,
      sizeof(TTransData), MMFileName);
   try
   {
      DataPointer = (TTransData *)MapViewOfFile(hFileMapObj, FILE_MAP_WRITE, 0, 0, 0);
      if(DataPointer){
         switch (tdID)
         {
           case tdRHandle:
            DataPointer->RHandle = (HANDLE)Value;
            break;
           case tdKeybdHookID:
            DataPointer->KeybdHookID = (HANDLE)Value;
            break;
           case tdWndHookID:
            DataPointer->WndHookID = (HANDLE)Value;
            break;
           default:
            UnmapViewOfFile(DataPointer);
            break;
         }
         UnmapViewOfFile(DataPointer);
      }
   }
   __finally
   {
      CloseHandle(hFileMapObj);
   }
}
//---------------------------------------------------------------------------
HANDLE FileMapObj;

void CreateFileMap()
{
   FileMapObj = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0,
      sizeof(TTransData), MMFileName);
}
//---------------------------------------------------------------------------
void EraseFileMap()
{
   CloseHandle(FileMapObj);
}
//---------------------------------------------------------------------------
