Solved

How to compile a program too Dll without using MFC ?

Posted on 1998-08-24
10
251 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:dekoay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1171136
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
 

Author Comment

by:dekoay
ID: 1171137
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
 
LVL 23

Expert Comment

by:chensu
ID: 1171138
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dekoay
ID: 1171139
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
 
LVL 23

Expert Comment

by:chensu
ID: 1171140
Did you link with the import library of the DLL?
0
 

Author Comment

by:dekoay
ID: 1171141
Hi Chensu.... I understand u mention file with extension .DEF... Does compiler generate this file or we have to type it manually ?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1171142
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
 

Author Comment

by:dekoay
ID: 1171143
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
 
LVL 23

Expert Comment

by:chensu
ID: 1171144
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
 

Author Comment

by:dekoay
ID: 1171145
Hi Chensu... I manage to create the DLL files. Thanks for yur help and advice.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question