Link to home
Start Free TrialLog in
Avatar of BlueKarana
BlueKarana

asked on

Visual Studio 2010 MFC ActiveX: How to declare and call a function in a DLL

I've created an MFC ActiveX Control in VS 2010 using the MFC ActiveX Wizard.

I need to call a function in an existing DLL. How do I declare it? Where would the declaration go?

All I know about the function is the declaration given to me (see code snippet)

BTW, I'm a complete nube in VS and C++ so the more detail the better :)

Int TheFunction (
  HDC hdc,      // handle to the device context
  Int nEscape,   
  Int cbParameter,
  LPCSTR lpszParameter,  //use char* ?
  Int cbResult,
  LPSTR lpszResult      //use char* ?
);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

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

ASKER

After an hour of searching, submitting the question...two seconds later I may have found the answer:

found code at: http://goffconcepts.com/techarticles/development/cpp/calldll.html

Haven't tested it yet, though.
// Define the DLL function
	/* get handle to dll */
		HINSTANCE hGetProcIDDLL = LoadLibraryW(LPCWSTR("TheDLLFile.dll")); 

	   /* get pointer to the function in the dll*/
		FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"TheFunction"); 

	   /* 
		  Define the Function in the DLL for reuse. This is just prototyping the dll's function. 
		  A mock of it. Use "stdcall" for maximum compatibility. 
	   */
		typedef int (__stdcall * pICFUNC)(HANDLE, int, int, const char*, int, char*); 

	   pICFUNC TheFunction; 
	   TheFunction = pICFUNC(lpfnGetProcessID);

Open in new window

The second snippet looks like what I need.

Thanks!