Solved

Writing Main Program to test dll

Posted on 2000-04-17
7
258 Views
Last Modified: 2010-04-10
I need a short Main program written in BC5 to test out my dll.
Dll complied using MFC, VC++6.
dll function -
extern "C" int Testing(void);
return value is the status of Testing function.
I have tried using _import and loadlibrary. But can't seems to work.

0
Comment
Question by:raymondwee
[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
  • 5
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
MDarling earned 50 total points
ID: 2722017
change extern "C" int Testing(void) to

extern "C" __declspec(dllexport) int Testing(void)

this will ensure that C++ exports your function correctly.
0
 
LVL 3

Expert Comment

by:MDarling
ID: 2722030
if your going to use your dll from other languages such as VB you should declare it also as stdcall like this...

extern "C" __declspec(dllexport) __stdcall int Testing(void)

This will ensure that the parameter passing method can be used by VB and other stdcall mechanism languages.

regards,
Mike.
0
 
LVL 3

Expert Comment

by:MDarling
ID: 2722038
a program to test this would look like...



void main()
{

  HANDLE hLib=LoadLibrary("MyLib.DLL");
  if(hLib)
  {
     FARPROC fProc=GetProcAddress(hLib,"Testing");
     if(fProc)
     {
      // successfully got proc address
     }
  }

}


0
Technology Partners: 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!

 

Author Comment

by:raymondwee
ID: 2722169
Adjusted points from 30 to 50
0
 

Author Comment

by:raymondwee
ID: 2722170
Thanks.
I have added those codes you mentioned.
but I can't get the address of the Function.(dll)
I have just changed my dll function to

extern int __declspec(dllimport) Test(char *name), where name is a input parameter for user to input name.

So my GetProcAddress should still be fProc = GetProcAddress(hLib,"Test");
right?

But the "if(fProc) ruturns NULL..

Pls help.



0
 
LVL 3

Expert Comment

by:MDarling
ID: 2722215
"C" grade?????
why not just ask for more info and not grade yet?


0
 
LVL 3

Expert Comment

by:MDarling
ID: 2722221
My answer was correct - by not putting extern "C" you have changed the name of the function.

You have introduced C++ name mangling - put the extern "C" back and all should be well.

Use the quickview application or depends.exe with VC++ to view the exports of a DLL.

C ???



0

Featured Post

Technology Partners: 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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

717 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