Creating statically linked, non-MFC DLLs Connecticut

This article illustrates how to create and use Statically linked Non-MFC (Implicit) DLLs.

Local Companies

Nandvarik Systems
999-999-9999
Farmington
Hartford, CT
Microsoft
(860) 916-7448
74 Batterson Park Rd., Ste. 100
Farmington, CT
GoECart
203 336 2284
Park City Plaza, 10 Middle Street
Bridgeport, CT
Teamworks Inc
(203) 852-7230
95 Rowayton Ave
Norwalk, CT
Tri-Com Consulting Group Llc
(860) 635-9600
333 Industrial Park Rd
Middletown, CT
Media Lantern Inc,
(800) 705-1213
236 State Street
New London, CT
OFFiS Corporation
203-265-6700
61 N Plains Industrial Rd
Wallingford, CT
Tamion Company
800-582-9637
1178 Mill Street
East Berlin, CT
Coordinated Systems, Inc.
860-289-2151
165 Burnside Avenue
East Hartford, CT
Computer Consulting Associates
(203) 255-8966
Fairfield, CT

provided by: 
Originally published at Internet.com


This article was contributed by Tair Abdurman.

This article illustrates how to create and use Statically linked Non-MFC (Implicit) DLLs. In order to build applications using DLLs in this way you must have .dll distribution with .lib & .h files. Lemme create DLL which can export whole class with method and variable and global variable with global procedure. I call this as HookWorks because have used this code to window's hook, and leave without changes. To start from 0, select New->Project->Win32 DLL. Select empty project and click finish (no need to help from wizards! ;). First going to planning our exports and declare them in //**************HWMain.h file***************** //HWMain.h Non-MFC DLL header file //sure it will be included only once #ifndef _ATM_HWMAIN_H_ #define _ATM_HWMAIN_H_ #pragma once //to speedup & reduce size #define VC_EXTRALEAN //Header body You can use .DEF file if wanna to use ordinal exports, but here I use exports by names. Create some usefull macros //export macros #define DLL_EXPORT __declspec(dllexport) //import macro #define DLL_IMPORT __declspec(dllimport) After completing your DLL, you can use DUMPBIN [options] files to view export table of DLL. // ... #include //to export for C++ & C #ifdef __cplusplus extern "C" { #endif Here, the class will be exported with all of its members. Now you only need to create a new instance of the object and all members will be accessable //class export, with all definitions class DLL_EXPORT CHookWorks { public: //blah blah method int HookWorksFunc(void); //blah blah variable int m_iHookWorks; //con and decon CHookWorks(); _1_CHookWorks(); }; Here is a variable which will be accesable as extern in your "client" //exported variable DLL_EXPORT int exp_iVar=99; this function will be directly accessable //exported function DLL_EXPORT BOOL ExportedFunc(BOOL bParam); copmleted ... only close this "language unconveniences". #ifdef __cplusplus } #endif //EOF Header body #endif //*******************HWMain.h file********************** implementation is too simple with some explains: //*******************HWMain.cpp file******************** #include "HWMain.h" //Regular DLL Entry Point, do not have any importancy //to me here BOOL WINAPI DllMain(HINSTANCE hinstDLL, // DLL module handle DWORD fdwReason, // for calling function LPVOID lpvReserved // reserved ) { switch(fdwReason) { case DLL_PROCESS_ATTACH: /* Indicates that the DLL is being loaded into the virtual address space of the current process as a result of the process starting up or as a result of a call to LoadLibrary.DLLs can use this opportunity to initialize any instance data or to use the TlsAlloc function to allocate a Thread Local Storage (TLS) index.*/ break; case DLL_THREAD_ATTACH: /* Indicates that the current process is creating a new thread.When this occurs, the system calls the entry-point function of all DLLs currently attached to the process. The call is made in the context of the new thread. DLLs can use this opportunity to initialize a TLS slot for the thread. A thread calling the DLL entry-point function with DLL_PROCESS_ATTACH does not call the DLL entry-point function with DLL_THREAD_ATTACH. Note that a DLL's entry-point function is called with this value only by threads created after the DLL is loaded by the process. When a DLL is loaded using LoadLibrary, existing threads do not call the entry-point function of the newly loaded DLL.*/ break; case DLL_THREAD_DETACH: /* Indicates that a thread is exiting cleanly. If the DLL has stored a pointer too allocated memory in a TLS slot, it uses this opportunity to free the memory. The system calls the entry-point function of all currently loaded DLLs with this value. The call is made in the context of the exiting thread.*/ break; case DLL_PROCESS_DETACH: /* Indicates that the DLL is being unloaded from the virtual address space of the calling process as a result of either a process exit or a call to FreeLibrary. The DLL can use this opportunity to call the TlsFree function to free any TLS indices allocated by using TlsAlloc and to free any thread local data.*/ break; default: break; } return TRUE; } //class export, with all definitions //member method int CHookWorks::HookWorksFunc() { m_iHookWorks=10; return 2; } //constructor CHookWorks::CHookWorks() { m_iHookWorks=1; } //destructor CHookWorks::_1_CHookWorks() { } //exported function declaration DLL_EXPORT BOOL ExportedFunc(BOOL bParam) { return bParam; } //*******************HWMain.cpp file******************** Yep. It's ready. Simply compile after checking that you don't want MFC support (in the Linker settings). After building the project, you will 3 files that you need to distribute: * DEBUG build * HookWorks.dll * HookWorks.lib * HWMain.h * RELEASE build * HookWorks.dll * HookWorks.lib * HWMain.h The DLL must be stored in the same folder as the client application or in system DLL paths in order for it to be accessable from the client. If the client application can't find the DLL, you will receive an error message...

