So, here we go...how to write a DLL in C++ syntax? Thanks for your
tolerance!
A good place to ask would be
news://comp.os.ms-windows.programer.win32 since this newsgroup deals
with the Standard C++ Language only. And Dll's are not part of the
language but rather an extension of the specific OS your are using
(Windows).
hth
--
jb
(replace y with x to reply)
Typo
news:comp.os.ms-windows.programmer.win32
john
What you'll have to do is not that much:
1) create (notepad) a yourdll.cpp file with the following code:
<begin code>
#include <windows.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;
}
<end code>
2 open it in MS Visual Studio, try to build it, VS will create a project for
you.
3 add all the existing C++ code to the project, build it again.
4 open a command prompt in the directory where the intermediate files are
build and type 'dumpbin /symbols *.obj > dumpbin.txt' or replace the * by a
specific file name.
6 create a yourdll.def with the following skeleton:
<begin code>
; yourdll.def : Declares the module parameters for the DLL.
LIBRARY "yourdll"
DESCRIPTION 'yourdll Windows Dynamic Link Library'
EXPORTS
; Explicit exports can go here
<end code>
5 open the dumpbin.txt and use find to find the function you want to export,
this function will be between parentheses. Copy the cryptic string to the
left (called decorated name) and place it in the def file below '; Explicit
exports can go here' followed by a tab and a @1
repeat this for all the functions you want to export and increase the
following number (@2 etcetera).
6 add the def file to the project and recompile.
That's it, you can now use the created .lib file in your other projects and
the dll will be linked
Corno
"Alex" <AlexJ...@spam.no> wrote in message
news:26CO8.42615$UT.28...@bgtnsc05-news.ops.worldnet.att.net...
class __declspec(dllexport) CFoo
{
};
Create a new project as Win32 Dynamic link library and add your c++ files
and create the dll.
now u can construct an object of class CFoo in your driver(main) program .
Dont forget to copy the .lib file
regards,
Shabeer
These links might be interesting:
http://www.codeguru.com/mfc/comments/1156.shtml
http://www.gamedev.net/reference/articles/article928.asp
"Alex" <AlexJ...@spam.no> wrote in message
news:26CO8.42615$UT.28...@bgtnsc05-news.ops.worldnet.att.net...
That's the other way around...sorry my mistake.
The CodeGuru comment is for a CodeGuru artricle which is also informative.
See:
http://www.codeguru.com/dll/expclass.shtml
"Ferdi Smit" <sm...@xs4all.nl> wrote in message
news:aeficm$6vu$1...@news1.xs4all.nl...
There is no good reason I am aware of not to use the AppWizard to generate a
project instead of creating it using the automatic method you describe.
I am not sure whether a C++ program can call a member function in a DLL but
it is definitely not possible for a non-C++ program to call a non-static
member function in a DLL. Therefore it is essentailly not useful to export a
decorated name in the manner you describe. It is much more practical to
simply make all functions to be exported C functions, not C++ functions that
get decorated.
"Corno Schraverus" <corno@%spam%.dds.nl> wrote in message
news:aeeuc5$dji$1...@news.tudelft.nl...
"josh" <jo...@xtreme.net> wrote in message
news:1105_1024149369@l2092in-wllka-2...
"Corno Schraverus" <corno@%spam%.dds.nl> wrote in message
news:aeeuc5$dji$1...@news.tudelft.nl...
"josh" <jo...@xtreme.net> wrote in message
news:1104_1024164757@l2092in-wllka-2...
Corno
> I am not sure whether a C++ program can call a member function in a DLL
but
> it is definitely not possible for a non-C++ program to call a non-static
> member function in a DLL. Therefore it is essentailly not useful to export
a
> decorated name in the manner you describe. It is much more practical to
> simply make all functions to be exported C functions, not C++ functions
that
> get decorated.
C++ can call member functions but you are right about the rest.
Corno
At the same time, using _declspec has performance advantages
(besides eliminating another piece - .def file - from your
configuration.) It is definitely a preferred way of exporting
stuff.
Calling DLL Functions from Visual Basic Applications
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HT
ML/_core_calling_dll_functions_from_visual_basic_applications.asp
I guess the main reason I only use C functions is because there is no need
for C++ functions since it is not possible to call a (non-static) member
function from programs that are not written in C++. Perhaps it is possible
but it is dangerous and I think most C++ programmers would not try to.
"josh" <jo...@xtreme.net> wrote in message
news:1105_1024182683@l2092in-wllka-2...