Click to See Complete Forum and Search --> : Question on DLL written in c++...


rag84dec
November 19th, 2008, 05:11 AM
Hi all,

I have a lot of static libraries written in c++. i would now like to construct a DLL.
I have few questions...

1) What are the possible conditions that i need to be aware of as far as DLL is concerned??
2) How will i ensure the shared data usage??
3) Race conditions caused by dll??


please give me some reference if you have

Infinite thanks in advance for the help

egawtry
November 20th, 2008, 10:11 AM
If you are using MFC, take a look at Extension DLLs.
Otherwise,

1. It is best to pass things as straight ANSI C. It doesn't matter what you use internally in the DLL
If you must pass C++ classes, be very careful. The smallest change will make the DLL incompatible with existing code. You will need to use the automated dllexport calls to export your class from the DLL. If you want an good example of the ways to do DLL exports, create a dummy MFC Extension DLL. (Not a MFC DLL, but Extension DLL.) There will be several methods demoed in the sample code generated.
One big note: You have a separate heap with the DLL. If you allocate memory in the DLL, you have to free that memory from the DLL, even if it is a stub that calls free() or delete. So if you are passing classes, make sure all the "new" and "delete" calls are done in the CPP file, not the class definition.
2. The best way to share data is to use shared memory. Take a look at CreateFileMapping(), there are plenty of examples.
3. For Race conditions, use CriticalSection calls like usual.

-Erik

Igor Vartanov
November 24th, 2008, 10:04 AM
I have a lot of static libraries written in c++. i would now like to construct a DLL. And what's the reason?

I have few questions...

1) What are the possible conditions that i need to be aware of as far as DLL is concerned??Not sure about conditions, but you definitely have to gain some experience in designing DLL exports.

2) How will i ensure the shared data usage??Please give us some more details about that "shared data" and "ensure". DLL is just a buch of functions.

3) Race conditions caused by dll??Race conditions are typically caused by flaws in threading design, and dll has nothing to do with that. What did make you think that?

coder_gate
January 1st, 2009, 09:56 AM
DLL có thể viết bằng C++ hoặc không cần thiết,có thể viết 1 exe đóng vai trò DLL cũng được

egawtry
January 1st, 2009, 12:13 PM
DLL có thể viết bằng C++ hoặc không cần thiết,có thể viết 1 exe đóng vai tṛ DLL cũng được

Sorry, I don't speak Vietnamese or Thai. Hopefully someone else will be able to answer your question, but I would suggest reposting in English, German, or Russian.

S_M_A
January 1st, 2009, 03:50 PM
Swedish might also work... :) (Sorry, couldn't resist this post)

egawtry
January 2nd, 2009, 10:47 AM
Swedish might also work... :) (Sorry, couldn't resist this post)

Yeah, so would several other languages that are on CG: Czech, Polish, Danish, all the Scandinavian languages, French, Spanish, and Japanese. (Plus many more)

I chose those three because they are the most common scientific languages. Actually, for Computer Science, English and Russian are the most common, I just added German because it is a traditional science language, followed closely by French. Anyone posting is guaranteed to have someone here understand with one of those three. If it was 10 years ago, I would have put Japanese instead of the German.

Sorry if I insulted anyone.

-Erik