Ejemplo n.º 1
0
 public int Init(string strName)
 {
     if (strName.Length <= 0)
     {
         return(1);
     }
     this.m_hSharedMemoryFile = ZyShareMem.OpenFileMapping(6, false, strName);
     if (this.m_hSharedMemoryFile == IntPtr.Zero)
     {
         this.m_bAlreadyExist = false;
         this.m_bInit         = false;
         return(2);
     }
     this.m_bAlreadyExist = true;
     this.m_pwData        = ZyShareMem.MapViewOfFile(this.m_hSharedMemoryFile, 6u, 0u, 0u, 0u);
     this.m_pwDataWrite   = this.m_pwData;
     this.m_pwDataRead    = (IntPtr)(this.m_pwData.GetHashCode() + 50);
     if (this.m_pwData == IntPtr.Zero)
     {
         this.m_bInit = false;
         ZyShareMem.CloseHandle(this.m_hSharedMemoryFile);
         return(3);
     }
     this.m_bInit = true;
     this.SetSemaphore();
     return(0);
 }
Ejemplo n.º 2
0
 private void Update()
 {
     if (!this.inited)
     {
         this.hMappingHandle = ZyShareMem.OpenFileMapping(4, false, this.memName);
         if (this.hMappingHandle == IntPtr.Zero)
         {
             Debug.Log("打开共享内存失败:");
             return;
         }
         this.hVoid = ZyShareMem.MapViewOfFile(this.hMappingHandle, 4u, 0u, 0u, (uint)Marshal.SizeOf(this.m_gameSharedDef));
         if (this.hVoid == IntPtr.Zero)
         {
             Debug.Log("文件映射失败——读共享内存");
             return;
         }
         //Debug.Log("共享内存Run");
         this.inited = true;
     }
     if (this.inited)
     {
         this.m_gameSharedDef = (GameSharedDef)this.ReadFromMemory(this.m_gameSharedDef.GetType());
         this.m_vectorAngExp  = this.m_gameSharedDef.Angle;
         //Debug.Log("游戏状态:" + m_gameSharedDef.GameStatus);
         //Debug.Log("读取角度 X:" + m_vectorAngExp.X + " Y:" + m_vectorAngExp.Y + " Z:" + m_vectorAngExp.Z);
     }
 }
Ejemplo n.º 3
0
 private void Close()
 {
     if (this.m_bInit)
     {
         ZyShareMem.UnmapViewOfFile(this.m_pwData);
         ZyShareMem.CloseHandle(this.m_hSharedMemoryFile);
     }
 }
Ejemplo n.º 4
0
 private void Close()
 {
     if (this.hVoid != IntPtr.Zero)
     {
         ZyShareMem.UnmapViewOfFile(this.hVoid);
         this.hVoid = IntPtr.Zero;
     }
     if (this.hMappingHandle != IntPtr.Zero)
     {
         ZyShareMem.CloseHandle(this.hMappingHandle);
         this.hMappingHandle = IntPtr.Zero;
     }
 }