1
0
Fork 0

correct verion of plugin

This commit is contained in:
= 2014-04-24 17:48:34 +02:00
parent ce54ce59f8
commit ab4e60d861
2 changed files with 71 additions and 37 deletions

View File

@ -34,13 +34,13 @@ extra_parameters* g_extra = NULL;
/// handle for the memory segment
///////////////////////////////////////////////////////////
HANDLE hMapFile = NULL;
// HANDLE hMapFile = NULL;
///////////////////////////////////////////////////////////
/// content of the memory segment
///////////////////////////////////////////////////////////
LPCTSTR pBuf = NULL;
// LPCTSTR pBuf = NULL;
///////////////////////////////////////////////////////////
/// content of the memory segment
@ -88,7 +88,8 @@ void PushReturnValue(int value);
PUBLIC_FUNCTION(CreateSharedMemory)
{
HANDLE hMapFile = NULL;
LPCTSTR pBuf = NULL;
TCHAR * szName = SHARED_MEM_SEGMENT;
SECURITY_ATTRIBUTES attr;
attr.bInheritHandle = 1;
@ -139,16 +140,45 @@ PUBLIC_FUNCTION_END
PUBLIC_FUNCTION(WriteIntoSharedMem)
{
if(!pBuf) {
PushReturnValue(-1);
return;
}
HANDLE hMapFile = NULL;
LPCTSTR pBuf = NULL;
TCHAR * szMsg = (TCHAR*)LocalAlloc(LPTR, g_string_size * sizeof(TCHAR));
if (!szMsg) {
PushReturnValue(-2); // memory could not be allocated
return;
}
hMapFile = OpenFileMapping(
FILE_MAP_WRITE, // read/write access
FALSE, // do not inherit the name
SHARED_MEM_SEGMENT); // name of mapping object
if (hMapFile == NULL)
{
PushReturnValue(GetLastError());
// _tprintf(TEXT("Could not open file mapping object (%d).\n"),
// GetLastError());
return;
}
pBuf = (LPTSTR)MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL)
{
// _tprintf(TEXT("Could not map view of file (%d).\n"),
// GetLastError());
PushReturnValue(GetLastError());
CloseHandle(hMapFile);
return;
}
// read name for mem segment from stack
popstring(szMsg);
CopyMemory((PVOID)pBuf, szMsg, (_tcslen(szMsg) * sizeof(TCHAR)));
@ -164,14 +194,13 @@ PUBLIC_FUNCTION_END
PUBLIC_FUNCTION(ReadIntoSharedMem)
{
HANDLE hMapFile;
LPCTSTR pBuf;
TCHAR * szName = SHARED_MEM_SEGMENT;
HANDLE hMapFile = NULL;
LPCTSTR pBuf = NULL;
hMapFile = OpenFileMapping(
FILE_MAP_WRITE, // read/write access
FALSE, // do not inherit the name
szName); // name of mapping object
SHARED_MEM_SEGMENT); // name of mapping object
if (hMapFile == NULL)
{
@ -210,17 +239,22 @@ PUBLIC_FUNCTION(ReadIntoSharedMem)
}
PUBLIC_FUNCTION_END
PUBLIC_FUNCTION(RemoveSharedMem)
PUBLIC_FUNCTION(ExistsSharedMem)
{
if(pBuf) {
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
pBuf = NULL;
hMapFile = NULL;
PushReturnValue(0);
HANDLE hMapFile = NULL;
hMapFile = OpenFileMapping(
FILE_MAP_WRITE, // read/write access
FALSE, // do not inherit the name
SHARED_MEM_SEGMENT); // name of mapping object
if (hMapFile == NULL)
{
PushReturnValue(GetLastError());
// _tprintf(TEXT("Could not open file mapping object (%d).\n"),
// GetLastError());
return;
}
PushReturnValue(GetLastError());
}
PUBLIC_FUNCTION_END