Solved

VC++ Console Application & DLL File

Posted on 1998-09-29
7
365 Views
Last Modified: 2008-03-06
I have a CGI/Console application that I want to add a DLL file(s) to.  I have found plenty of resources on how to do this in a windows environment, but not in a DOS/Console application environment.  Does anyone know how or where a good resource is that describes this process.  Or even sample code would be appreciated.  

Thanks
0
Comment
Question by:delvin
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1174041
As long as it is windows console program, you can use DLL just as you do it in normal windows application.  You can link with a import lib or use LoadLibrary(), all win32 API works.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1174042
DOS programs cannot use DLLs.  DOS was written 10 years prior to the first DLL.

But a win32 console program looks a lot like a DOS program to the user.  It looks a lot like a standard C++ program to the programmer.  And it has complete access to the windows API functions and 32 bit memory.  I suspect you are using a win32 console program already (not DOS), but if not, there is a good chance that you can easily change to a win32 console program with little effort.  (Note VC 5 and 6 do not produce DOS programs.  If that is what you are using, you already have a console program.)
0
 

Author Comment

by:delvin
ID: 1174043
Do you know of a good book that covers this topic?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Accepted Solution

by:
NullTerminator earned 70 total points
ID: 1174044
Like Nietod said, dos itself does not support dlls at all. If you are using MSVC 4 or better you can't really create a straight dos program.  But for a console app, you can use dll.

Assume you have header file for functions in the dll
include that header in your app file

///////////////////////////////////
// myDLL.h
int someFunc(int argIN);
///////////////////////////////////

When you build the dll the linker also creates a .lib file
Add the LIB file to your project to resolve linker calls at
compile time.  Open your project,  select Build | Settings -- Link Tab -- Drop down select input,  add the path to your lib.   Make Sure the dll is in the path or in the same directory where you will run the executable.

///////////////////////////////////////////////////////
//source for dll
extern "C" int someFunc(int argIn) { return argIn; }

DllMain(....) { etc. }
//////////////////////////////////////////////////////

///////////////////////////////////////////////////
// MyDLL.def file   USED BY DLL BUILD
LIBRARY                MYDLL
EXPORTS
      someFunc     @1
/////////////////////////////////////////////////

HTH
'\0'
0
 
LVL 22

Expert Comment

by:nietod
ID: 1174045
>> Do you know of a good book that covers this topic?
What topic?  DLLs?  That is not that big an issue that a book would be devoted to it.  Any introductory windows programming book will do.  The VC on-line help will as well.
0
 
LVL 7

Expert Comment

by:faster
ID: 1174046
You don't need any book if you already know tranditional windows programming.
0
 

Author Comment

by:delvin
ID: 1174047
Thanks ALL!  I should be able to take it from here. :)  I can always count on the experts at the experts-exchange to come through.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

776 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