Solved

DLL and GetProcAddress() Problem

Posted on 1998-03-16
10
653 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 97
notReplace  challenge 53 152
modThree challenge 4 153
x-bar in Google Sheets 2 126
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…

739 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