locked
Communication between vb6 and C# applications RRS feed

  • Question

  • I have two applications , one is a WinForms Application written  in C# and the other is a VB6 Application, i need to call the C# application from VB6, is that possible.  

    i.e: How can i call the C# methods from VB6 application.

    what are the different methods that i can use to communicate between the applications.

    If anyone can help me here that would be great.

    Monday, November 16, 2015 9:48 PM

Answers

All replies

  • I have two applications , one is a WinForms Application written  in C# and the other is a VB6 Application, i need to call the C# application from VB6, is that possible.  

    i.e: How can i call the C# methods from VB6 application.

    There is nothing you can do with two exe(s) as both programs must be running concurrently for you to access anything directly in the C# program, an exe.  The reality here is there is nothing you can do without making drastic changes to both programs as I see it.

    What you can do is make a .NET DLL VB or C# and place the functionality in the DLL from the C# exe program. Then you can call the DLL from you VB6 program, since the VB6 program would be hosting the .NET DLL. That's assuming you have source code access to both codes C# and VB6.

    https://msdn.microsoft.com/en-us/library/ms973802.aspx

    Monday, November 16, 2015 10:19 PM
  • No and beside that is this not the C# or the VB6 forum.

    This forum does not support vintage VB only versions from VB7 and newer are supported. 


    Success
    Cor

    Monday, November 16, 2015 10:38 PM
  • If the apps are on the same system you can use the clipboard using a clipboard listener in each app if vb6 supports that and if you still develop both apps. Or use other InterProcess Communication methods if vb6 supports them.

    This is a clipboard listener for VB.Net. It should work if you convert it to C# using some converter like Telerik. It may even work in vb6 or less if you know how to alter it and vb6 can monitor windows messages for its app and possibly use the 32 bit versions of the .Dlls for the vb6 app.

    For a clipboard listening system both apps would need a messaging scheme to understand when something copied to the clipboard by one of them was for the other one.

    In C# you can use the Cliboard Class for copying to the clipboard but who knows for vb6. Of course if any of this works you don't want to copy 64 bit info to a clipboard for 32 bit vb6 to deal with unless you compensate for that in some fashion.

    You could even use a filewatcher if vb6 supports that so that each app sends messages via updating a file and when the file is updated for an app its filewatcher will notify it of the file updating so the app can read the file for whatever the data is which could be text or binary.

    Option Strict On
    
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        ' System.Windows.Forms.DataFormats class http://msdn.microsoft.com/en-us/library/system.windows.forms.dataformats(v=vs.110).aspx
    
        Declare Function AddClipboardFormatListener Lib "user32.dll" (hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    
        Declare Function RemoveClipboardFormatListener Lib "user32.dll" (hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    
        Dim DataFormats As New Dictionary(Of String, String)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
    
            DataFormats.Add("Bitmap", "Specifies a Windows bitmap format. This static field is read-only.")
            DataFormats.Add("CommaSeparatedValue", "Specifies a comma-separated value (CSV) format which is a common interchange format used by spreadsheets. This format is not used directly by Windows Forms. This static field is read-only.")
            DataFormats.Add("Dib", "Specifies the Windows device-independent bitmap (DIB) format. This static field is read-only.")
            DataFormats.Add("Dif", "Specifies the Windows Data Interchange Format (DIF) which Windows Forms does not directly use. This static field is read-only.")
            DataFormats.Add("EnhancedMetafile", "Specifies the Windows enhanced metafile format. This static field is read-only.")
            DataFormats.Add("FileDrop", "Specifies the Windows file drop format which Windows Forms does not directly use. This static field is read-only.")
            DataFormats.Add("Html", "Specifies text in the HTML Clipboard format. This static field is read-only.")
            DataFormats.Add("Locale", "Specifies the Windows culture format which Windows Forms does not directly use. This static field is read-only.")
            DataFormats.Add("MetafilePict", "Specifies the Windows metafile format which Windows Forms does not directly use. This static field is read-only.")
            DataFormats.Add("OemText", "Specifies the standard Windows original equipment manufacturer (OEM) text format. This static field is read-only.")
            DataFormats.Add("Palette", "Specifies the Windows palette format. This static field is read-only.")
            DataFormats.Add("PenData", "Specifies the Windows pen data format which consists of pen strokes for handwriting software; Windows Forms does not use this format. This static field is read-only.")
            DataFormats.Add("Riff", "Specifies the Resource Interchange File Format (RIFF) audio format which Windows Forms does not directly use. This static field is read-only.")
            DataFormats.Add("Rtf", "Specifies text consisting of Rich Text Format (RTF) data. This static field is read-only.")
            DataFormats.Add("Serializable", "Specifies a format that encapsulates any type of Windows Forms object. This static field is read-only.")
            DataFormats.Add("StringFormat", "Specifies the Windows Forms string class format which Windows Forms uses to store string objects. This static field is read-only.")
            DataFormats.Add("SymbolicLink", "Specifies the Windows symbolic link format which Windows Forms does not directly use. This static field is read-only.")
            DataFormats.Add("Text", "Specifies the standard ANSI text format. This static field is read-only.")
            DataFormats.Add("Tiff", "Specifies the Tagged Image File Format (TIFF) which Windows Forms does not directly use. This static field is read-only.")
            DataFormats.Add("UnicodeText", "Specifies the standard Windows Unicode text format. This static field is read-only.")
            DataFormats.Add("WaveAudio", "Specifies the wave audio format which Windows Forms does not directly use. This static field is read-only.")
    
            AddClipboardFormatListener(Me.Handle)
           
        End Sub
    
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            RemoveClipboardFormatListener(Me.Handle)
        End Sub
    
        Protected Overrides Sub WndProc(ByRef m As Message)
            If m.ToString.Contains("msg=0x31d") Then
                Invoke(New ClipboardListenerDelegate(AddressOf ClipboardListener))
            End If
            MyBase.WndProc(m)
        End Sub
    
        Private Delegate Sub ClipboardListenerDelegate()
    
        Private Sub ClipboardListener()
            If InvokeRequired Then
                Invoke(New ClipboardListenerDelegate(AddressOf ClipboardListener))
            Else
                RichTextBox1.Clear()
                For Each Item In DataFormats.Keys
                    If Clipboard.ContainsData(Item) = True Then
                        RichTextBox1.AppendText(Item & " .. " & DataFormats(Item) & vbCrLf)
                    End If
                Next
            End If
        End Sub
    
    End Class


    La vida loca

    Monday, November 16, 2015 11:38 PM
  • Your best and easiest option would probably be to use named pipes. You will need to use the Windows API for VB 6.0.

    How To Use Named Pipes in a Visual Basic 32-bit Program

    How to: Use Named Pipes for Network Interprocess Communication

    Some of the other technologies such as DDE and Mailslots are rather ancient so I would not recommend them going forward. Using COM would require a "wrapper" around your C# app, which sort of mimics a VB 6.0 ActiveX EXE.


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Tuesday, November 17, 2015 1:08 PM
  • Your best and easiest option would probably be to use named pipes. You will need to use the Windows API for VB 6.0.

    How To Use Named Pipes in a Visual Basic 32-bit Program

    How to: Use Named Pipes for Network Interprocess Communication

    Some of the other technologies such as DDE and Mailslots are rather ancient so I would not recommend them going forward. Using COM would require a "wrapper" around your C# app, which sort of mimics a VB 6.0 ActiveX EXE.


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Is there something with my eyes Paul, I still read this forum is not for VB6.

    Or should we awake MW to tell that he is needed to help here?


    Success
    Cor

    Tuesday, November 17, 2015 3:06 PM
  • Thanks Cor. It's not for C# either, so a moderator can probably move it to the Visual C# forum.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, November 17, 2015 5:15 PM
  • Thanks Cor. It's not for C# either, so a moderator can probably move it to the Visual C# forum.

    Paul ~~~~ Microsoft MVP (Visual Basic)


    I'm closing the thread and moving it to Off Topic.  I don't think the C# forum is correct because the OP wants to consume the .Net library from VB6; it should be irrelevant that said library was writing in C#.  I believe this to ultimately be a VB6 question.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, November 17, 2015 5:59 PM