[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Calling DLL Function

Posted on 2002-05-10
14
Medium Priority
?
201 Views
Last Modified: 2010-04-02
I want to have my application call a function in a DLL without linking to the DLL's header file. Here's how i defined the DLL function. How should I call it from my program?

__declspec(dllexport) void* CMyApp::DLLFUNC()
{
     m_ret = new COtherClass();
     return (void*)m_ret;
}
0
Comment
Question by:qqqqqqqqq
[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
  • 3
  • 2
  • +1
14 Comments
 

Author Comment

by:qqqqqqqqq
ID: 7002828
I have this much:
HMODULE hMod = LoadLibrary( "PathToMyDLL" );
Now that my DLL is loaded what should I do to call a specific function?
0
 
LVL 32

Accepted Solution

by:
jhance earned 400 total points
ID: 7003016
First, determine the NAME of the EXPORT you want to call.  Use the Visual Studio tool DUMPBIN.EXE like:

DUMBIN /EXPORTS PathToMyDll.Dll

Find the exact name of your export function and then use the GetProcAddress() to get it's loaded address:

FARPROC myFunction;
myFunction = GetProcAddress(hMod, "NameYouFoundUsingDUMPBIN");
if(myFunction == NULL){
  // ERROR, function not found...
}
0
 
LVL 32

Expert Comment

by:jhance
ID: 7003285
You have a number of open questions needing your attention:

Questions Asked 6
Last 10 Grades Given A B  
Question Grading Record 2 Answers Graded / 2 Answers Received


http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20298614
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20294637
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20294243
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!

 
LVL 86

Expert Comment

by:jkr
ID: 7003425
0
 

Author Comment

by:qqqqqqqqq
ID: 7003561
i know i have open questions but they are all active (all have a post within the last day)
0
 

Author Comment

by:qqqqqqqqq
ID: 7003566
jhance: so how would I invoke the function after that?
jkr: your link doesn't load for me
0
 
LVL 86

Expert Comment

by:jkr
ID: 7003594
just copied it from the brpwser: http://www.codeguru.com/win32/dyndllclass.shtml works...
0
 

Author Comment

by:qqqqqqqqq
ID: 7003602
i have no access to the whole codeguru site, no clue why. Can you just post the code to call the function?
0
 
LVL 32

Expert Comment

by:jhance
ID: 7003771
>>so how would I invoke the function after that?

myFunction();
0
 

Author Comment

by:qqqqqqqqq
ID: 7003830
ok thanks. My problem is that when i try to run DUMPBIN.EXE i get errors about missing DLLs. I've tried re-installing VC++6. Is there a way to find the name of the function based on it's name in the source code? (It's not the same, because I tried the name of the function in the dll and the function wasn't invoked)
0
 

Author Comment

by:qqqqqqqqq
ID: 7004141
nevermind about the dumpbin problem. I found the answer in a USENET group. I see that the function export name is: ?DLLFUNC@CMyApp@@QAEPAXXZ. I plan on using this code for multiple DLLs with the same function in them. It seems like the ?DLLFUNC@CMyApp@@ part will be the same but will the QAEPAXXZ part change? If so, is there a way to modify this to work with multiple DLLs?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7004756
If you don't haf a .DEF fiel for your DLL, add one like this:

; Merger.def : Declares the module parameters for the DLL.

LIBRARY      "ABC_Plugin"
DESCRIPTION  'Plugin Dynamic Link Library'

EXPORTS
    ; Explicit exports can go here
MyFirstExportedFn         @1
AnotherExportedFn         @2

-==-=-=-=-=-=-=-
That cleans up the 'decorations' on the exported fn names.

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7004768
You can also view exported fn names using DEPENDS.EXE (it is a tool in the ...\Common\tools dir, available via the Start button.

-- Dan
0
 

Author Comment

by:qqqqqqqqq
ID: 7004914
jhance: thank you very much
dan: thanks for the tip about cleaning up the name
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

650 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