• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

Writing Main Program to test dll

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
raymondwee
Asked:
raymondwee
  • 5
  • 2
1 Solution
 
MDarlingCommented:
change extern "C" int Testing(void) to

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

this will ensure that C++ exports your function correctly.
0
 
MDarlingCommented:
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
 
MDarlingCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
raymondweeAuthor Commented:
Adjusted points from 30 to 50
0
 
raymondweeAuthor Commented:
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
 
MDarlingCommented:
"C" grade?????
why not just ask for more info and not grade yet?


0
 
MDarlingCommented:
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

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now