?
Solved

function not working in DLL

Posted on 2002-04-27
12
Medium Priority
?
244 Views
Last Modified: 2013-11-20
The following function works fine when the class "Util" was part of the MFC project I am writing.

void CBBrowserView::DMakeFormPretty()
{
     Util *utilCTRL = new Util;
     if(::IsWindow(m_EnglishCTRL.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_EnglishCTRL,"Courier New",17);

     //Init Font Resources for the Non-English Verse
     utilCTRL->ApplyFontToObj(&m_NonEnglishCTRL,"OLBHEB",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(intFontSize,0,0,0,intWeight,bItalic,bUnderline,0,
          ANSI_CHARSET,OUT_DEFAULT_PRECIS,
          CLIP_DEFAULT_PRECIS,DEFAULT_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(&cfFontHolder);
     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
0
Comment
Question by:Smave
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 

Author Comment

by:Smave
ID: 6974180
NOTE: m_EnglishCTRL is a control member variable for an Edit box.

CEdit     m_EnglishCTRL;

Thanx
Dave
0
 

Author Comment

by:Smave
ID: 6974212
ALSO: this is the out put from the TRACE macros:
*****DMFP Is Window 1836788
*****AFTO Not Window 0
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6974261
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.

0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6974268
(not batch build) - I meant (not incremental build)
0
 

Author Comment

by:Smave
ID: 6974947
Tried that.  It didn't work.
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6975706
Hmmmmm...
Maybe you will have to zip up both projects and post a link to them for experts to have a closer look.
0
 

Author Comment

by:Smave
ID: 6975817
OK.  Will do.  Stand by...
0
 

Author Comment

by:Smave
ID: 6975935
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
0
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 400 total points
ID: 6976124
Your dll project has "Use MFC in a shared Dll".
Your exe project has "Use MFC in a static library".

Change your exe project to "shared dll".

Cheers Greg
0
 

Author Comment

by:Smave
ID: 6976147
I feel a little stupid.  But, I figured the solution would probably be that dumb.

Question: Why should that matter?

Thanx again
Dave
0
 

Author Comment

by:Smave
ID: 6976150
Just a thought.  While you have the project there...

If you have any constructive criticism it would be appreciated.

Thanx again
Dave
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6976193
The CWnd structure has different members depending upon whether or not you are linking statically or dynmaically.
The CRuntimeClass::m_pfnGetBaseClass 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
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question