Read article at Internet.com site

Featured Local Company

Media Lantern Inc,

(800) 705-1213
236 State Street
New London, CT

Regional Articles
- Creating statically linked, non-MFC DLLs Ansonia CT
- Creating statically linked, non-MFC DLLs Bethel CT
- Creating statically linked, non-MFC DLLs Bloomfield CT
- Creating statically linked, non-MFC DLLs Branford CT
- Creating statically linked, non-MFC DLLs Bridgeport CT
- Creating statically linked, non-MFC DLLs Bristol CT
- Creating statically linked, non-MFC DLLs Cheshire CT
- Creating statically linked, non-MFC DLLs Danbury CT
- Creating statically linked, non-MFC DLLs Darien CT
- Creating statically linked, non-MFC DLLs East Hartford CT
- Creating statically linked, non-MFC DLLs East Haven CT
- Creating statically linked, non-MFC DLLs Enfield CT
- Creating statically linked, non-MFC DLLs Glastonbury CT
- Creating statically linked, non-MFC DLLs Greenwich CT
- Creating statically linked, non-MFC DLLs Groton CT
- Creating statically linked, non-MFC DLLs Guilford CT
- Creating statically linked, non-MFC DLLs Hamden CT
- Creating statically linked, non-MFC DLLs Hartford CT
- Creating statically linked, non-MFC DLLs Manchester CT
- Creating statically linked, non-MFC DLLs Meriden CT
- Creating statically linked, non-MFC DLLs Middletown CT
- Creating statically linked, non-MFC DLLs Milford CT
- Creating statically linked, non-MFC DLLs Naugatuck CT
- Creating statically linked, non-MFC DLLs New Britain CT
- Creating statically linked, non-MFC DLLs New Canaan CT
- Creating statically linked, non-MFC DLLs New Haven CT
- Creating statically linked, non-MFC DLLs New London CT
- Creating statically linked, non-MFC DLLs Newington CT
- Creating statically linked, non-MFC DLLs North Haven CT
- Creating statically linked, non-MFC DLLs Norwalk CT
- Creating statically linked, non-MFC DLLs Norwich CT
- Creating statically linked, non-MFC DLLs Plainville CT
- Creating statically linked, non-MFC DLLs Ridgefield CT
- Creating statically linked, non-MFC DLLs Rocky Hill CT
- Creating statically linked, non-MFC DLLs Shelton CT
- Creating statically linked, non-MFC DLLs Simsbury CT
- Creating statically linked, non-MFC DLLs South Windsor CT
- Creating statically linked, non-MFC DLLs Southbury CT
- Creating statically linked, non-MFC DLLs Southington CT
- Creating statically linked, non-MFC DLLs Stamford CT
- Creating statically linked, non-MFC DLLs Storrs Mansfield CT
- Creating statically linked, non-MFC DLLs Stratford CT
- Creating statically linked, non-MFC DLLs Torrington CT
- Creating statically linked, non-MFC DLLs Trumbull CT
- Creating statically linked, non-MFC DLLs Vernon Rockville CT
- Creating statically linked, non-MFC DLLs Wallingford CT
- Creating statically linked, non-MFC DLLs Waterbury CT
- Creating statically linked, non-MFC DLLs West Hartford CT
- Creating statically linked, non-MFC DLLs West Haven CT
- Creating statically linked, non-MFC DLLs Westport CT
- Creating statically linked, non-MFC DLLs Wethersfield CT
- Creating statically linked, non-MFC DLLs Willimantic CT
- Creating statically linked, non-MFC DLLs Wilton CT
- Creating statically linked, non-MFC DLLs Windsor CT
- Creating statically linked, non-MFC DLLs Winsted CT
- Creating statically linked, non-MFC DLLs Wolcott CT
Related Local Events
NET Series: Lunch Bunch
Dates: 1/5/2010 - 1/5/2010
Location: Maneeley's Banquet Facility & Catering
South Windsor, CT
View Details

The New Balancing Act
Dates: 11/5/2009 - 11/5/2009
Location: Acton Public Library
Old Saybrook, CT
View Details

The New Balancing Act
Dates: 11/3/2009 - 11/3/2009
Location: Estuary Council of Seniors
Old Saybrook, CT
View Details

Topics: 
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML