CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2007
    Posts
    90

    Question on DLL written in c++...

    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

  2. #2
    Join Date
    Oct 2005
    Location
    Minnesota, U.S.A.
    Posts
    680

    Re: Question on DLL written in c++...

    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


  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Question on DLL written in c++...

    Quote Originally Posted by rag84dec View Post
    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?
    Best regards,
    Igor

  4. #4
    Join Date
    Jan 2009
    Posts
    1

    Re: Question on DLL written in c++...

    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

  5. #5
    Join Date
    Oct 2005
    Location
    Minnesota, U.S.A.
    Posts
    680

    Re: Question on DLL written in c++...

    Quote Originally Posted by coder_gate View Post
    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
    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.

  6. #6
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Question on DLL written in c++...

    Swedish might also work... (Sorry, couldn't resist this post)
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  7. #7
    Join Date
    Oct 2005
    Location
    Minnesota, U.S.A.
    Posts
    680

    Re: Question on DLL written in c++...

    Quote Originally Posted by S_M_A View Post
    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
    Last edited by egawtry; January 2nd, 2009 at 01:19 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured