Link to home
Start Free TrialLog in
Avatar of dekoay
dekoay

asked on

How to compile a program too Dll without using MFC ?

Hello everyone...

I have a program consists of many functions written in MSVC++ as .CPP. I have compiled this program and tested it which is free of bugs.. Right now, I taught convert this program into a DLL.. How can I compile existing code into Dlll without using MFC? Does pow(double,double) functions in math work in DLL ? I have compilation error mention that pow undeclared.. How do i solve this problem....

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada 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 dekoay
dekoay

ASKER

1. I have put the math header file but there is still compilation error saying pow undeclared...

2. I'm still looking forward to a better hints on how to make dll file (without using MFC) than just look at the book as I'm just a beginner

1. Show your code.

2.
To create a Win32 DLL

1. On the File menu, click New and then click the Projects tab.
2. Specify the Project Name, Location, Workspace, Dependency, and Platforms options and then double-click the Dynamic Link-Library icon.
3. On the Project menu, point to Add to Project, then click Files to add your source code files to the project.
4. If needed, add a function called DllMain and add the initialization and termination code for the DLL to this function.
5. Make sure you have exported the entry points to your DLL by using either the __declspec(dllexport) keyword or by listing the functions in the DLL's .DEF file.
6. Prepare a header file that includes the programs using your DLL. This header file should contain the declarations of the appropriate functions. When the header file is compiled for a DLL, use the __declspec(dllexport) keyword to export from the DLL. When the header file is compiled for a program that uses the DLL, use the declspec(dllimport) keyword.
7. If your DLL uses __declspec(dllexport) or a .DEF file, an import library will be created automatically. In other situtations you will need to prepare an import library for your programs to link with by ensuring that the /IMPLIB linker switch is set when building your DLL.
8. Build the DLL.

Avatar of dekoay

ASKER

Thank you for the fast response chensu. I really appreciate it.... I manage to compile to .dll, unfortunately when I try to use the function(which I created in dll), it was unable to
link to exe
Example code in dll
#include <iostream.h>
void show(var char[])
{
cout << var << endl;
}

eg of retrieving the function (filename test.cpp)
#include "hello.h"
void main()
{
char t[] = "Hello";
show(t);
}

When I rebuild test.cpp to exe... linker give me unresolved external symbol void_decl show( char *const).......andd so on.. Is there anything that I miss out ?
Did you link with the import library of the DLL?
Avatar of dekoay

ASKER

Hi Chensu.... I understand u mention file with extension .DEF... Does compiler generate this file or we have to type it manually ?
If you use the __declspec(dllexport) keyword, a .DEF file is not needed. The compiler does not generate it, you have to create it yourself and add it into the project.
Avatar of dekoay

ASKER

Hello Chensu.. Thanks for replying... really aprreciate it.

1.  I am still wondering where or which file should I add this _declspec(dllexport).
2. How do I link to my test.cpp which I execute, it can called up my function in DLL

Your help will be very much appreciate.

Thank You
1. If you want to export your show function.
void __declspec(dllexport) show()
{
}
2. When you build a DLL, an import library (.lib) is generated. Add the .lib into your project so that you can call the exported functions.

I would suggest you read the documentation I mentioned. Don't jump into coding.

You are welcome.
Avatar of dekoay

ASKER

Hi Chensu... I manage to create the DLL files. Thanks for yur help and advice.