+ Post New Thread
Results 1 to 13 of 13
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 ...
  1. #1

    Join Date
    Jan 2007
    Location
    Durham, UK
    Posts
    328
    Thank Post
    33
    Thanked 17 Times in 12 Posts
    Rep Power
    21

    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

  2. #2

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,772
    Thank Post
    1,308
    Thanked 804 Times in 698 Posts
    Rep Power
    246
    Quote Originally Posted by Jackd View Post
    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

  3. #3

    Join Date
    Jan 2007
    Location
    Durham, UK
    Posts
    328
    Thank Post
    33
    Thanked 17 Times in 12 Posts
    Rep Power
    21
    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.

  4. #4

    matt40k's Avatar
    Join Date
    Jun 2008
    Location
    Ipswich
    Posts
    4,523
    Thank Post
    375
    Thanked 677 Times in 551 Posts
    Rep Power
    166
    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++

  5. #5

    Join Date
    Jan 2007
    Location
    Durham, UK
    Posts
    328
    Thank Post
    33
    Thanked 17 Times in 12 Posts
    Rep Power
    21
    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

  6. #6

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,772
    Thank Post
    1,308
    Thanked 804 Times in 698 Posts
    Rep Power
    246
    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

  7. #7
    Friez's Avatar
    Join Date
    Dec 2006
    Posts
    839
    Thank Post
    22
    Thanked 22 Times in 21 Posts
    Rep Power
    24
    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.

  8. #8

    Join Date
    Jan 2007
    Location
    Birmingham
    Posts
    807
    Thank Post
    29
    Thanked 36 Times in 24 Posts
    Rep Power
    27
    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.

  9. #9

    Join Date
    Jan 2007
    Location
    Durham, UK
    Posts
    328
    Thank Post
    33
    Thanked 17 Times in 12 Posts
    Rep Power
    21
    Think ill have a try with sockets for my listening app, know any nice tutorials for sockets that i could look at?

    Thanks
    Jack

  10. #10

    Join Date
    Jan 2007
    Location
    Birmingham
    Posts
    807
    Thank Post
    29
    Thanked 36 Times in 24 Posts
    Rep Power
    27
    Quote Originally Posted by Jackd View Post
    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?

  11. #11

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,772
    Thank Post
    1,308
    Thanked 804 Times in 698 Posts
    Rep Power
    246
    Quote Originally Posted by Jackd View Post
    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

  12. #12

    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    130
    Thank Post
    0
    Thanked 5 Times in 5 Posts
    Rep Power
    17
    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

  13. #13

    Join Date
    Jan 2007
    Location
    Durham, UK
    Posts
    328
    Thank Post
    33
    Thanked 17 Times in 12 Posts
    Rep Power
    21
    Quote Originally Posted by Lee_K_81 View Post
    For which language? Do you have any preference? Or are you sticking with C?
    Think i will stick with c++

    Thanks,
    Jack



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 0
    Last Post: 12th March 2008, 10:20 AM
  2. Replies: 1
    Last Post: 25th September 2007, 08:34 PM
  3. Replies: 6
    Last Post: 11th April 2007, 05:30 PM
  4. App to Web App
    By Quackers in forum Web Development
    Replies: 8
    Last Post: 28th February 2007, 02: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
  •