Coding Thread, Send data to C++ app in Coding and Web Development; I dont have much knowledge of C++ just abit to get me by. I'm writing a program that will sit ...
21st August 2008, 02:02 PM #1
Send data to C++ app
I dont have much knowledge of C++ just abit to get me by. I'm writing a program that will sit in the background and wait for data then submit it to a database. What is the best way for another C++ app (Winamp which i will be writing a plugin for) to send data to my app?
E.g it will be like this
Winamp Plugin -> My App
So whats the best way of sending the data to my app in c++
21st August 2008, 02:20 PM #2
Originally Posted by Jackd
Hacks: If they're on the same machine then you could have your plugin call your separate application as a command, i.e. have C++ do a system() call to start your application and pass it some data via the command line. Does a process spawn each time you call the application, so not tremendously efficient. You could also have your plugin plonk its data in a separate directory and have your application periodically scan that directory for changes. Simple, but does mean a delay in your data getting from your plugin to your application.
Properly, you'll be wanting to use inter-process communication - Google search for "C++ interprocess communication" should get you started - or define an API for your application that other programs (i.e. your plugin) can call. I think this means creating a library of callable functions (a Windows DLL file) - time to rummage through the compiler manual and/or Google for a while.
Some more details of what, exactly, you are doing might get a more detailed response.
21st August 2008, 02:29 PM #3
Well they'll both be on the same machine, basically the app will be running in the background (e.g. continously running) waiting for data to be received and this app will parse the data. inter-process communication sounds like what i need time to google i think.
21st August 2008, 02:52 PM #4
Sounds :S to me,
I would look at Firedaemon if you want to make a program run as a service. As for actually doing anything, I've got no idea, I would guess, look at WinAmp, see if they have a API in C++
21st August 2008, 03:02 PM #5
Winamp do have an API, and the plugins are just .dlls made in either c or c++ i was just using that as an example
21st August 2008, 03:15 PM #6
The Wikipedia article on DLL files is probably worth a read:
Dynamic-link library - Wikipedia, the free encyclopedia
Specifically the bit about exporting C++ functions:
// DLL entry function (called on load, unload, ...)
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
// Exported function - adds two numbers
extern "C" __declspec(dllexport) double AddNumbers(double a, double b)
return a + b;
28th August 2008, 09:38 AM #7
THE easiest way is to use TCP sockets. Google for winsock if it's a windows app (since its slightly different to your standard unix sockets). Short of that, there's various other routes to use such as named piping and god forbid even having a file sat in the middle of the two apps (not recommended) but sockets are the easiest method to grasp.
28th August 2008, 09:51 AM #8
Are you more familiar with any other languages? If you use sockets it doesnt matter what language the program is written in in the first instance, just that the data that is sent is correct. I know the .NET framework (c# is synactically and symantically similar to C/C++/Java so might be worth a look) provide support for writing a service, which can obviously be set to start automatically and sit in the background waiting for some other app to send comms to it's open port.
You may be constrained by WinAmp as to what language you need to write the plug-in in though but as i said, the listening/processing app can be written in any language you are more comfortable in.
28th August 2008, 03:44 PM #9
Think ill have a try with sockets for my listening app, know any nice tutorials for sockets that i could look at?
29th August 2008, 09:51 AM #10
Originally Posted by Jackd
For which language? Do you have any preference? Or are you sticking with C?
29th August 2008, 10:41 AM #11
When it opens for business, get yourself over to stackoverflow - it would seem to be perfect for answering the exact type of question you have here. It's still in beta, but (according to the podcast I heard last night) should be live by around the 5th of September.
Originally Posted by Jackd
29th August 2008, 10:55 AM #12
- Rep Power
Another approach is to send a message from your WinAmp plugin to your app. Windows provides a special message called WM_COPYDATA that allows for inter process communication. The tricky bit is knowing where to send it, you need to know the destination HWND (Window handle), you can find it using FindWindow. Also your app will have to have a window that can receive the message. Most apps have windows even if they aren't visible to the user so its no big problem.
This approach is simpler than sockets but it isn't very portable, with sockets you could easily move your app onto another machine where as with WM_COPYDATA they would always have to be on the same physical box.
Just another idea though.
29th August 2008, 03:26 PM #13
Think i will stick with c++
Originally Posted by Lee_K_81
Last Post: 12th March 2008, 10:20 AM
By pooley in forum MIS Systems
Last Post: 25th September 2007, 08:34 PM
By mattpant in forum Windows
Last Post: 11th April 2007, 05:30 PM
By Quackers in forum Web Development
Last Post: 28th February 2007, 02:32 PM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread