mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-11 12:11:04 +00:00
Update native component
This commit is contained in:
parent
9bc4621962
commit
ba47a7f62d
|
@ -19,6 +19,8 @@
|
|||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
@ -28,6 +30,9 @@ namespace WelsonJS
|
|||
{
|
||||
private IntPtr hFile;
|
||||
private IntPtr hFileMappingObject;
|
||||
private string _lpName;
|
||||
|
||||
public static Dictionary<string, NamedSharedMemory> Cached;
|
||||
|
||||
[Flags]
|
||||
public enum FileProtection : uint
|
||||
|
@ -91,8 +96,19 @@ namespace WelsonJS
|
|||
|
||||
public void Open(string lpName)
|
||||
{
|
||||
hFile = FileMappingNative.CreateFileMapping((IntPtr)(-1), IntPtr.Zero, FileProtection.PAGE_READWRITE, 0u, 1024u, lpName);
|
||||
hFileMappingObject = FileMappingNative.MapViewOfFile(hFile, FileMapAccess.FILE_MAP_ALL_ACCESS, 0u, 0u, 1024u);
|
||||
_lpName = lpName;
|
||||
|
||||
if (!Cached.ContainsKey(_lpName))
|
||||
{
|
||||
hFile = FileMappingNative.CreateFileMapping((IntPtr)(-1), IntPtr.Zero, FileProtection.PAGE_READWRITE, 0u, 1024u, _lpName);
|
||||
hFileMappingObject = FileMappingNative.MapViewOfFile(hFile, FileMapAccess.FILE_MAP_ALL_ACCESS, 0u, 0u, 1024u);
|
||||
Cached.Add(_lpName, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
hFile = IntPtr.Zero;
|
||||
hFileMappingObject = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInitialized()
|
||||
|
@ -131,6 +147,11 @@ namespace WelsonJS
|
|||
FileMappingNative.CloseHandle(hFile);
|
||||
hFile = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (Cached.ContainsKey(_lpName))
|
||||
{
|
||||
Cached.Remove(_lpName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,15 +38,8 @@ namespace WelsonJS
|
|||
[ComVisible(true)]
|
||||
public class Toolkit
|
||||
{
|
||||
private Dictionary<string, NamedSharedMemory> sharedMemoryDict;
|
||||
|
||||
public static readonly string ApplicationName = "WelsonJS";
|
||||
|
||||
public Toolkit()
|
||||
{
|
||||
sharedMemoryDict = new Dictionary<string, NamedSharedMemory>();
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool SendClick(string title, int x, int y)
|
||||
{
|
||||
|
@ -66,6 +59,7 @@ namespace WelsonJS
|
|||
return SendKey(hWnd, key);
|
||||
}
|
||||
|
||||
// [ComVisible(false)]
|
||||
public bool SendKey(IntPtr hWnd, char key)
|
||||
{
|
||||
return Window.PostMessage(hWnd, (int)Window.Message.WM_CHAR, key, IntPtr.Zero);
|
||||
|
@ -151,20 +145,12 @@ namespace WelsonJS
|
|||
|
||||
// [Toolkit] Access to a shared memory #96
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool OpenNamedSharedMemory(string lpName)
|
||||
{
|
||||
NamedSharedMemory sharedMemory = new NamedSharedMemory(lpName);
|
||||
sharedMemoryDict.Add(lpName, sharedMemory);
|
||||
return sharedMemory.IsInitialized();
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
// [ComVisible(false)]
|
||||
public NamedSharedMemory GetSharedMemory(string lpName)
|
||||
{
|
||||
if (sharedMemoryDict.ContainsKey(lpName))
|
||||
if (NamedSharedMemory.Cached.ContainsKey(lpName))
|
||||
{
|
||||
NamedSharedMemory sharedMemory = sharedMemoryDict[lpName];
|
||||
NamedSharedMemory sharedMemory = NamedSharedMemory.Cached[lpName];
|
||||
if (sharedMemory.IsInitialized())
|
||||
{
|
||||
return sharedMemory;
|
||||
|
@ -174,6 +160,14 @@ namespace WelsonJS
|
|||
return null;
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
public bool OpenNamedSharedMemory(string lpName)
|
||||
{
|
||||
NamedSharedMemory sharedMemory = new NamedSharedMemory(lpName);
|
||||
return sharedMemory.IsInitialized();
|
||||
}
|
||||
|
||||
|
||||
[ComVisible(true)]
|
||||
public void CloseNamedSharedMemory(string lpName)
|
||||
{
|
||||
|
@ -181,7 +175,6 @@ namespace WelsonJS
|
|||
if (sharedMemory != null)
|
||||
{
|
||||
sharedMemory.Close();
|
||||
sharedMemoryDict.Remove(lpName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user