VC++ .NET 2002: Which Wizard/Template to Use to Get a Regular DLL and a non-MFC DLL of native C++ pr

G

Guest

Hi all
(1) In MSDN, there are lots of technical information about VC++ 6.0 programming of Regular DLLs, Extension DLLs and non-MFC DLLs, and some technical articles about mixed MC++ and native C++ DLLs. I did not see the technical information about getting a regular DLL and a non-MFC DLL of native C++ programming in VC++ .NET 2002 (VC++ 7.0). I just have VC++ .NET 2002 (VC++ 7.0) in my Windows XP Pro PC to catch up the VC++ 6.0 DLL programming before I go into the mixed MC++ and native C++ DLLs. I have tried to use the "NEW Project" Template of Managed C++ Empty Project to do a simple regular DLL (without .def file) to do the DLL's CWinApp object's InitInstance and ExitInstance without any success (because #include <stdafx.h> is not available in the Template of Managed C++ Empty Project) and I was informed that I should go to the "New Project" Win32 Project, and then go to DLL. But the New Project" Win32 Project has its built files of the .cpp, .h, etc. including the #include "stdafx.h" file - it throws me out completely here and I do not know how to get the regular DLL I want.
(2) I have difficulties in finding a right "New Project" Template to start the non-MFC DLL in VC++ .NET 2002 (VC++ 7.0) that has the following Templates for Visual C++ Projects: ATL Project, ATL Server Project, ATL Server Web Service, Makefile Project, Managed C++ Application, Managed C++ Class Library, Managed C++ Empty Project, Managed C++ Web Service, MFC ActiveX Control, MFC DLL and Win32 Project.
Please help and tell me which Template of Visual C++ Projects of Visual C++ .NET 2002 to use to get a regular DLL/non-MFC DLL (no .def file) programming started. If I have to use the Template of Managed C++ Empty Project or Win32 Project to get the DLL I want, please tell me how to set the "Properties" of C/C++, etc. and how to modify the .h and resource files

Thanks in advance
Scott Chang
 
S

Sin

(1) In MSDN, there are lots of technical information about VC++ 6.0
programming of Regular DLLs, Extension DLLs and non-MFC DLLs, and some
technical articles about mixed MC++ and native C++ DLLs. I did not see the
technical information about getting a regular DLL and a non-MFC DLL of
native C++ programming in VC++ .NET 2002 (VC++ 7.0). I just have VC++ .NET
2002 (VC++ 7.0) in my Windows XP Pro PC to catch up the VC++ 6.0 DLL
programming before I go into the mixed MC++ and native C++ DLLs. I have
tried to use the "NEW Project" Template of Managed C++ Empty Project to do a
simple regular DLL (without .def file) to do the DLL's CWinApp object's
InitInstance and ExitInstance without any success (because #include
<stdafx.h> is not available in the Template of Managed C++ Empty Project)
and I was informed that I should go to the "New Project" Win32 Project, and
then go to DLL. But the New Project" Win32 Project has its built files of
the .cpp, .h, etc. including the #include "stdafx.h" file - it throws me out
completely here and I do not know how to get the regular DLL I want.
(2) I have difficulties in finding a right "New Project" Template to start
the non-MFC DLL in VC++ .NET 2002 (VC++ 7.0) that has the following
Templates for Visual C++ Projects: ATL Project, ATL Server Project, ATL
Server Web Service, Makefile Project, Managed C++ Application, Managed C++
Class Library, Managed C++ Empty Project, Managed C++ Web Service, MFC
ActiveX Control, MFC DLL and Win32 Project.
Please help and tell me which Template of Visual C++ Projects of Visual
C++ .NET 2002 to use to get a regular DLL/non-MFC DLL (no .def file)
programming started. If I have to use the Template of Managed C++ Empty
Project or Win32 Project to get the DLL I want, please tell me how to set
the "Properties" of C/C++, etc. and how to modify the .h and resource files.



Arrrgg... Not sure I understood all of that but anyways... Here are a couple
of clarifications, I hope the answer to your pile of characters lies in
there :

- stdafx.h/cpp is for precompiled headers. AFAIK all C/C++ projects can
choose to use it or not and most if not all templates include it by default.
I personally chose NOT to use them and scrap those files as well as the
precompiled header option when I do use a template. BTW stdafx has nothing
to do with MFC or managed code.. There seems to be some confusion about this
in your mail... It's strictly related to precompiled headers which can by
used in any type of C/C++ project AFAIK.

- Managed vs Unmanaged : Win32 projects, be them DLL or EXE, are unmanaged
by default. You CAN make them managed by changing project options once the
template is built. I haven't really gone any further than that so I can't
comment on actually calling Win32 API calls from managed code, but I suppose
there's a bit of pain involved there.

- When generating a Win32 project, you can choose to build an empty project.
This is what I usually do myself. Just add a .DEF for DLL exports and make
sure you're set to stdcall if you want an API-style DLL and you're in
business. Just add a blank cpp in there, #include <windows.h> and you're
off.

BTW: If you're migrating VC6 code to .NET there's absolutly no problem
there. I did it on a LARGE suite of software and it was under control in a
couple of hours. Just open the VC6 project or workspace file in .NET and
it'll create a vcproj file and solution automatically. Just click compile
and you shouldn't have anything more to do.

As mentionned before, to create new VC6 style projects, just stick to Win32
either with the template or blanks and you should be ok.

Alex.
 
G

Guest

Hi Alex. Thanks for your response.

Your responses are general and do not solve my particlar problems completely. Please have a look at 'VC++ .NET 2002: Error C1803 in creation of a simple regular DLL' that had the VC++ .NET source code I posted on 3/17/2004, then you will understand what kind of answers I am looking for. Please help me again. Your help would be greatly appreciated

Scott Chang
 
B

Bronek Kozicki


Hi Scott


I have a feeling that you do not quite understand what "regular DLL" is.
It's a single executable file compiled to machine code (not MSIL, ie.
not .NET assembly - just old-fashioned Win32 executable) exporting
C-style functions, that can be called from other DLL-s or programs, but
cannot be started in own process (like .exe executables). It's also
called "dynamic library", as it's just a library of functions which can
be dynamically loaded into memory by other programs. Prior to this use
such DLL file must be loaded into memory of host process, and when it's
no longer needed it might be unloaded. When DLL file is loaded or
unloaded to/from memory of process (host, ie. the one using your dynamic
library), function DllMain contained within this DLL is called to notify
your code to prepare for work or do final cleanup. It's also called when
process hosting your DLL starts new threads or terminates them. There
are some restrictions on what can be called from within DllMain - most
notably you may not create new threads. Thanks to recent additions to
Visual C++ it's also possible to export variables or C++ classes from
DLL, as you will see later on. Do not use these it if you want to make
your DLL usable from other compilers, though.

