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.
dekoayAsked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
Look into the Visual C++ documentation: Visual C++ Programmer's Guide\Adding Program Functionality\Overviews\Overviews: Adding Program Functionality\DLLs: Overview\Non-MFC DLLs: Overview.

You need to #include <math.h> for pow.

0
 
dekoayAuthor Commented:
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

0
 
chensuCommented:
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.

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
dekoayAuthor Commented:
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 ?
0
 
chensuCommented:
Did you link with the import library of the DLL?
0
 
dekoayAuthor Commented:
Hi Chensu.... I understand u mention file with extension .DEF... Does compiler generate this file or we have to type it manually ?
0
 
chensuCommented:
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.
0
 
dekoayAuthor Commented:
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
0
 
chensuCommented:
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.
0
 
dekoayAuthor Commented:
Hi Chensu... I manage to create the DLL files. Thanks for yur help and advice.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.