 |
|
 |
Good article. Don't mind Rolf Schaeuble - he is insecure.
|
|
|
|
 |
|
 |
Hi there,
I'm fairly new to C++ and have been trying to follow this example after struggling on my own. But the problem I've got is I can't seem to get Visual Studio to create a .lib file, have you got any suggestions? Because without the .lib I can't link it into my projects... :S
Any help would be appreciate! Thanks
|
|
|
|
 |
|
 |
You will have do the following.
1. Right click on your project on solution explorer and click "Properties".
2. Expand the "Linker" item in the tree.
3. Click on "Input"
4. Type in the name of your def file in the case of this example it would be "EasyDll.def" in the text box beside "Module Definition File".
5. Selection "Release" from the configuration dropdown box at the top left and enter in "EasyDll.def" to make sure that you also are given a .lib file when you compile for release mode too.
Cheers,
Greg
|
|
|
|
 |
|
 |
thanks for this ...this is really good for new bie like me.....
|
|
|
|
 |
|
 |
is creating a DLL with public variables declaration enable it to hold the information for other applications to use ?
i wrote this code in VC++ and wanted to create a DLL from it for VB
this code enables byte data array share between functions , can it be a DLL and anable byte data array between applications ?
i wanna use it as a winsock emulator so i can debug client / server applications i write in VB
tnx in advance
here is the code , following main() to test it
#include
bool DataAvalibale_Flg;
bool BufferBusy_Flg;
unsigned char global_data [65536];
unsigned long global_data_size;
unsigned long global_address;
bool PutData (unsigned long intl_size,unsigned char data[],unsigned long l_address);
bool GetData (unsigned long *intl_size,unsigned char data[],unsigned long l_address);
void main ()
{
unsigned char local_data[3];
unsigned long l_size;
local_data[0] = 123;
local_data[1] = 222;
if (PutData( 2,local_data,1) == 1)
{
local_data[0] = 111;
local_data[1] = 111;
if (GetData (&l_size,local_data,1 ))
{
local_data[0] = 0;
}
}
}
bool PutData (unsigned long intl_size,unsigned char data[],unsigned long l_address)
{
bool l_status;
l_status = 0;
if(!BufferBusy_Flg)
{
BufferBusy_Flg = 1;
global_data_size = intl_size;
global_address = l_address;
memcpy(&global_data[0], &data[0],intl_size);
DataAvalibale_Flg = 1;
l_status = 1;
}
return l_status;
}
bool GetData (unsigned long *intl_size_ptr,unsigned char data[],unsigned long l_address)
{
bool l_status;
l_status = 0;
if((DataAvalibale_Flg)&&(l_address == global_address))
{
DataAvalibale_Flg = 0;
*(intl_size_ptr) = global_data_size;
memcpy(&data[0],&global_data[0],*(intl_size_ptr));
l_status = 1;
BufferBusy_Flg = 0;
}
return l_status;
}
|
|
|
|
 |
|
 |
v r final year students, v thought of doing project using DLL codings.plz give brief explanation about DLL coding & files and how to use this codings.
|
|
|
|
 |
|
 |
Maybe you are a beginner, but when a program is too big to be in only one file, ( one ".exe" file ) you must split the program into some parts. DLLs allow you to write really big programs. A DLL is another file ( ".dll" ) and could be programmed in any language, for example a dll created in C++ could be opened by a program writed in Pascal. And all the libraries in Windows are DLLs files, too;
Happy Programming
DgMv
|
|
|
|
 |
|
 |
This article is clear and easy to follow. It was perfect for this old unix hacker. I found nothing on the msdn site of use. Since the way dynamic libraries are built and used on unix are so different it was difficult for me to do simple things. The windows approach is convoluted and complex.
|
|
|
|
 |
|
 |
Hi Folks...
When I try to compile the "Super Easy DLL Project" I get the following error.
Compiling...
Easydll.cpp
c:\project\easydll\easydll.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/Easydll.pch': No such file or directory
Obviously in the directory debug/easydll there isn't any file with that name...
Is a Visual Studio setting issue?
Any help will be appreciated.
Thanks a lot.
|
|
|
|
 |
|
 |
The method you use has a few downsides that should be mentioned (especially in a beginners' article):
1) You cannot export objects this way, only functions. Lets say you create your own dynamic array class and want to put it in a library. Using the method described in this article is not for you (the MFC extended DLL method would be more useful)
2) By linking to the dll, you are making it a static dll. That is, the dll is loaded at when the program first starts (even if no features that use it have been loaded yet). So, if the dll does not exist or is in the wrong location, you will get an error message and will not be able to run the program until you get the DLL in the right place. Using the LoadLibrary/GetProcAddress functions allows you to run the program and attempt to load the libraries yourself so you can catch the errors and decide if the program can still be run (perhaps without the use of some features).
3) For many third-party DLLs (and even some system DLLs), you will not have access to the header files for them, so you will need to use the LoadLibrary/GetProcAddress method (so you should learn how to do that).
4) If you are creating your own DLLs and intend to do this, many times you would be better off creating a static library (which will compile to a .lib file and will link into whatever projects you need it in) instead. You will have dupilicate code if you use it in many projects, but you will also avoid what is affectionately known as "DLL HELL" should you need to revise the DLL.
"If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week"
|
|
|
|
 |
|
 |
Hmm? So why not just use teh wizard to create "A DLL that exports some symbols", using the "Win32 Dynamic-Link Library" wizard?
Bikram Singh
I believe we should all pay our tax with a smile. I tried - but they wanted cash.
|
|
|
|
 |
|
 |
