Solved

Writing Main Program to test dll

Posted on 2000-04-17
7
218 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
  • 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
Highfive Gives IT Their Time Back

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!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

747 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

10 Experts available now in Live!

Get 1:1 Help Now