Smave
asked on
function not working in DLL
The following function works fine when the class "Util" was part of the MFC project I am writing.
void CBBrowserView::DMakeFormPr etty()
{
Util *utilCTRL = new Util;
if(::IsWindow(m_EnglishCTR L.m_hWnd))
TRACE("*****DMFP Is Window %d\n",m_EnglishCTRL.m_hWnd );
else
TRACE("*****DMFP Not Window %d\n",m_EnglishCTRL.m_hWnd );
//Init Font Resources for the English Verse
utilCTRL->ApplyFontToObj(& m_EnglishC TRL,"Couri er New",17);
//Init Font Resources for the Non-English Verse
utilCTRL->ApplyFontToObj(& m_NonEngli shCTRL,"OL BHEB",17);
delete utilCTRL;
}
I created an MFC extension DLL and transfered the Util class to it.
The Util class is declared in the "Util.h" class like this:
class AFX_EXT_CLASS Util : public CCmdTarget
I changed the #include statement in the CPP for the "Util.h" to point it to it's new location.
Also, in the Project Settings Link tab, I put the path to the new DLLs .Lib file there.
The function I am calling in the DLL is as follows:
The prototype:
void Util::ApplyFontToObj(CWnd* p_objToApply, CString strFontName, int intFontSize, int intWeight, bool bItalic, bool bUnderline)
{
CFont cfFontHolder; // structure for applying a font to an object
//Init Font Resources for the search for edit box
cfFontHolder.CreateFont(in tFontSize, 0,0,0,intW eight,bIta lic,bUnder line,0,
ANSI_CHARSET,OUT_DEFAULT_P RECIS,
CLIP_DEFAULT_PRECIS,DEFAUL T_QUALITY,
DEFAULT_PITCH | FF_SWISS, strFontName);
if(::IsWindow(p_objToApply ->m_hWnd))
TRACE("*****AFTO Is Window %d\n", p_objToApply->m_hWnd);
else
TRACE("*****AFTO Not Window %d\n", p_objToApply->m_hWnd);
p_objToApply->SetFont(&cfF ontHolder) ;
cfFontHolder.Detach(); //release DC
}
The ::IsWindows function returns true in the EXE but not in the DLL. In fact the m_hWnd is zero in the DLL.
Like I said, the Util::ApplyFontToObj function worked just fine when is was implemented in the EXE. When I implemented it into the DLL the CWnd* p_objToApply variable seems to have lost its refenence.
What is that?
Thanx
Dave
void CBBrowserView::DMakeFormPr
{
Util *utilCTRL = new Util;
if(::IsWindow(m_EnglishCTR
TRACE("*****DMFP Is Window %d\n",m_EnglishCTRL.m_hWnd
else
TRACE("*****DMFP Not Window %d\n",m_EnglishCTRL.m_hWnd
//Init Font Resources for the English Verse
utilCTRL->ApplyFontToObj(&
//Init Font Resources for the Non-English Verse
utilCTRL->ApplyFontToObj(&
delete utilCTRL;
}
I created an MFC extension DLL and transfered the Util class to it.
The Util class is declared in the "Util.h" class like this:
class AFX_EXT_CLASS Util : public CCmdTarget
I changed the #include statement in the CPP for the "Util.h" to point it to it's new location.
Also, in the Project Settings Link tab, I put the path to the new DLLs .Lib file there.
The function I am calling in the DLL is as follows:
The prototype:
void Util::ApplyFontToObj(CWnd*
{
CFont cfFontHolder; // structure for applying a font to an object
//Init Font Resources for the search for edit box
cfFontHolder.CreateFont(in
ANSI_CHARSET,OUT_DEFAULT_P
CLIP_DEFAULT_PRECIS,DEFAUL
DEFAULT_PITCH | FF_SWISS, strFontName);
if(::IsWindow(p_objToApply
TRACE("*****AFTO Is Window %d\n", p_objToApply->m_hWnd);
else
TRACE("*****AFTO Not Window %d\n", p_objToApply->m_hWnd);
p_objToApply->SetFont(&cfF
cfFontHolder.Detach(); //release DC
}
The ::IsWindows function returns true in the EXE but not in the DLL. In fact the m_hWnd is zero in the DLL.
Like I said, the Util::ApplyFontToObj function worked just fine when is was implemented in the EXE. When I implemented it into the DLL the CWnd* p_objToApply variable seems to have lost its refenence.
What is that?
Thanx
Dave
ASKER
ALSO: this is the out put from the TRACE macros:
*****DMFP Is Window 1836788
*****AFTO Not Window 0
*****DMFP Is Window 1836788
*****AFTO Not Window 0
First thoughts...
After checking that the "Structure member alignment", code geration option is the same in you exe & dll, I would do a "Rebuild All" (not batch build) on both the exe & dll, keeping fingers & toes firmly crossed.
After checking that the "Structure member alignment", code geration option is the same in you exe & dll, I would do a "Rebuild All" (not batch build) on both the exe & dll, keeping fingers & toes firmly crossed.
(not batch build) - I meant (not incremental build)
ASKER
Tried that. It didn't work.
Hmmmmm...
Maybe you will have to zip up both projects and post a link to them for experts to have a closer look.
Maybe you will have to zip up both projects and post a link to them for experts to have a closer look.
ASKER
OK. Will do. Stand by...
ASKER
Here is the URL to my FTP site.
ftp://24.159.56.211/ProgShare/
Username:IUSER
Password: expert
Download Theo.zip from there.
I am running ZoneAlarmPro, so let me know if you have any problems.
Dave
ftp://24.159.56.211/ProgShare/
Username:IUSER
Password: expert
Download Theo.zip from there.
I am running ZoneAlarmPro, so let me know if you have any problems.
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I feel a little stupid. But, I figured the solution would probably be that dumb.
Question: Why should that matter?
Thanx again
Dave
Question: Why should that matter?
Thanx again
Dave
ASKER
Just a thought. While you have the project there...
If you have any constructive criticism it would be appreciated.
Thanx again
Dave
If you have any constructive criticism it would be appreciated.
Thanx again
Dave
The CWnd structure has different members depending upon whether or not you are linking statically or dynmaically.
The CRuntimeClass::m_pfnGetBas eClass is different.
Makes it difficult when your exe & your dll each have their own opinion of the layout of structures which they pass around.
Cheers
The CRuntimeClass::m_pfnGetBas
Makes it difficult when your exe & your dll each have their own opinion of the layout of structures which they pass around.
Cheers
ASKER
CEdit m_EnglishCTRL;
Thanx
Dave