Yes, as first for beginners you (Greg Ellis) should use the Visual studio wizards. They are a good base to learn.
As second I will say to you (Greg Ellis) that you use the basic C interface to a DLL. This is good way, if different implementation will use your DLL (Basic, Borland C, Microsoft C ...).
But if you only use DLL for your own modularisation, then you can use C++ exports which be more typesafe. For this I would say... see my first comment: Use Visual Studio Wizards.
|
|
|
|
 |
|
 |
Thanks for the article. I was interested in creating DLLs a few weeks ago and started surfing for articles that contained beginner information on the subject.
Still learning about DLLs and this article helps.
Mark
|
|
|
|
 |
|
 |
Is it a dynamic loading?
I think it is a static.
WHERE DLL?
|
|
|
|
 |
|
 |
When you add a .lib to your project it will be "static"... Meaning that your program will not start ifnot the dll exists. This is not the way for making "plugins" system, or as he described as "strange getprocaddress functions".
=====================
Lars [Large] Werner
lars@werner.no
http://lars.werner.no
=====================
|
|
|
|
 |
|
 |
I knew a Greg Ellis that went to Purdue about 5 years ago. Would you be him?
|
|
|
|
 |
|
|
 |
|
 |
I knew a Greg Ellis that used to be my dentist. Would you be him?
~Nitron.
ññòòïðïðB A start
|
|
|
|
 |
|
 |
HAHAHA,
Nope I'm not your old dentist, although I would like to have his pay check!
Cheers,
Greg
|
|
|
|
 |
|
 |
This article is ridiculous. This is absolutely basic knowledge for a Windows developer.
'nuff said.
- Rolf
P.S.: Next time, you could write an article about how to declare a variable. Would be very useful
|
|
|
|
 |
|
 |
Rolf Schaeuble wrote:
This article is ridiculous. This is absolutely basic knowledge for a Windows developer.
'nuff said.
I disagree. I remember a couple of years ago I was searching for information about how to make a simple DLL in MSDN, etc. and it was very challenging. There is all sorts of crap in there about exporting classes from DLLs, etc. but it is hard to find good information about making a simple DLL that simply exports a couple of functions like this one.
Thank you for making the article. It will be useful for others I am sure.
|
|
|
|
 |
|
 |
For beginners I would recommend buying a good introductionary book. MSDN Library is useful mostly as a reference manual, or for quite advanced material. Usually it doesn't state the obvious.
You argument is like saying that MSDN doesn't contain good introductionary material for learning C/C++, so people should post such articles here.
That just doesn't make sense.
Something that is written about in every beginner's book shouldn't be posted here . That just makes this site less useful.
- Rolf
|
|
|
|
 |
|
 |
I couldn't disagree more, Rolf. I think that beginner articles are fantastic. I often send some of my Jr. programmers who are new to MFC to this site for good begginer articles.
It doesn't take that long to skim and disregard an article if it is too simple for you. Trust me, those who are learning this stuff are happy to get the information anywhere they can.
And as a more Sr. programmer having introductory articles on this site is good to see. Let's not get so "hard-core" here that we leave beginners out of the community.
|
|
|
|
 |
|
 |
I understand your point, but wouldn't it be better to just give a good introductionary book to your collegues? A book can cover more than one topic, each chapter building upon the earlier ones. That's something that's much harder to do on a site like this one. As a result, a book can be much more effective.
I'm not opposed to introductionary articles 'per se'; I just think that this article is not useful. The next step would be to write an article about 'how to turn on your PC'. There's a limit beyond which an article shouldn't be written.
- Rolf
|
|
|
|
 |
|
 |
To Rolf,
According to you, articles for beginners do not belong on the codeproject. I find that funny considering that there is a difficulty level combobox that has a category called "Beginner". That would suggest to me that there is a place for beginner articles on the codeproject.
You may not find the article useful since you are obviously not a beginner. Or are you? Why did you look at the article to begin with? I mean, it's labeled Super Easy DLL and categorized as a beginner article. If you are such an advanced programmer and dll's are such a peice of cake for you, then why would you even click the link?
The beginner articles on this site helped me immensely and I learned a lot from them when I first started programming. I owe a lot to this site and the people that post articles here so I try to give back whenever possible. I noticed you have not done the same since becoming a member in 2003. Since you are such an advanced programmer and this article is so beneath you, then why haven't you shared your vast knowledge with the rest of us? Don't give me the, "I'm too busy" pitch because you are obviously not too busy to trash someone's article that you claim to be a waste of your time. Which is ironic considering you wasted your time typing that garbage message of yours in the message forum.
Maybe instead of Rolling On The Floor Laughing, you should Get Up and Write a Peice of Code. It'll serve you better than copying and pasting from codeproject.
So you think I should write a sequel called 'how to turn on your pc?'. I think it would be more beneficial for everyone if I wrote an article called 'how to turn off your pc for dummies' dedicated in your name. *Hint* *Hint*!
Nothing annoys me more than RTFM people such as yourself. It's people like you that force these articles to be written in the first place. If I asked how to write a dll like this in a newsgroup you would be the first one to tell me to RTFM! Well that's not good enough. This article will probably save people from having to search through msdn or books as you suggest they do. Plus it gives them example code to work from.
P.S. Rolf, maybe you should write that article on how to delcare a variable. It looks like you need an idea to use for an article to submit.
To everyone else,
Sorry for the rant. Sometimes I just get really annoyed with people's comments, especially when the comments are from people who have contributed JACK S*** to the codeproject. Comments like these make me want to remove every article I have ever submitted to this site.
Cheers,
Greg
|
|
|
|
 |