I am developing a non-MFC dialog-less dll using version release 1.11.0 (I have also tried 1.10.2) and would like to use the MfcTestRunner, called from a win32 console-app, using VC6 for development but this will not open the testrunner dialog.
I can call a test-runner in my dll that directly use the textbased runner (CppUnit::CompilerOutputter:: defaultOutputter) tests from a win32-app and it work perfect.
I had a number of problems to compile and let my dll call the mfctestrunner. I'll show you below what I did to solve the compile issues, but I'm stranded on a resource issue (?) in the MfcTestRunner::run() method, the line with dlg.DoModal ().
I get an exception in AFXWIN1.INL line 22
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL); <============= this line
Call stack:
-----------
AfxGetResourceHandle() line 22 + 33 bytes
CDialog::DoModal() line 502 + 5 bytes
CppUnit::MfcTestRunner::run() line 42
CMyDllTestRunnerCaller::Run() line ....
In the CDialog::DoModal() method parameter m_lpszTemplateName has the right resource name
("CPP_UNIT_TEST_RUNNER_IDD_DIALOG_TESTRUNNER"), the m_lpDialogTemplate and m_lpDialogTemplate are both NULL when I
call HINSTANCE hInst = AfxGetResourceHandle(); where things breaks.
Question: Is there some fundamentally wrong here?
- The MfcTestrunner "uses MFC in a shared dll",
- my dll is "not using MFC" (WIN32,_DEBUG,_WINDOWS,_MBCS,_AFXDLL).
- my console app is "not using MFC" (WIN32,_DEBUG,_CONSOLE,_MBCS).
It does not make any difference if I use cppunitd.xxx or cppunitd_dll.xxx in my dll, switching CPPUNIT_DLL to compensate for this.
I have in other projects used the mfctestrunner successfully, called from MFC exe but not called from a dll.
Problem (solved) to make my dll compile:
--------------------------------------------------
I get the compiler message "...mfctestrunner.h(53) : error C2079: MfcTestRunner' uses undefined class 'AFX_EXT_CLASS".
I first tried this:
I made a number of attempts to include som standard files to get the default handling of AFX_EXT_CLASS by adding
#include <afxver_.h> // declares AFX_DATA_IMPORT
#include <afxv_dll.h> // declares AFX_EXT_CLASS
but then I got the error
C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h> (error from afxv_w32.h)
I solved this by removing the includes above and instead temporarily define AFX_EXT_CLASS to import the MfcTestRunner class by adding these lines to my dll code:
#undef MY_EXT_CLASS_ORIG_
#define MY_EXT_CLASS_ORIG_ AFX_EXT_CLASS // remember original value
#undef AFX_EXT_CLASS
#define AFX_EXT_CLASS __declspec(dllimport)
# include <cppunit/ui/mfc/MfcTestRunner.h> // now declares MfcTestRunner for dllimport
#undef AFX_EXT_CLASS
#define AFX_EXT_CLASS MY_EXT_CLASS_ORIG_// restore original value
#undef MY_EXT_CLASS_ORIG_
Hope you can help me
/Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am developing a non-MFC dialog-less dll using version release 1.11.0 (I have also tried 1.10.2) and would like to use the MfcTestRunner, called from a win32 console-app, using VC6 for development but this will not open the testrunner dialog.
I can call a test-runner in my dll that directly use the textbased runner (CppUnit::CompilerOutputter:: defaultOutputter) tests from a win32-app and it work perfect.
I had a number of problems to compile and let my dll call the mfctestrunner. I'll show you below what I did to solve the compile issues, but I'm stranded on a resource issue (?) in the MfcTestRunner::run() method, the line with dlg.DoModal ().
I get an exception in AFXWIN1.INL line 22
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL); <============= this line
Call stack:
-----------
AfxGetResourceHandle() line 22 + 33 bytes
CDialog::DoModal() line 502 + 5 bytes
CppUnit::MfcTestRunner::run() line 42
CMyDllTestRunnerCaller::Run() line ....
In the CDialog::DoModal() method parameter m_lpszTemplateName has the right resource name
("CPP_UNIT_TEST_RUNNER_IDD_DIALOG_TESTRUNNER"), the m_lpDialogTemplate and m_lpDialogTemplate are both NULL when I
call HINSTANCE hInst = AfxGetResourceHandle(); where things breaks.
Question: Is there some fundamentally wrong here?
- The MfcTestrunner "uses MFC in a shared dll",
- my dll is "not using MFC" (WIN32,_DEBUG,_WINDOWS,_MBCS,_AFXDLL).
- my console app is "not using MFC" (WIN32,_DEBUG,_CONSOLE,_MBCS).
It does not make any difference if I use cppunitd.xxx or cppunitd_dll.xxx in my dll, switching CPPUNIT_DLL to compensate for this.
I have in other projects used the mfctestrunner successfully, called from MFC exe but not called from a dll.
Problem (solved) to make my dll compile:
--------------------------------------------------
I get the compiler message "...mfctestrunner.h(53) : error C2079: MfcTestRunner' uses undefined class 'AFX_EXT_CLASS".
I first tried this:
I made a number of attempts to include som standard files to get the default handling of AFX_EXT_CLASS by adding
#include <afxver_.h> // declares AFX_DATA_IMPORT
#include <afxv_dll.h> // declares AFX_EXT_CLASS
but then I got the error
C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h> (error from afxv_w32.h)
I solved this by removing the includes above and instead temporarily define AFX_EXT_CLASS to import the MfcTestRunner class by adding these lines to my dll code:
#undef MY_EXT_CLASS_ORIG_
#define MY_EXT_CLASS_ORIG_ AFX_EXT_CLASS // remember original value
#undef AFX_EXT_CLASS
#define AFX_EXT_CLASS __declspec(dllimport)
# include <cppunit/ui/mfc/MfcTestRunner.h> // now declares MfcTestRunner for dllimport
#undef AFX_EXT_CLASS
#define AFX_EXT_CLASS MY_EXT_CLASS_ORIG_// restore original value
#undef MY_EXT_CLASS_ORIG_
Hope you can help me
/Chris