Shared DLL - Programmer

This is a discussion on Shared DLL - Programmer ; Hello there! I'm in serious trouble here... Imagine this situation: I have a dll (lets name it "main dll") used by two different applications. This main dll is used for, among other things, use another dll ("comm dll") to access ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Shared DLL

  1. Shared DLL

    Hello there!

    I'm in serious trouble here...
    Imagine this situation: I have a dll (lets name it "main dll") used by
    two different applications.
    This main dll is used for, among other things, use another dll ("comm
    dll") to access the serial port COM1 (the class that access the serial
    port is a singleton).

    The first application works alright but when I start the second one, it
    creates another instance of the main dll which tries to use the comm
    dll. Result: it crashes! I see an access violation at the comm dll's
    object inside the main dll.

    Do you know how to let only one dll instance in memory? Or do you see
    another solution?

    Thanks a lot for the attention!


  2. Re: Shared DLL

    Gandalf, the White wrote:
    > Hello there!
    >
    > I'm in serious trouble here...
    > Imagine this situation: I have a dll (lets name it "main dll") used by
    > two different applications.
    > This main dll is used for, among other things, use another dll ("comm
    > dll") to access the serial port COM1 (the class that access the serial
    > port is a singleton).
    >
    > The first application works alright but when I start the second one, it
    > creates another instance of the main dll which tries to use the comm
    > dll. Result: it crashes! I see an access violation at the comm dll's
    > object inside the main dll.
    >
    > Do you know how to let only one dll instance in memory? Or do you see
    > another solution?
    >
    > Thanks a lot for the attention!


    Only one process at a time may open a COM port. A DLL is not a process,
    it is part of each process that loads it. Each loaded version is a
    separate instance, unrelated to the other instances.

    You need to open the port in one process only, then you can use
    interprocess communication to exchange data with other processes. One
    possible solution is to open the port in a service process.

    --
    Scott McPhillips [VC++ MVP]


  3. Re: Shared DLL



    Scott McPhillips [MVP] wrote:
    > Gandalf, the White wrote:
    > > Hello there!
    > >
    > > I'm in serious trouble here...
    > > Imagine this situation: I have a dll (lets name it "main dll") used by
    > > two different applications.
    > > This main dll is used for, among other things, use another dll ("comm
    > > dll") to access the serial port COM1 (the class that access the serial
    > > port is a singleton).
    > >
    > > The first application works alright but when I start the second one, it
    > > creates another instance of the main dll which tries to use the comm
    > > dll. Result: it crashes! I see an access violation at the comm dll's
    > > object inside the main dll.
    > >
    > > Do you know how to let only one dll instance in memory? Or do you see
    > > another solution?
    > >
    > > Thanks a lot for the attention!

    >
    > Only one process at a time may open a COM port. A DLL is not a process,
    > it is part of each process that loads it. Each loaded version is a
    > separate instance, unrelated to the other instances.
    >
    > You need to open the port in one process only, then you can use
    > interprocess communication to exchange data with other processes. One
    > possible solution is to open the port in a service process.
    >
    > --
    > Scott McPhillips [VC++ MVP]


    I know that I can share a memory section via #pragma or .def (e.g.
    SECTIONS .data READ WRITE SHARED) but it doesn't work properly in my
    case. I'm avoiding doing another process to manage the serial port and
    use IPC do exchange data because it's odd to my architecture, but it
    seems to be the only way...
    My last hope was to check why the pragma stuf ain't working...
    any ideas?


  4. Re: Shared DLL

    Gandalf, the White wrote:
    > I know that I can share a memory section via #pragma or .def (e.g.
    > SECTIONS .data READ WRITE SHARED) but it doesn't work properly in my
    > case. I'm avoiding doing another process to manage the serial port and
    > use IPC do exchange data because it's odd to my architecture, but it
    > seems to be the only way...
    > My last hope was to check why the pragma stuf ain't working...
    > any ideas?


    A shared memory section is one form of interprocess communication. It
    doesn't change the rules with regard to sharing a port.

    If you can't get the shared memory working with #pragma you can do it
    with CreateFileMapping and MapViewOfFile.

    --
    Scott McPhillips [VC++ MVP]


+ Reply to Thread