Click here to Skip to main content
15,890,579 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralFile's length over HTTP Pin
Hans Ruck18-May-04 3:37
Hans Ruck18-May-04 3:37 
GeneralRe: File's length over HTTP Pin
Michael Dunn18-May-04 4:55
sitebuilderMichael Dunn18-May-04 4:55 
GeneralRe: File's length over HTTP Pin
Hans Ruck18-May-04 5:00
Hans Ruck18-May-04 5:00 
QuestionHow to use mutex in a dll Pin
yingkou18-May-04 2:49
yingkou18-May-04 2:49 
AnswerRe: How to use mutex in a dll Pin
Diddy18-May-04 4:46
Diddy18-May-04 4:46 
GeneralRe: How to use mutex in a dll Pin
yingkou18-May-04 14:08
yingkou18-May-04 14:08 
GeneralRe: How to use mutex in a dll Pin
Diddy18-May-04 23:40
Diddy18-May-04 23:40 
GeneralRe: How to use mutex in a dll Pin
yingkou19-May-04 2:26
yingkou19-May-04 2:26 
#pragma data_seg(".TimeDATA")

static HWND hCallHook=NULL;
static HHOOK hHook=NULL;
static HINSTANCE hins=NULL;
static HANDLE m_hmutex=NULL;
static char LastEventTimebuf[19]="";
#pragma data_seg()
#pragma comment(linker,"/SECTION:.TimeDATA,RWS")

// CRegulardll1App construction
CRegulardll1App theApp;

CRegulardll1App::CRegulardll1App()
{
}
BOOL CRegulardll1App::InitInstance ()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hins=AfxGetInstanceHandle();
return TRUE;
}
BOOL CRegulardll1App::ExitInstance ()
{
CloseHandle(m_hmutex);
return TRUE;
}
LRESULT __declspec(dllexport)__stdcall CALLBACK GetMsgProc(int nCode,WPARAM wParam,LPARAM lParam)
{
PMSG pmsg;
pmsg = (PMSG)lParam;

if (nCode >= 0)
{
if((pmsg->message==WM_KEYDOWN || (pmsg->message==WM_MOUSEMOVE)||(pmsg->message==WM_NCLBUTTONDOWN)||(pmsg->message==WM_NCLBUTTONDBLCLK)
||(pmsg->message==WM_LBUTTONDOWN)||(pmsg->message==WM_RBUTTONDOWN)||(pmsg->message==WM_RBUTTONUP)||(pmsg->message==WM_LBUTTONDBLCLK)||(pmsg->message==WM_RBUTTONDBLCLK)))
{
COleDateTime oleLogDate = COleDateTime::GetCurrentTime();
CString strCurTime = oleLogDate.Format("%Y-%m-%d %H:%M:%S");
m_hmutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"timemutex");
WaitForSingleObject(m_hmutex,INFINITE);
strcpy(LastEventTimebuf,strCurTime);
ReleaseMutex(m_hmutex);
}
}
return CallNextHookEx(hHook, nCode,wParam, lParam);
}

BOOL __declspec(dllexport)__stdcall installhook(HWND hCallProc)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

m_hmutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"timemutex");
hCallHook=hCallProc;
hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)GetMsgProc,AfxGetInstanceHandle(),0);
return TRUE;
}
BOOL __declspec(dllexport)__stdcall UnHook()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BOOL unhooked = UnhookWindowsHookEx(hHook);

return TRUE;
}

BOOL __declspec(dllexport) __stdcall GetLastEventTime(char* pBuf,int size)
{
if(NULL == pBuf || size<19)
return FALSE;
else
{
WaitForSingleObject(m_hmutex,INFINITE);
CString str(LastEventTimebuf);
strcpy(pBuf,str);
ReleaseMutex(m_hmutex);
}

return TRUE;
}

Application:

HINSTANCE hinstDLL=LoadLibrary("regulardll1.dll");
if(hinstDLL)
{
typedef BOOL GetLastEventTime(char* ,int);
GetLastEventTime* p=(GetLastEventTime*)GetProcAddress(
hinstDLL, "GetLastEventTime");
if(NULL != p)
{
char buf[19]="";
if(p(buf,sizeof(buf)))//Problem happens here
{
CString str(buf);
MessageBox(hWnd,str,"",MB_OK);
}
}
}
GeneralRe: How to use mutex in a dll Pin
Diddy19-May-04 2:45
Diddy19-May-04 2:45 
GeneralRe: How to use mutex in a dll Pin
yingkou19-May-04 3:55
yingkou19-May-04 3:55 
GeneralRe: How to use mutex in a dll Pin
Diddy19-May-04 10:08
Diddy19-May-04 10:08 
GeneralUnreferenced memory Pin
krugger18-May-04 2:28
krugger18-May-04 2:28 
GeneralRe: Unreferenced memory Pin
Cedric Moonen18-May-04 2:37
Cedric Moonen18-May-04 2:37 
GeneralRe: Unreferenced memory Pin
David Crow18-May-04 3:14
David Crow18-May-04 3:14 
GeneralRe: Unreferenced memory Pin
valikac18-May-04 6:22
valikac18-May-04 6:22 
GeneralRe: Unreferenced memory Pin
Anonymous18-May-04 6:41
Anonymous18-May-04 6:41 
GeneralModeless CDialogbar Pin
krugger18-May-04 1:55
krugger18-May-04 1:55 
GeneralRe: Modeless CDialogbar Pin
Maximilien18-May-04 2:27
Maximilien18-May-04 2:27 
Generalmodal dialog Pin
Jiten D. Gandhi18-May-04 1:48
Jiten D. Gandhi18-May-04 1:48 
GeneralRe: modal dialog Pin
David Crow18-May-04 2:21
David Crow18-May-04 2:21 
GeneralRe: modal dialog Pin
Mahendra_78619-May-04 21:48
Mahendra_78619-May-04 21:48 
GeneralSending message to window Pin
Imtiaz Murtaza18-May-04 1:34
Imtiaz Murtaza18-May-04 1:34 
GeneralRe: Sending message to window Pin
jmkhael18-May-04 1:41
jmkhael18-May-04 1:41 
GeneralRe: Sending message to window Pin
Imtiaz Murtaza18-May-04 1:44
Imtiaz Murtaza18-May-04 1:44 
GeneralRe: Sending message to window Pin
jmkhael18-May-04 1:48
jmkhael18-May-04 1:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.