Link to home
Start Free TrialLog in
Avatar of raymondwee
raymondwee

asked on

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.

ASKER CERTIFIED SOLUTION
Avatar of MDarling
MDarling

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MDarling
MDarling

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.
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
     }
  }

}


Avatar of raymondwee

ASKER

Adjusted points from 30 to 50
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.



"C" grade?????
why not just ask for more info and not grade yet?


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 ???