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, 01:02 PM #1
- Rep Power
- 16
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++
Thanks
Jack
-
-
IDG Tech News
-
21st August 2008, 01:20 PM #2 
Originally Posted by
Jackd
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?
Are the two programs on separate machines, and how do you mean by "in the background"? If the applications are on separate machines you'll be needing some kind of network-based communications mechanism - i.e. using a direct TCP connection or using an HTTP-based remote procedure call mechanism (like Ajax for JavaScript - probably a SOAP or similar library).
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.
--
David Hicks
-
-
21st August 2008, 01:29 PM #3
- Rep Power
- 16
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, 01: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, 02:02 PM #5
- Rep Power
- 16
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, 02: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:
Code:
#include <windows.h>
// DLL entry function (called on load, unload, ...)
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
// Exported function - adds two numbers
extern "C" __declspec(dllexport) double AddNumbers(double a, double b)
{
return a + b;
} --
David Hicks
-
-
28th August 2008, 08: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, 08: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, 02:44 PM #9
- Rep Power
- 16
Think ill have a try with sockets for my listening app, know any nice tutorials for sockets that i could look at?
Thanks
Jack
-
-
29th August 2008, 08:51 AM #10 
Originally Posted by
Jackd
Think ill have a try with sockets for my listening app, know any nice tutorials for sockets that i could look at?
Thanks
Jack
For which language? Do you have any preference? Or are you sticking with C?
-
-
29th August 2008, 09:41 AM #11 
Originally Posted by
Jackd
Think ill have a try with sockets for my listening app, know any nice tutorials for sockets that i could look at?
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.
--
David Hicks
-
-
29th August 2008, 09:55 AM #12
- Rep Power
- 14
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.
Rob
-
-
29th August 2008, 02:26 PM #13
- Rep Power
- 16

Originally Posted by
Lee_K_81
For which language? Do you have any preference? Or are you sticking with C?
Think i will stick with c++
Thanks,
Jack
-
SHARE: 
Similar Threads
-
Replies: 0
Last Post: 12th March 2008, 09:20 AM
-
By pooley in forum MIS Systems
Replies: 1
Last Post: 25th September 2007, 07:34 PM
-
By mattpant in forum Windows
Replies: 6
Last Post: 11th April 2007, 04:30 PM
-
By Quackers in forum Web Development
Replies: 8
Last Post: 28th February 2007, 01:32 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules