Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Two aplications communicate through a dll...

Two aplications communicate through a dll...

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionjavajavascripthelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Freeze
    wrote on last edited by
    #1

    Hi, I have two application which need to communicate though a dll (one application is written in C++, the other in Java). The Java application makes calls to the dll through its native interface. My problem is the following: The dll has to transmit data (just a string and a float) to my C++ application which should immediately react. I use a shared data segment in my dll. The data which has to be transmited is first stored in that data segment, and then my C++ application periodically looks if something in the shared data segment is waiting. This is not so elegant and also my C++ application doesn't immediately react since it only does polling. What is the best way to proceed? Should I use a PostMessage to announce that there is data waiting? And in that case will my C++ application immediately be able to react? (the C++ application is just a dialog doing nothing if no button is pressed). Or can the data directly be transmitted in a PostMessage? (there's just a string and a float to transmit). Should you have some good idea, please let me know :) Thanks

    C A M 3 Replies Last reply
    0
    • M Mr Freeze

      Hi, I have two application which need to communicate though a dll (one application is written in C++, the other in Java). The Java application makes calls to the dll through its native interface. My problem is the following: The dll has to transmit data (just a string and a float) to my C++ application which should immediately react. I use a shared data segment in my dll. The data which has to be transmited is first stored in that data segment, and then my C++ application periodically looks if something in the shared data segment is waiting. This is not so elegant and also my C++ application doesn't immediately react since it only does polling. What is the best way to proceed? Should I use a PostMessage to announce that there is data waiting? And in that case will my C++ application immediately be able to react? (the C++ application is just a dialog doing nothing if no button is pressed). Or can the data directly be transmitted in a PostMessage? (there's just a string and a float to transmit). Should you have some good idea, please let me know :) Thanks

      C Offline
      C Offline
      Christopher Lord
      wrote on last edited by
      #2

      Hmm, there are a couple things that i can think of anyways. If you have the DLL working in both projects already with shared memory, you can either poll a variable in your c++ code (a byte set to 0 for no-change or haschange). You can do this as little as once a second or in a tight loop depending on your needs. Not generally a good idea though, so i recommend: Sending a windows message with PostMessage/SendMessage. PostMessage is will return as soon as the message is dispatched, sendmessage waits for recipt confermation. Only use sendmessage for intra-process for deadlock reasons. So your left with PostMessage. you can PostMessage an address in the DLL, or simply use the fact that the message has been sent to check pre-defined areas in the DLL. Either way is a good way of going. Post/sendMessage can only send two 32-bit numbers, so you cant send a string. You could try packeting through the message pump, but thats just plain silly. // Rock

      1 Reply Last reply
      0
      • M Mr Freeze

        Hi, I have two application which need to communicate though a dll (one application is written in C++, the other in Java). The Java application makes calls to the dll through its native interface. My problem is the following: The dll has to transmit data (just a string and a float) to my C++ application which should immediately react. I use a shared data segment in my dll. The data which has to be transmited is first stored in that data segment, and then my C++ application periodically looks if something in the shared data segment is waiting. This is not so elegant and also my C++ application doesn't immediately react since it only does polling. What is the best way to proceed? Should I use a PostMessage to announce that there is data waiting? And in that case will my C++ application immediately be able to react? (the C++ application is just a dialog doing nothing if no button is pressed). Or can the data directly be transmitted in a PostMessage? (there's just a string and a float to transmit). Should you have some good idea, please let me know :) Thanks

        A Offline
        A Offline
        Andreas Saurwein
        wrote on last edited by
        #3

        There are some other (more efficient) methods too: Events, Pipes, Mailslots, etc. Simplest solution is to prepare the data and raise an event. The receiving DLL will WaitForSingleObject/WaitForMultipleObjects on that event. And then requests/reads the data. No polling, no SendMessage/PostMessage. Additionally you can secure the communication by using object level security. At the same time you gain also real synchronization between sender/receiver.

        1 Reply Last reply
        0
        • M Mr Freeze

          Hi, I have two application which need to communicate though a dll (one application is written in C++, the other in Java). The Java application makes calls to the dll through its native interface. My problem is the following: The dll has to transmit data (just a string and a float) to my C++ application which should immediately react. I use a shared data segment in my dll. The data which has to be transmited is first stored in that data segment, and then my C++ application periodically looks if something in the shared data segment is waiting. This is not so elegant and also my C++ application doesn't immediately react since it only does polling. What is the best way to proceed? Should I use a PostMessage to announce that there is data waiting? And in that case will my C++ application immediately be able to react? (the C++ application is just a dialog doing nothing if no button is pressed). Or can the data directly be transmitted in a PostMessage? (there's just a string and a float to transmit). Should you have some good idea, please let me know :) Thanks

          M Offline
          M Offline
          Mr Freeze
          wrote on last edited by
          #4

          Thanks for your kind help, I got it to work correctly :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups