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

x
?
Solved

Writing Main Program to test dll

Posted on 2000-04-17
7
Medium Priority
?
268 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 100 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

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