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,19 +34,19 @@ extra_parameters* g_extra = NULL;
/// handle for the memory segment /// handle for the memory segment
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
HANDLE hMapFile = NULL; // HANDLE hMapFile = NULL;
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
/// content of the memory segment /// content of the memory segment
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
LPCTSTR pBuf = NULL; // LPCTSTR pBuf = NULL;
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
/// content of the memory segment /// content of the memory segment
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
TCHAR * SHARED_MEM_SEGMENT = "__TRIANGES_INSTALLER_STATE__"; TCHAR * SHARED_MEM_SEGMENT = "__TRIANGES_INSTALLER_STATE__";
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
/// PLUG-IN Handling /// PLUG-IN Handling
@ -55,7 +55,7 @@ TCHAR * SHARED_MEM_SEGMENT = "__TRIANGES_INSTALLER_STATE__";
#define PUBLIC_FUNCTION(Name) \ #define PUBLIC_FUNCTION(Name) \
EXTERN_C void __declspec(dllexport) __cdecl Name(HWND hWndParent, int string_size, TCHAR* variables, stack_t** stacktop, extra_parameters* extra) \ EXTERN_C void __declspec(dllexport) __cdecl Name(HWND hWndParent, int string_size, TCHAR* variables, stack_t** stacktop, extra_parameters* extra) \
{ \ { \
EXDLL_INIT(); \ EXDLL_INIT(); \
g_string_size = string_size; \ g_string_size = string_size; \
@ -86,9 +86,10 @@ void PushReturnValue(int value);
/// ///
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
PUBLIC_FUNCTION(CreateSharedMemory) PUBLIC_FUNCTION(CreateSharedMemory)
{ {
HANDLE hMapFile = NULL;
LPCTSTR pBuf = NULL;
TCHAR * szName = SHARED_MEM_SEGMENT; TCHAR * szName = SHARED_MEM_SEGMENT;
SECURITY_ATTRIBUTES attr; SECURITY_ATTRIBUTES attr;
attr.bInheritHandle = 1; attr.bInheritHandle = 1;
@ -106,12 +107,12 @@ PUBLIC_FUNCTION(CreateSharedMemory)
if (hMapFile == NULL) if (hMapFile == NULL)
{ {
PushReturnValue(GetLastError()); // Could not create file mapping object PushReturnValue(GetLastError()); // Could not create file mapping object
return; return;
} }
// memory was created succefull // memory was created succefull
// generate the buffer for input/output operatíons // generate the buffer for input/output operatíons
pBuf = (LPTSTR)MapViewOfFile(hMapFile, // handle to map object pBuf = (LPTSTR)MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission FILE_MAP_ALL_ACCESS, // read/write permission
0, 0,
@ -126,7 +127,7 @@ PUBLIC_FUNCTION(CreateSharedMemory)
} }
PushReturnValue(0); PushReturnValue(0);
} }
PUBLIC_FUNCTION_END PUBLIC_FUNCTION_END
@ -137,22 +138,51 @@ PUBLIC_FUNCTION_END
/// ///
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
PUBLIC_FUNCTION(WriteIntoSharedMem) PUBLIC_FUNCTION(WriteIntoSharedMem)
{ {
if(!pBuf) { HANDLE hMapFile = NULL;
PushReturnValue(-1); LPCTSTR pBuf = NULL;
return;
}
TCHAR * szMsg = (TCHAR*) LocalAlloc(LPTR, g_string_size * sizeof(TCHAR)); TCHAR * szMsg = (TCHAR*)LocalAlloc(LPTR, g_string_size * sizeof(TCHAR));
if(!szMsg) { if (!szMsg) {
PushReturnValue(-2); // memory could not be allocated PushReturnValue(-2); // memory could not be allocated
return; return;
} }
// read name for mem segment from stack 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); popstring(szMsg);
CopyMemory((PVOID)pBuf, szMsg, (_tcslen(szMsg) * sizeof(TCHAR))); CopyMemory((PVOID)pBuf, szMsg, (_tcslen(szMsg) * sizeof(TCHAR)));
PushReturnValue(0); PushReturnValue(0);
} }
PUBLIC_FUNCTION_END PUBLIC_FUNCTION_END
@ -162,21 +192,20 @@ PUBLIC_FUNCTION_END
/// ///
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
PUBLIC_FUNCTION(ReadIntoSharedMem) PUBLIC_FUNCTION(ReadIntoSharedMem)
{ {
HANDLE hMapFile; HANDLE hMapFile = NULL;
LPCTSTR pBuf; LPCTSTR pBuf = NULL;
TCHAR * szName = SHARED_MEM_SEGMENT;
hMapFile = OpenFileMapping( hMapFile = OpenFileMapping(
FILE_MAP_WRITE, // read/write access FILE_MAP_WRITE, // read/write access
FALSE, // do not inherit the name FALSE, // do not inherit the name
szName); // name of mapping object SHARED_MEM_SEGMENT); // name of mapping object
if (hMapFile == NULL) if (hMapFile == NULL)
{ {
PushReturnValue(GetLastError()); PushReturnValue(GetLastError());
// _tprintf(TEXT("Could not open file mapping object (%d).\n"), // _tprintf(TEXT("Could not open file mapping object (%d).\n"),
// GetLastError()); // GetLastError());
return; return;
} }
@ -210,17 +239,22 @@ PUBLIC_FUNCTION(ReadIntoSharedMem)
} }
PUBLIC_FUNCTION_END PUBLIC_FUNCTION_END
PUBLIC_FUNCTION(RemoveSharedMem) PUBLIC_FUNCTION(ExistsSharedMem)
{ {
if(pBuf) { HANDLE hMapFile = NULL;
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile); hMapFile = OpenFileMapping(
pBuf = NULL; FILE_MAP_WRITE, // read/write access
hMapFile = NULL; FALSE, // do not inherit the name
PushReturnValue(0); SHARED_MEM_SEGMENT); // name of mapping object
if (hMapFile == NULL)
{
PushReturnValue(GetLastError());
// _tprintf(TEXT("Could not open file mapping object (%d).\n"),
// GetLastError());
return; return;
} }
PushReturnValue(GetLastError());
} }
PUBLIC_FUNCTION_END PUBLIC_FUNCTION_END