V
Vincent RICHOMME
Hi,
I am trying to convert a C project into C++. This project is used to
hook some system calls on a Windows CE platform.
Here is the class definition:
class CHookBase
{
public:
CHookBase(DWORD dwSysCallAddr);
~CHookBase(void);
virtual void SetHook() = 0;
virtual void InitHook();
private:
const DWORD FIRST_METHOD;
const DWORD CURRENT_METHOD;
const int APICALL_SCALE;
const int HANDLE_SHIFT;
const DWORD METHOD_MASK;
const DWORD HANDLE_MASK;
BOOL m_bMode;
DWORD m_dwPerm;
CINFO** m_SystemAPISets;
DWORD m_Tmp;
DWORD m_ApiSet;
DWORD m_Method;
PFNVOID m_pfnOrgFunc;
};
#include "hookbase.h"
class CCreateFileHook : public CHookBase
{
public:
//----------------------- SIGNATURE OF FUNCTIONS TO
HOOK--------------------//
typedef HANDLE t_CreateFile
(
LPCTSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile
);
CCreateFileHook(DWORD dwSysCallAddr);
~CCreateFileHook(void);
static HANDLE _CreateFileHook( LPCTSTR lpFileName, DWORD
dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
virtual void SetHook();
};
and here is the implementation:
/*static*/
HANDLE CCreateFileHook::_CreateFileHook( LPCTSTR lpFileName, DWORD
dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES
lpSecurityAttributes, DWORD dwCreationDisposition, DWORD
dwFlagsAndAttributes, HANDLE hTemplateFile)
{
HANDLE H = ((t_CreateFile*) m_pfnOrgFunc
)(lpFileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);
DWORD Err = GetLastError();
SetLastError(Err);
return H;
}
However when I compile I got the following message :
CCreateFileHook.cpp(21) : error C2440: 'type cast' : cannot convert from
'' to 't_CreateFile (__cdecl *)'
The expression being converted is not valid
In C this cast is allowed .........
For info :
HANDLE is a void*
PFNVOID is defined as a pointer to function returning void and taking 0
parameter (=typedef void(PFNVOID*)(void)
How can I fix that ?
I am trying to convert a C project into C++. This project is used to
hook some system calls on a Windows CE platform.
Here is the class definition:
class CHookBase
{
public:
CHookBase(DWORD dwSysCallAddr);
~CHookBase(void);
virtual void SetHook() = 0;
virtual void InitHook();
private:
const DWORD FIRST_METHOD;
const DWORD CURRENT_METHOD;
const int APICALL_SCALE;
const int HANDLE_SHIFT;
const DWORD METHOD_MASK;
const DWORD HANDLE_MASK;
BOOL m_bMode;
DWORD m_dwPerm;
CINFO** m_SystemAPISets;
DWORD m_Tmp;
DWORD m_ApiSet;
DWORD m_Method;
PFNVOID m_pfnOrgFunc;
};
#include "hookbase.h"
class CCreateFileHook : public CHookBase
{
public:
//----------------------- SIGNATURE OF FUNCTIONS TO
HOOK--------------------//
typedef HANDLE t_CreateFile
(
LPCTSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile
);
CCreateFileHook(DWORD dwSysCallAddr);
~CCreateFileHook(void);
static HANDLE _CreateFileHook( LPCTSTR lpFileName, DWORD
dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
virtual void SetHook();
};
and here is the implementation:
/*static*/
HANDLE CCreateFileHook::_CreateFileHook( LPCTSTR lpFileName, DWORD
dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES
lpSecurityAttributes, DWORD dwCreationDisposition, DWORD
dwFlagsAndAttributes, HANDLE hTemplateFile)
{
HANDLE H = ((t_CreateFile*) m_pfnOrgFunc
)(lpFileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);
DWORD Err = GetLastError();
SetLastError(Err);
return H;
}
However when I compile I got the following message :
CCreateFileHook.cpp(21) : error C2440: 'type cast' : cannot convert from
'' to 't_CreateFile (__cdecl *)'
The expression being converted is not valid
In C this cast is allowed .........
For info :
HANDLE is a void*
PFNVOID is defined as a pointer to function returning void and taking 0
parameter (=typedef void(PFNVOID*)(void)
How can I fix that ?