Solved

How to compile a program too Dll without using MFC ?

Posted on 1998-08-24
10
213 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
  • 5
  • 5
10 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:dekoay
Comment Utility
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
Comment Utility
Did you link with the import library of the DLL?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:dekoay
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Chensu... I manage to create the DLL files. Thanks for yur help and advice.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now