Creating Windows Service with VB.NET (in Off-topic)
May 4 2010 12:17 AM EDT
For my final project for my Windows Programming course, I have to create two separate GUI applications and have the first one launch the other and send/receive data to/from it. Since there's no way to access another processes data fields directly, he suggested using a service as sort of a "middle man," and send data through that.
Now I've figured out how to create/install and start a service from the application, and I know you can use the myServiceController.ExecuteCommand(integer) method to send it an integer code, I'm just not sure how to get the data from the service to the second application.
Can anybody help me out with this or direct me somewhere that might help? I've done some extensive Googling and information on the topic is hard to find.
Or if anybody knows of a better/easier way to transfer data between applications, please share that as well. Thanks in advance.
I'm using VB.NET in Microsoft Visual Studio.
This might be of some help to you. Try looking up Process.Start() to launch another application. To communicate between two processes, what you're looking to do is creating a named pipe. For further information, look here: http://support.microsoft.com/?kbid=871044
Silly question, but can you use a database for your data? Because if so, then you can just do that.
The service could also shuttle data between the two applications via file operations and you have a file-monitoring control on a file in both applications.
Otherwise, you could use the socket interface to do it as well. That is probably a little bit overkill though.
May 5 2010 1:15 AM EDT
Thanks for the replies guys, turns out using a service would have been much more difficult on the campus' machines due to certain restrictions. I did manage to get a named pipe working almost flawlessly, thanks a bunch Lamu for pointing me in that direction. Verifex, my professor never said anything about NOT using a database, but since we had a choice of two projects (the other one exclusively dealing with databases) I assume he would like us to try a different approach.
May 6 2010 4:52 PM EDT
Uh, hey Lamu... I'm not sure how proficient you are with pipes or how much you'll be able to help, but I'm having a really strange problem now that I've spent hours trying to figure out.
I implemented my code for the pipe almost exactly as in the example on the page you showed me. I only changed it slightly to suit my purposes so it returns another integer instead of a char array.
In my program I have a ComboBox, and the integer that is sent through the pipe from the first program to the second program is determined by which item is selected in the ComboBox. The second program then modifies that integer and sends the new modified integer value back.
However, this only works for the first item in the ComboBox. For the others, when sending the integer back from the second program to the first program, a null reference exception would be thrown for the first program. Somehow the form for the first program and all the controls and variables in it became null.
This makes absolutely no sense to me because it is exactly the same code no matter what item is selected in the ComboBox. The only difference is the value of the integer that is being sent.
Do you have any idea what the problem could be?
May 7 2010 12:36 AM EDT
Ok, I've figured out if the integer that I sent from the first program to the second is greater than 16, it causes the crash. Odd that its such a small number...
Are you using WriteFile correctly? The function is expecting a buffer that is containing the data. Which application is crashing? The "server" or the "client"?
May 8 2010 2:28 PM EDT
It is the client that is crashing. I suppose it is possible I am not using Write correctly; the only thing I changed from the example was "ByRef lpBuffer() As Byte" to "ByRef lpBuffer as Integer" in "WriteFile". I left all the other parameters (even the ones I no longer needed) unchanged.
As a temporary solution for now, I simply reduced the values of the integers I send to the client.
This thread is closed to new posts.
However, you are welcome to reference it
from a new thread; link this with the html
<a href="/bboard/q-and-a-fetch-msg.tcl?msg_id=0032wX">Creating Windows Service with VB.NET</a>