dcsimg
Results 1 to 9 of 9

Thread: Inter-process communication with C# application

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    431

    Inter-process communication with C# application

    I want to have my VB6 application communicate with C# application program.
    The message to communicate is simple. Here is a scenario.

    Code:
    VB6 APP                                            C# APP
    ---------------                          -----------------------
    Run C# APP         "1", "2" or "3"       
    Send command  ----------------> 
         Wait                                    Do work as the command
    Exit from loop    <----------------        Return code
                                                           Terminate
    I implemented this with Profile(ini file) but I want to do without file writing.
    Which way would be desirable?

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,911

    Re: Inter-process communication with C# application

    My preference would be just to use a socket control on each side to send data back and forth.
    Second might be Memory Mapped File, which doesn't actually require a file if doing non-persistent communication between the apps. For me it would be second choice because I haven't really done it, so don't have a good feel about how to go about it. But the reason I would consider it the .Net (since the 4.0 framework) includes a managed class to support Memory Mapped Files, so you don't have to resort to API calls on the .Net side of the connection.
    I do a lot more socket communication though, which is why it would be my first choice. Since both VB6 and C# have a control or class to do the work, it would only take a few minutes to set up. I'm on my way out, so signing off, but I'm sure someone can point you in the right direction, or have another choice they are familiar with.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    431

    Re: Inter-process communication with C# application

    Do you mean that socket control is Microsoft Winsock Control 6.0?
    If so, I know this is for TCPIP communication that interface with other PC in the LAN or WAN.
    Can I use this from different process in one computer?

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Inter-process communication with C# application

    Quote Originally Posted by jdy0803 View Post
    Do you mean that socket control is Microsoft Winsock Control 6.0?
    If so, I know this is for TCPIP communication that interface with other PC in the LAN or WAN.
    Can I use this from different process in one computer?
    Of course as long as both or all apps have Winsock.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Inter-process communication with C# application

    Dilittante has a ShellPipe control which works just fine as long as your C# uses StdIn, StdOut, and StdErr. Nice thing about it is you don't need to make any changes to your C# applictation
    Last edited by jmsrickland; Apr 24th, 2015 at 06:20 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,961

    Re: Inter-process communication with C# application

    As mentioned ShellPipe could work if the C# program is written as a console application, but aside from that it doesn't really apply.

    Probably the only ad hoc approach that will be easy to do generally is the least common denominator: TCP or UDP. Of course you need to worry about port collisions, but for personal use you can just fish around for some available port and then hope nothing else ever tries to use it down the road. Most casual coders struggle with this though.

    I can't recall whether WinForms supports DDE, but that's an often overlooked alternative with good support in VB6. Most people haven't ever used it though, so expect a round of whinging there too.

    There are lots of alternatives but they all require some effort, and as usual .Net's WCF tends to throw monkey wrneches into the works to prevent interoperability.

  7. #7
    Addicted Member
    Join Date
    Mar 2007
    Posts
    183

    Re: Inter-process communication with C# application

    I'm just returning to the VB scene after a few years, and don't use Windows outside of school, so take what I say with a grain of salt.

    I thought I read somewhere that you can have non-.NET code and .NET code in the same application. So, you can throw in some non-.NET code into the program to handle communications with your VB6 app. Then you can use .NET for the other stuff.

    Hopefully, someone who's more experienced will comment on my reply.
    Do not read this sentence.
    You read that last one, didn't you?
    Darn. You now read the previous two.

    Check out my pins on Pinterest!

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,152

    Re: Inter-process communication with C# application

    I would probably use the TCP or UDP methods if I were doing it.

  9. #9
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    Re: Inter-process communication with C# application

    Very interesting question you got here.

    If you're working in winforms, another approach that is easy to implement is to shell a C# 's executable with a vb6 form's Textbox1.hwnd as an argument, and have C# use PostMessage API to send WM_KEYDOWN with a char to that handle.
    This char can then be interpreted using the Text_Change event on the VB6 side, with a SELECT-CASE block.
    This will allow your C# application to update VB6's about its progress in real-time.

    If implemented well enough, and you pass a C# textbox's handle back to vb6, this can even become a two-way communication via Postmessage.

    Prerequisites though are to hide the textboxes from the users on both C# and Vb6, and implemented a Switch\Select-Case blocks on each application.
    looking at it, this actually sounds way more complicated than it really is, if interested i can post some code.

    Another way which i found quite useful but somehow isn't very popular, and i'm probably the only person who uses it, is using Memory-writing to constants on both sides.
    WriteProcessMemory API allows you to change another process's memory values - making it ideal for this situation.
    It's like having a shared variable between the two application - what more can one ask.
    (doing so on CONSTs is preferable as it removes the headache of playing with pointers to find the wanted memory address of your variable each time.)
    If interested i can post some code on this as well.
    Last edited by stum; Apr 25th, 2015 at 05:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width