Jump to content

Recommended Posts

Posted

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

Posted
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

Posted
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.
Posted

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++

Posted

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:

 

#include 

// 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

Posted
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.
Posted

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.

Posted

Think ill have a try with sockets for my listening app, know any nice tutorials for sockets that i could look at?

 

Thanks

Jack

Posted
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?

Posted
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

Posted

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

Posted
For which language? Do you have any preference? Or are you sticking with C?

 

Think i will stick with c++

 

Thanks,

Jack

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...