Let me first show you how to make "regular DLL". Start Visual Studio
..NET (I'm talking about version 2002, aka 7.0), select menu File > New >
Project... . Select "Visual C++ Project" on the left pane and then
"Win32 Project" on right one (last icon, at least on my computer). Name
your project (your .dll file will use this name - make is short and
without special characters) and click OK. "Win32 Application Wizard -
your_name" appears, but do not close it yet! Click on "Application
Settings" on the left side of the wizard window. Now you can see
"Application type" option - default one is "Windows application". Change
it to "DLL". If you press "Finish" now, you will get what you are
looking for: project for regular Win32 dynamic library, aka "regular
DLL". Before you click OK you have two options, NONE of them is related
to MFC or Managed C++:

* "Empty project" means that wizard will not create any source file
(like .c, .cpp or .h) for your project - you need to manually create
these files in your project. It also means that wizard will not create
precompiled header and will setup your project not to use it (I will
explain later what's "precompiler header"). If you leave this option
unchecked, wizard will setup your project to use precompiled header and
create few source files:
stdafx.cpp - it's used to compile precompiled header (you compile it
whenever you change project settings or content of stdafx.h)
your_name.cpp - here you can put functions you are going to export
from your DLL. Currently it contains only DllMain function. You can
read more about this function in MSDN. If your code do not need to do
anything on startup (when loaded into memory, just before any of its
functions is called) or cleanup (just before being unloaded from memory)
you may leave this function as it is. I advice that you look for more
information here :
http://msdn.microsoft.com/library/en-us/dllproc/base/dynamic_link_library_entry_point_function.asp

stdafx.h - here you may include all headers you are going to put in
precompiled header. By default there's only <windows.h>. I usually
include there number of standard C++ headers, like:
#include <string>
#include <vector>
#include <algorithm>
#include <memory>
(because I use standard C++ library in my C++ code quite often), but you
may leave it as it is, or put any other common (ie. ones you are going
to include from all .cpp files in your project) includes. If you are
using precompiled header, make sure all .cpp files start with
#include "stdafx.h"
This will effectively include to your .cpp file all files included in
stdafx.h, there is performance gain however - all these headers has been
processed once, when you compiled stdafx.cpp. As a result all .cpp files
which included "stdafx.h" header will compile faster, thus saving your
(developer) time. This is the sole purpose of precompiled header - as
you can see, it has nothing to do with MFC. Of course MFC projects do
use stdafx.h for own purposes, as you can - without all burden of MFC.
Just remember that whatever you put into this file will be processed by
all .cpp files (technicaly it should be called "translation units", not
".cpp files") and anytime you change it, you need to recompile
stdafx.cpp
You should consider adding version resource to your project. Select
menu Project > Add Resource, in "Add Resource" dialog select "Version"
(last one) and press "New" - version info will appear, here you can put
some info about your DLL - like version number, full project name and
your copyright.

* If you do not check "Empty project", you may check "Export symbols".
This will result in slightly longer your_name.cpp file and new file
named your_name.h.
your_name.h - this file is designed to contain declarations of all
entities you are exporting from your DLL library. It also contains
example of definition of simple class, declaration of variable and
declaration of function - all exported from your DLL. I suggest that you
comment out everything below #endif preprocessor directive and use it
later only for reference. This file is designed to accompany your DLL
file when you want others to see declarations of exported functions (or
classes) - it will allow them to call them safely. It's specific to
Visual C++ - other compilers might not understand "__declspec" keyword.
If someone with different compiler is going to use your DLL, he/she will
probably need to manually adjust this header file.
your_name.cpp - this file now contains little longer DllMain and
definitions of entities declared in your_name.h - namely body of
constructor of sample class, definition of variable and body of sample
function. If you commented out in your_name.h everything below #endif,
you also need to comment out in this file everything below DllMain.

Please note that there's no .def file - it's no longer required in
Visual Studio .NET . Instead you put "__declspec(dllexport)" before
declaration or definition of entities (functions, classes, variables)
are going to export from you DLL file. If you do not use it, users of
your dynamic library will not see these entities. BTW: If you are going
to use this DLL from other compilers than Visual C++, do not export
anything other than functions, and make sure you follow this advice: you
also need to put:
extern "C"
prior to function definition (and declaration - together with
"__declspec(dllexport)"). Otherwise users of your library will see
mangled name of your function instead of expected name. As mangling is
specific to compiler, users of other compilers will not be able to find
your function using name you provided.

Here is sample implementation file of your library - you may use it in
place of of your_name.cpp if you did not checked "Export symbols" (or if
you checked it but commented out parts of your_name.h and your_name.cpp,
as advised above).

#include "stdafx.h"
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID
lpReserved)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
; // 1 - init code here
else if (ul_reason_for_call == DLL_PROCESS_DETACH)
; // 2 - cleanup code here
return TRUE;
}

