Solved

DLL and GetProcAddress() Problem

Posted on 1998-03-16
10
631 Views
Last Modified: 2013-11-19
I've been developing a real time Image processing with
QuickCam program.
There are mainly 4 files

RV2.exe(uses rvcommon.dll through import lib and using mfc in dll)

rvcommon.dll(uses mfc in dll the project generated with appwizard using MfcExtension using MFC in dll)

addon1.dll(uses rvcommon.dll through import lib the project generated with appwizard using regular dll using MFC in dll)

addon2.dll(uses rvcommon.dll through import lib the project generated with appwizard using regular dll using MFC in dll)


addon*.dll is where the image processing functions reside.
users can load and unload them at rumtime.

rv2.exe would load addon1.dll and addon2.dll at runtime
using AfxLoadLibrary();

The program works fine under debug build(VC++5.0 sp3).But When I do a release build the program causes GPF whenever there is GetProcAddress() api. I have verified that AfxLoadLibrary() return correct HINSTANCE.

Does anyone got any idea why??


thanks

psksvp@ccs.neu.edu
0
Comment
Question by:petersvp
10 Comments
 
LVL 2

Expert Comment

by:mnguyen021997
ID: 1317016
a lot of times people get confused with ASSERT() and VERIFY().  you wouldn't happen to be doing an

ASSERT(AfxLoadLibrary()) would you?? if so then switch it to VERIFY().  

also initialize your hinstance variable to null prior to calling afxloadlibrary.  unless msoft screwed up it shouldn't be crashing for a null hinstance but may crash for an invalid (random stack value) instance.
0
 

Author Comment

by:petersvp
ID: 1317017
The problem is not the AfxLoadLibrary(), I verified it, before
I call GetProcAddress(). GetProcAddress() causes GPF whenever
I call it in a release build. In debug build, my program
works perfectly..without any asserting...

anyhelp would be great

psksvp@ccs.neu.edu
0
 

Expert Comment

by:JohnWeidner
ID: 1317018
If you load the library with out a full path specification, it could be that there is an old copy of the DLL in the "release" directory that is being loaded.
0
 

Expert Comment

by:dr_funfrock
ID: 1317019

  I think you need to use _AFXDLL define in your app or DLL.
0
 

Author Comment

by:petersvp
ID: 1317020
When I build(both debug and release), I always have all the
dll(s) and exe, put into a same dir, regradless of release
or debug build.. so there would be only one place where the    dll(s) could be.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:dustinn
ID: 1317021
Can you post a code snippet of the GetProcAddress call that is causing the crash?  Also, include any pertinent code around that general area of the program (specifically, code that modifies any of the parameters to GetProcAddress).
0
 

Author Comment

by:petersvp
ID: 1317022
Is this can be the case, I pass and MFC-derived class to a
function in the DLL. I just read an article in KB that MFC app
cannot pass MFC-derived class to RegularDLL..

nayone has any idea, if this is true..
0
 

Accepted Solution

by:
dustinn earned 100 total points
ID: 1317023
In order to pass an MFC class between modules (EXE and DLL or DLL and DLL) you must create an MFC Extension DLL.  A normal DLL will not work.

If you are using VC++ 5.0, AppWizard can create a shell of an MFC Extension DLL for you.  An extension DLL requires certain #defines and other implementation specifics that a regular DLL doesn't.

Check out "Inside VC++" by David Kruglinski for an in-depth discussion of the differences between the two.
0
 

Author Comment

by:petersvp
ID: 1317024
one last question before I go and fix my code.
If I call the MFC Extension DLL explicitly by using
AfxLoadLibrary(). Does the DLLMain() get called?
Or I need another export function that create
CDynLinkLibrary() ?
Thanks for all yoou helps
psksvp@ccs.neu.edu
0
 

Expert Comment

by:dustinn
ID: 1317025
DllMain() will get called.  You should never have to play with the CDynLinkLibrary object that gets created by your DLL.  You should create the object in your DllMain() with a call to AfxInitExtensionModule() like so:

BOOL WINAPI DllMain(HMODULE hInst, ULONG uReason,
                    LPVOID lpvReserved)
{
    if (uReason == DLL_PROCESS_ATTACH)
    {
        if (!AfxInitExtensionModule(extMyExtension, hInst))
            return 0;
    }

    return 1;

}

And, if you are using AfxLoadLibrary() to load the DLL you should also add the following code to DllMain():

if (uReason == DLL_PROCESS_DETACH)
{
    AfxTermExtensionModule(extMyExtension)
}

This is not necessary, but recommended, otherwise the memory and resources allocated by your call to AfxInitExtensionModule() will not be freed until the calling executable terminates.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now