Help wiht regular MFC DLL
Hi there,
I'm quite a newbie in MFC....
I have a porjet alread written in C and now I have to write a so
saying Spy Tool to verifiy some data of it. So in order to do so, I
have create a C projet (dummy to serve as the main program) and then
create a MFC regular DLL (as we are intrefacing with C program).
So, the dummy C program is nothing but just a C 'Hello World" projet a
dynamic call to the DLL. Here is the code:
///
*******************************************************************************************//
#include <windows.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows
headers
#include <stdio.h>
/***************************** from MFC
****************************////////
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows
headers
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/********************************************* thi is how is define in
EXCP.h *******************
#ifdef _MSC_VER
/*
* Currently, all MS C compilers for Win32 platforms default to 8 byte
* alignment.
#pragma pack(push,8)
#endif /* _MSC_VER */
typedef void (*pfDLLFunc)();
main ()
{
pfDLLFunc _DLLFunc;
//Load DLL Library
HINSTANCE hInstLibrary = LoadLibrary("NewRegularDll.dll");
//Library is not loaded, free the allocated space
if (hInstLibrary == NULL)
{
FreeLibrary(hInstLibrary);
}
//Get the Export function
_DLLFunc= (pfDLLFunc) GetProcAddress(hInstLibrary, "CallMyApp");
//call the export function
_DLLFunc ();
}
//
*******************************************************************************************///
So it looks simple no? just forget about all the include.... (if
possible)
So now here is my DLL.
A regular DLL created using VC++ Wizard.
What I want to do is able to spawn a window from when the CallMyApp is
called in the Dummy C program.
There is a rule saying that non MFC program cant call a MFC class.
So to do so, I create an other fucntion, which is CallMyApp which is
to be exported and in this function we'll call a Dialog.
But it just can work. So to do so I'll create a Thread and in the
Thread the dialog will be created
Here is the ExportDll file
//
*****************************************************************************************//
#include "stdafx.h"
#include "NewRegularDll.h"
#include "MFCThread.h"
#include "stdio.h"
CMFCThread *m_mfcthread;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
__declspec(dllexport) void CallMyApp()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_mfcthread = new CMFCThread ();
m_mfcthread->m_bAutoDelete = FALSE;
m_mfcthread->CreateThread();
}
#ifdef __cplusplus
}
#endif
///////////////////////
******************************************************************///////////////
Here is the Thread Defination:
//////
******************************************************************************/////////////
// MFCThread.cpp : implementation file
#include "stdafx.h"
#include "NewRegularDll.h"
#include "MFCThread.h"
#include "MFCDoModalDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMFCThread
IMPLEMENT_DYNCREATE(CMFCThread, CWinThread)
CMFCThread::CMFCThread()
{
}
CMFCThread::~CMFCThread()
{
}
BOOL CMFCThread::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
int CMFCThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CMFCThread, CWinThread)
//{{AFX_MSG_MAP(CMFCThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMFCThread message handlers
int CMFCThread::Run()
{
CMFCDoModalDlg myDoModalDlg;
myDoModalDlg.DoModal();
return 1;
}
///////
*****************************************************************************////////////
So here is the senario.....
When I run my Dummy C program, nothting happen.....
So in order to test if I have been mistaken in my coding, I try the
same thing but this time the Dummy program is not a C but Win32
console support MFC.....;
the result is what I expected..;I have my Dialog......
Can anyone tell me what to do??
I have gone through lots of tutorials and forum, but don't seem there
was anyone facing the same problem...
THx for helping.
TAN