UMP
15th February 2004, 23:49
Hello DspGuru,
would there be a chance to get a shared memory stucture in the next BeSweet.exe build to be able to have feedback about the transcoding progress ? This would be great since besweet.dll - through it does the job - isn't yet as reliable as BeSweet.exe.
Best regards,
ump
Sample about how it would be used :
#include "CSharedStruct.h"
typedef struct _SharedProgressData
{
DWORD Progress;
bool Cancel;
} SharedProgressData;
// declare the shared memory variable
CSharedStruct<SharedProgressData> m_SharedProgressData("BeSweet Shared Progress Data");
main()
{
// set the shared memory value. This can be read from any process.
m_SharedProgressData->Progress = dwProgress;
}
Here is CSharedStruct.h :
----- CUT HERE -----
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CSharedStruct_H__86467BA6_5AFA_11D3_863D_00A0244A9CA7__INCLUDED_)
#define AFX_CSharedStruct_H__86467BA6_5AFA_11D3_863D_00A0244A9CA7__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <Aclapi.h>
template <class StructType>
class CSharedStruct
{
private:
HANDLE m_hFileMapping;
char m_hSharedName[MAX_PATH];
DWORD m_dwMaxDataSize;
StructType *m_pvData;
BOOL m_bCreated;
public:
CSharedStruct();
CSharedStruct(char *Name);
~CSharedStruct();
VOID Release();
BOOL Acquire(char *Name);
StructType *operator->();
};
template <class StructType>
StructType *CSharedStruct<StructType>::operator->()
{
return m_pvData;
}
template <class StructType>
CSharedStruct<StructType>::CSharedStruct()
{
m_hFileMapping = NULL;
m_pvData = NULL;
}
template <class StructType>
CSharedStruct<StructType>::~CSharedStruct()
{
Release();
}
template <class StructType>
CSharedStruct<StructType>::CSharedStruct(char *Name)
{
CSharedStruct();
Acquire(Name);
}
template <class StructType>
VOID CSharedStruct<StructType>::Release()
{
if (m_pvData)
{
UnmapViewOfFile(m_pvData);
m_pvData = NULL;
}
if (m_hFileMapping)
{
CloseHandle(m_hFileMapping);
}
}
template <class StructType>
BOOL CSharedStruct<StructType>::Acquire(char *Name)
{
m_dwMaxDataSize = 0;
m_hFileMapping = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(StructType), Name);
if (m_hFileMapping == NULL)
{
int err = GetLastError();
return FALSE;
}
// OK, if we're the first person to create this
// file mapping object
// we want to clear the ACL, so
// anyone else can access this object
//
// If we don't do this, and a service creates the file mapping
// User processes won't be able to access it.
// So, we set the DACL to NULL, which effectively
// grants Everyone All Access
// More complicated ACLs are left as an exercise for the reader
// (because I sure as hell can't figure them out!)
SetNamedSecurityInfo(Name, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, 0, 0, (PACL) NULL, NULL);
m_dwMaxDataSize = sizeof(StructType);
strncpy(m_hSharedName, Name, MAX_PATH - 1);
m_pvData = (StructType *) MapViewOfFile( m_hFileMapping, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
if (m_pvData == NULL)
{
CloseHandle(m_hFileMapping);
return FALSE;
}
return TRUE;
}
#endif
----- CUT HERE -----
would there be a chance to get a shared memory stucture in the next BeSweet.exe build to be able to have feedback about the transcoding progress ? This would be great since besweet.dll - through it does the job - isn't yet as reliable as BeSweet.exe.
Best regards,
ump
Sample about how it would be used :
#include "CSharedStruct.h"
typedef struct _SharedProgressData
{
DWORD Progress;
bool Cancel;
} SharedProgressData;
// declare the shared memory variable
CSharedStruct<SharedProgressData> m_SharedProgressData("BeSweet Shared Progress Data");
main()
{
// set the shared memory value. This can be read from any process.
m_SharedProgressData->Progress = dwProgress;
}
Here is CSharedStruct.h :
----- CUT HERE -----
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CSharedStruct_H__86467BA6_5AFA_11D3_863D_00A0244A9CA7__INCLUDED_)
#define AFX_CSharedStruct_H__86467BA6_5AFA_11D3_863D_00A0244A9CA7__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <Aclapi.h>
template <class StructType>
class CSharedStruct
{
private:
HANDLE m_hFileMapping;
char m_hSharedName[MAX_PATH];
DWORD m_dwMaxDataSize;
StructType *m_pvData;
BOOL m_bCreated;
public:
CSharedStruct();
CSharedStruct(char *Name);
~CSharedStruct();
VOID Release();
BOOL Acquire(char *Name);
StructType *operator->();
};
template <class StructType>
StructType *CSharedStruct<StructType>::operator->()
{
return m_pvData;
}
template <class StructType>
CSharedStruct<StructType>::CSharedStruct()
{
m_hFileMapping = NULL;
m_pvData = NULL;
}
template <class StructType>
CSharedStruct<StructType>::~CSharedStruct()
{
Release();
}
template <class StructType>
CSharedStruct<StructType>::CSharedStruct(char *Name)
{
CSharedStruct();
Acquire(Name);
}
template <class StructType>
VOID CSharedStruct<StructType>::Release()
{
if (m_pvData)
{
UnmapViewOfFile(m_pvData);
m_pvData = NULL;
}
if (m_hFileMapping)
{
CloseHandle(m_hFileMapping);
}
}
template <class StructType>
BOOL CSharedStruct<StructType>::Acquire(char *Name)
{
m_dwMaxDataSize = 0;
m_hFileMapping = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(StructType), Name);
if (m_hFileMapping == NULL)
{
int err = GetLastError();
return FALSE;
}
// OK, if we're the first person to create this
// file mapping object
// we want to clear the ACL, so
// anyone else can access this object
//
// If we don't do this, and a service creates the file mapping
// User processes won't be able to access it.
// So, we set the DACL to NULL, which effectively
// grants Everyone All Access
// More complicated ACLs are left as an exercise for the reader
// (because I sure as hell can't figure them out!)
SetNamedSecurityInfo(Name, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, 0, 0, (PACL) NULL, NULL);
m_dwMaxDataSize = sizeof(StructType);
strncpy(m_hSharedName, Name, MAX_PATH - 1);
m_pvData = (StructType *) MapViewOfFile( m_hFileMapping, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
if (m_pvData == NULL)
{
CloseHandle(m_hFileMapping);
return FALSE;
}
return TRUE;
}
#endif
----- CUT HERE -----