extern "C" __declspec(dllexport) int Add(int a, int b)
{
return a + b;
}

You may use it also in "Empty project", but please change first line
from:
#include "stdafx.h"
to:
#include <windows.h>
as "empty project" is set not to use precompiled header.

If you define function is .c file (ie. you write it in C, not in C++) do
not use
extern "C"

I hope now you get the basics. Regards


B.
 
G

Guest

Hi Alex
I followed your advice and started a new program "MC++EmptyProjVGDLL" from the Empty Project of Managed C++ Project
////----VGDLLsin.cpp----///
#include <windows.h
#include "SourceFile.h

class CDllApp : public CWinAp

public
CDllApp::CDllApp(

Calc (1,2)

DECLARE_MESSAGE_MAP(
}
BEGIN_MESSAGE_MAP(CDllApp,CWinApp
END_MESSAGE_MAP(
CDllApp DllObject
////----SourceFile.h----///
extern "C" _declspec(dllexport) int Calc(char no1,char no2

char result
result = no1 + no2
return result

////////////////////////////////
I did "Build" on the MC++EmptyProjVGDLL project in my Microsoft Visual C++ .NET 2002 - Windows XP Pro PC
and I got the following errors
error C2504: 'CwinApp': base class undefine
error C2143: syntax error: missing ';' before '}
warning C4183: 'DECLARE_MESSAGE_MAP': missing return type; assume to be a member function returning 'int
error C2061: syntax error: identifier 'CWindApp
error C2146: syntax error: missing ';' before identifier 'END_MESSAGE_MAP
error C2146: syntax error: missing ';' before identifier 'CDllApp'
Please help and tell me what is wrong in my source code and how to correct the problem
Thanks in advance
Scott Chan
************************************************************************
P. S. The above code is my first 'regular DLL' of VC++ .NET 2002 program and I tried to learn it from the followin
material of a published tutorial article

Introductio
This article shows a step by step technique to create your first DLL with VC++

Steps to create your first DL
Create a Win32 Dynamic Link Library project and add a .cpp & a .h file.
In the .cpp file, create a class instantiated from the CWinApp file.
# include <stdafx.h
# include "SourceFile.h

class CDllApp : public CWinAp

public

CDllApp::CDllApp(

Calc(0,0)


DECLARE_MESSAGE_MAP(
}

BEGIN_MESSAGE_MAP(CDllApp,CWinApp

END_MESSAGE_MAP(

CDllApp DllObject
In the .h file (Here it is SourceFile.h) define the functions to be used. Also specify the "dllexport" value for the _declspec function. extern "C" _declspec(dllexport) int Calc(char no1,char no2

char result
result = no1 + no2
return result

Then Compile the Dll.
Then Create a normal Win32 Application with a .cpp file & a .h file.
In the .h file, ( Here it is AppHeader.h )declare the function with the dllimport value of _declspec extern "C" _declspec(dllimport) Calc(int FirstValue
int SecondValue)
In the .cpp file, use the function. # include "AFXWIN.H
# include "AppHeader.h

class MainFrame : public CFrameWn

public

MainFrame(

Create(0,"Trial")


void OnLButtonDown(UINT nFlags,CPoint point

int res
char str[5]
res = Calc(998,226)
sprintf(str,"%d",res)
MessageBox(str)


DECLARE_MESSAGE_MAP(
}
In the Link tab of the "Project->Settings" Dialog, Go to the Text Box labeled "Object / Library Modules" and specify the path of the Dll File. Then copy the compiled dll file to your current app path directory and run the program.
Some things to not
The DLL file may not be visible due to the File View Options in the Windows folder. So, U can either go to the DOS Prompt and copy the file or enable the setting "Show all files" in Windows explorer to copy the file. To Create a DLL that uses MFC, See the following example. Note that extern "C" has not been used and the macro AFX_MANAGE_STATE(AfxGetStaticModuleState()); has been used to implement MFC.

_declspec(dllexport)CString Display(CString a,CString b

AFX_MANAGE_STATE(AfxGetStaticModuleState())
CString Str
Str = a + b
return Str
 
B

Bronek Kozicki

class CDllApp : public CWinApp

it's MFC DLL, not "regular" one
class CDllApp : public CWinApp

it's another MFC DLL, not "regular" one. Plain dynamic library do not
require such special code, like deriving own class from CWinApp or ....
BEGIN_MESSAGE_MAP(CDllApp,CWinApp)

.... defining message maps.

See my previous message in this thread for instruction on how to create
plain Win32 dynamic library (ie. "regular DLL"). Regards


B.
 
B

Bronek Kozicki


Hi Scott


I have a feeling that you do not quite understand what "regular DLL" is.
It's a single executable file compiled to machine code (not MSIL, ie.
not .NET assembly - just old-fashioned Win32 executable) exporting
C-style functions, which can be called from other DLL-s or programs, but
cannot be started in own process (like .exe executables). It's also
called "dynamic library", as it's just a library of functions which can
be dynamically loaded into memory by other programs and then called.
Prior to this use such DLL file must be loaded into memory by host
process, and when it's no longer needed it might be unloaded. When DLL
file is loaded to or unloaded from memory by host process, function
DllMain contained within this DLL is called to notify
your code to prepare for work or do final cleanup. It's also called when
process hosting your DLL starts new threads or terminates them. There
are some restrictions on what can be called from within DllMain - most
notably you may not create new threads. Thanks to recent additions to
Visual C++ it's also possible to export variables or C++ classes from
DLL, as you will see later on. Do not use these features if you want to
make your DLL usable from other compilers or other programming
languages, though. Please also note that I did not use words "MFC" or
"Managed C++" above - as those are NOT plain dynamic libraries!

Let me first show you how to make "regular DLL". Start Visual Studio
..NET (I'm talking about version 2002, aka 7.0), select menu File > New >
Project... . Select "Visual C++ Project" on the left pane and then
"Win32 Project" on right one (last icon, at least on my computer). Name
your project (your .dll file will use this name - make is short and
without special characters) and click OK. "Win32 Application Wizard -
your_name" appears, but do not close it yet! Click on "Application
Settings" on the left side of the wizard window. Now you can see
"Application type" option - default one is "Windows application". Change
it to "DLL". If you press "Finish" now, you will get what you are
looking for: project for plain Win32 dynamic library, aka "regular
DLL". Before you click OK you have two options, NONE of them is related
to MFC or Managed C++:

* "Empty project" means that wizard will not create any source file
(like .c, .cpp or .h) for your project - you need to manually create
these files in your project. It also means that wizard will not create
precompiled header and will setup your project not to use it (I will
explain later what's "precompiler header"). If you leave this option
unchecked, wizard will setup your project to use precompiled header and
create few source files:
stdafx.cpp - it's used to compile precompiled header (you compile it
whenever you change project settings or content of stdafx.h)
your_name.cpp - here you can put functions you are going to export
from your DLL, but there's nothing special about this file. Currently it
contains only DllMain function. You can read more about this function
in MSDN. If your code do not need to do anything on startup (when loaded
into memory, just before any of its functions is called) or cleanup
(just before being unloaded from memory) you may leave this function as
it is. I advice that you look for more information here:
http://msdn.microsoft.com/library/en-us/dllproc/base/dynamic_link_library_entry_point_function.asp

stdafx.h - here you may include all headers you are going to put in
precompiled header. By default there's only <windows.h>. I usually
include there number of standard C++ headers, like:
#include <string>
#include <vector>
#include <algorithm>
#include <memory>
#include <sstream>
(because I use standard C++ library in my code quite often), but you
may leave it as it is, or put any other common includes (ie. ones you
are going to include from all .cpp files in your project). Make sure all
your .cpp files start with:
#include "stdafx.h"
This will indirectly include to your .cpp files all files included in
stdafx.h. There is performance gain however - all these headers has been
processed once, when you compiled stdafx.cpp. As a result all .cpp files
which included "stdafx.h" header will compile faster, thus saving your
(developer) time. This is the sole purpose of precompiled header - as
you can see, it has nothing to do with MFC. Of course MFC projects do
use stdafx.h for own purposes, as you can - without all burden of MFC.
Just remember that whatever you put into stdafx.h will be included by
all .cpp files (technically it's called "translation units", not ".cpp
files") and anytime you change it, you need to recompile stdafx.cpp

* If you do not check "Empty project", you may check "Export symbols".
This will result in slightly longer your_name.cpp file and new file
named your_name.h.
your_name.h - this file is intended to contain declarations of all
entities you are exporting from your DLL library. It also contains
sample definition of simple class, declaration of variable and
declaration of function - all exported from your DLL. I suggest that you
comment out everything below #endif preprocessor directive and use it
later only for reference. This file is designed to accompany your DLL
file when you want others to see declarations of exported functions (or
classes or variables) - it will help them to use your DLL properly. It's
specific to Visual C++ - other compilers might not understand
"__declspec" keyword. If someone with different compiler is going to use
your DLL, he/she will probably need to manually adjust this header file.
your_name.cpp - this file now contains little longer DllMain and
definitions of entities declared in your_name.h - namely body of
constructor of sample class, definition of variable and body of sample
function. If you commented out in your_name.h everything below #endif,
you also need to comment out in this file everything below DllMain.

Please note that there's no .def file - it's no longer required in
Visual Studio .NET . Instead you put "__declspec(dllexport)" before
declaration or definition of entities (functions, classes, variables)
you are going to export from DLL. If you do not use it, users of your
dynamic library will not see these entities (but you can still use .def
file for required effect). BTW: If you are going to use this DLL from
other compilers than Visual C++ or programs compiled in other languages
(like Delphi or .NET), do not export anything else but functions, and
make sure you put:
extern "C"
prior to function definition (and declaration), just before
"__declspec(dllexport)" if your function is defined in .cpp file (ie. is
written in C++, not C). Otherwise users of your library will see mangled
name of your function instead of expected name. As mangling is specific
to compiler, users of other compilers will not be able to find your
function using name you provided, also GetProcAddress won't be able to
find your exported function.

Here is sample implementation file of dynamic library - you may use it
in place of of your_name.cpp if you did not checked "Export symbols" (or
if you checked it but commented out parts of your_name.h and
your_name.cpp, as advised above).

#include "stdafx.h"
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hModule);
; // your initialization code goes here
}
else if (reason == DLL_PROCESS_DETACH)
{
; // your cleanup code goes here
}

return TRUE;
}

extern "C" __declspec(dllexport) int Add(int a, int b)
{
return a + b;
}

You may also use it in "Empty project", but please change first line
from:
#include "stdafx.h"
to:
#include <windows.h>
as "empty project" by default is set not to use precompiled header.

If you define exported function inside .c file (ie. you write it in C,
not in C++ programming language) do not use extern "C"

You should consider adding version resource to your project. Select
menu Project > Add Resource, in "Add Resource" dialog select "Version"
(last one) and press "New" - version info will appear. Here you can put
some information about your DLL - like version number, full project name
and copyright.

Another thing you should take care of is to select right runtime version
- by default its static, but if you want to return pointers from
functions exported in your DLL and allow your users to free these
pointers, you need to use dynamic runtime instead. Click on your project
in one of windows "Solution Explorer", "Class View" or "Resource View"
then select Properties from right-click menu. You will see project
properties window. On the left pane select "C/C++" (you need to have at
least one .c or .cpp file in your project, otherwise you won't see this
option there), then "Code Generation" below. Now you need to change
Runtime Library on the right pane - in Debug configuration it should be
"Multi-threaded Debug DLL (/MDd)" (by default it's "Multi-threaded Debug
(/MTd)"); in Release configuration it should be "Multi-threaded DLL
(/MD)" (by default it's "Multi-threaded (/MT)"). Make sure you change
both configurations - Debug and Relase! You will also need to distribute
your DLL file together with runtime libraries: msvcr70.dll and
msvcp70.dll (together with Release version of your DLL) or msvcr70d.dll
and msvcp70d.dll (together with Debug version of your DLL). These files
have nothing to do with MFC - you are not using it! It's just Microsoft
C and C++ runtime library for Visual C++ 7.0 . Good news is that you do
not always need to redistribute these files (as many users already have
them) and thanks to use of dynamic runtime your own DLL will be smaller.
If you want to use static runtime library (and not to worry about
distribution of DLLs stated above) there's nothing wrong, just make sure
that functions exported from your DLL do not allow your users to free
any kind of resources you are allocating. Otherwise they will experience
all kinds of strange errors. These errors will also happen if you are
using dynamic runtime, but your users are using different dynamic
runtime or static runtime. It's best not to allow your users to free any
resources allocated by your dynamic library - if you follow this advice,
you do not need to worry about runtime version your DLL is using.

I hope you get the basics now. Good luck and best regards!


B.


PS. it's updated version
 
G

Guest

Hi Bronek, Thank you very very much for your respsones that help me greatly
1) I missed the "Application Settings" on the left side of the "Win32 Application Wizard" completely before and so I did not get to change "Window application" to "DLL" on the Application type.
2) After I read your statement about "DllMain", I tried to run the attached source code (of DllTest and DllTestApp - just saying "Hello C++!) that was a published tutorial for the exact DLL I want to experience. I did "Build" on Solution 'DllTest' (2 projects- DllTest and DllTestApp), and then I clicked the "! Start Without Debugging" button under the Debug menu. It threw out the following Dialog Box
DllTest - Executable for Debugging Sessio
Please specify the name of the executable file to be used for the debug sessio
Executable file name
|_________________|\/|
(There are three choices under this drop-down button
Internet Exeplore
ActiveX Control Test Containe
regsur 3

URL where the project can be accessed (ATL Session

I do not know how to proceed from here. I believe this set of source code for the 2-project DLL is a right material for me to do and to learn the regular DLL you want to enlighten me. Please comment on this matter and give me the necessary instructions to solve the problem, so I can go on to do more DLL programming of using a third library/utility in the OpenGL 1.1-GLUT 3.7 graphics
Thanks again
Scott Chan
////***Solution 'DllTest' (2 projects)***//
////***DllTest****//// ( First project
////-----DllTest.cpp----///
// DllTest.cpp : Defines the entry point for the DLL application
/

#include "stdafx.h
#include "DllTest.h

BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved

switch (ul_reason_for_call

case DLL_PROCESS_ATTACH
case DLL_THREAD_ATTACH
case DLL_THREAD_DETACH
case DLL_PROCESS_DETACH: break

return TRUE


void CDllTest::SayHello(

printf("Hello C++!")

////---StdAfx.cpp----///
// stdafx.cpp : source file that includes just the standard include
// DllTest.pch will be the pre-compiled heade
// stdafx.obj will contain the pre-compiled type informatio

#include "stdafx.h

// TODO: reference any additional headers you need in STDAFX.
// and not in this fil
////----DllTest.h----//
class __declspec(dllexport) CDllTes

public:
CDllTest(){
~CDllTest(){

public
void SayHello()
}
////----StdAfx.h----////
// stdafx.h : include file for standard system include files
// or project specific include files that are used frequently, bu
// are changed infrequentl
/

#if !defined(AFX_STDAFX_H__548DFEB0_F45C_49C6_A183_A99D163A2114__INCLUDED_
#define AFX_STDAFX_H__548DFEB0_F45C_49C6_A183_A99D163A2114__INCLUDED

#if _MSC_VER > 100
#pragma onc
#endif // _MSC_VER > 100

// Insert your headers her
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows header

#include <windows.h

#include <cstdio

//{{AFX_INSERT_LOCATION}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line

#endif // !defined(AFX_STDAFX_H__548DFEB0_F45C_49C6_A183_A99D163A2114__INCLUDED_
///***DllTestApp***/// (Second project
///----DllTestApp.cpp---//
// DllTestApp.cpp : Defines the entry point for the console application
/

#include "stdafx.h
#include "DllTest.h

int main(int argc, char* argv[]

CDllTest dt

dt.SayHello()

return 0

////----StdAfx.cpp---///
// stdafx.cpp : source file that includes just the standard include
// DllTestApp.pch will be the pre-compiled heade
// stdafx.obj will contain the pre-compiled type informatio

#include "stdafx.h

// TODO: reference any additional headers you need in STDAFX.
// and not in this fil
////----StdAfx.h----///
// stdafx.h : include file for standard system include files
// or project specific include files that are used frequently, bu
// are changed infrequentl
/

#if !defined(AFX_STDAFX_H__5A1F8A5B_8FB2_4C57_BE36_C4C9E0EF415E__INCLUDED_
#define AFX_STDAFX_H__5A1F8A5B_8FB2_4C57_BE36_C4C9E0EF415E__INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

#include <stdio.h>

// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__5A1F8A5B_8FB2_4C57_BE36_C4C9E0EF415E__INCLUDED_)
 
B

Bronek Kozicki

Hi Bronek, Thank you very very much for your respsones that help me greatly.
Please specify the name of the executable file to be used for the debug session
I do not know how to proceed from here. I believe this set of source code for
the 2-project DLL is a right material for me to do and to learn the regular DLL


Ok, here is short explanation. As I wrote before, DLL is a library - it
does not "run" by itself, or more precisely - it does not own process of
execution (neither console attached to process). You may not "just run"
it. What you can do is to load it into some other process (called
"host"), and then execute (from within host process) selected functions
exported from DLL. That's what for you have second project. Just click
on "DllTestApp" in Soluction Explorer window, and select (from
right-click menu) "Set as StartUp project". As this (second) project is
regular .exe, it will be started in own process, then load your DLL
(first project) and execute "SayHello" function in it.

And last advice: I suggest that you look for other tutorial. Good
tutorial should explain all this before actually showing some code. Also
good tutorial would not use console from within DLL, as DLL might not
have access to console. Last but not least, good tutorial would not
start with exporting class, as only few users of such DLL would be able
to make use of if. There are good uses for DLLs exporting classes (or
variables), but there are much more situations when exporting functions
alone is more appropriate.

Regards


B.
 
B

Bronek Kozicki

After reading your last response, I found that the author of that
tutorial provided two files "DllTest.dll" and "DllTest.lib" in the
folder.
How can I load them and execute "SayHello" function in it by
using VC++ .NET 2002 - Windows XP Pro? Hope to hear from you again.

You need to make new project, Window executable (command line, not DLL),
link to this lib and include provided header file (there should be some
..h file, too). In this project you just call functions exported from
DLL. Make sure DLL you are refereing to is copied to your application
directory or is in some directory listed in your PATH environment
variable.
Thanks again, Scott Chang P. S. I am also puzzling why my souce
code did not create the .dll and .lib files. Please address this
matter too.

Did you actually try to build your project?


B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top