Solved

DLL and GetProcAddress() Problem

Posted on 1998-03-16
10
646 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is it possible to combine several text files into one big one? (redhat v5 enterprise) 4 102
Process filename extension 3 194
sum67 challenge 35 107
wait notify demo infinite loop 3 122
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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