Two aplications communicate through a dll...
-
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
-
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
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
-
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
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.
-
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