Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
I have created an .ocx with MFC ActiveX Wizard in C++. Now, I have a .dll, I want to call the .dll with the .ocx. So,how to do?

Thank you very much?
Posted

You can simply #include the header file defining the functions you need and use #pragma comment(lib, "YOUR_PATH\YOUR_LIB.lib")

You also could use the environment variable LIB. The DLL must be in the PATH.
 
Share this answer
 
v2
Comments
Espen Harlinn 19-Jan-11 8:18am    
5+ Sounds reasonable, but I would go for #pragma comment(lib, "YOUR_LIB"), and use project settings to set up the library path for the ocx.
T2102 19-Jan-11 17:26pm    
I did it that way for a few years, but switched to a version where I have a different output directory for each configuration. When I finish building all of the projects in a configuration, I then copy the add-ins from the output directory to my add-in directory in the path.

For file paths, I use the preprocessor to prepend the particular include directory. I think this may reduce link-time, makes it easier to read, and trace through code. I've found it hard to work with projects in the past the combined a few other projects that all defined date classes for instance.

In Visual C++, I haven't gotten a preprocessor working for a configuration specific lib path consistently for all of native/MFC/CLR projects. So I simply add some extra code

#ifdef _DEBUG
#pragma comment(lib "C:/Addins/Your_Lib.lib")
#else
...
flyicing 19-Jan-11 21:25pm    
Thank you for your answer!
But I need call the DLL dynamically, that is, using LoadLibrary("*.dll");
So, what should I do?
You need the .tlh (Type Library Header) file of your ocx.
i.e. with excel:
#include "EXCEL8.tlh"
void doanythingwithexcel()
{
  Excel::_ApplicationPtr  excelapp;
  if(S_OK==excelapp.CreateInstance(__TEXT("Excel.Application"))
  {
    excelapp->Visible = 1;
    MessageBox(0,__TEXT("close excel?"),__TEXT("???"),MB_OK);
    excelapp->Quit();
  }
}
 
Share this answer
 
Comments
Nish Nishant 19-Jan-11 15:37pm    
I think you mis-read his question. He wants to call into a regular DLL from his OCX.
mbue 20-Jan-11 15:19pm    
Oh sorry, yes indeed i've read the question vice versa. :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900