VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 307,124 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,001 people online right now. Registration is fast and FREE... Join Now!




VB Communications

 

VB Communications

(none)

4 Nov, 2009 - 10:54 AM
Post #1

New D.I.C Head
*

Joined: 30 Sep, 2009
Posts: 35

Hi.

Is it possible for a Visual Basic Application to connect and communicate with a Windows Service written in C++? I am trying to avoid Sockets if I can, but I would like something which is as simple as. ConnectToService(). SendToVisualBasic, ReceiveFromService, SendToService, ReceiveFromVisualBasic, CloseConnection.

Thanks.

User is offlineProfile CardPM
+Quote Post


JackOfAllTrades

RE: VB Communications

4 Nov, 2009 - 01:21 PM
Post #2

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 5,321



Thanked: 454 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: code.gif

Thanks.
User is offlineProfile CardPM
+Quote Post

(none)

RE: VB Communications

4 Nov, 2009 - 02:36 PM
Post #3

New D.I.C Head
*

Joined: 30 Sep, 2009
Posts: 35

Hi.

This is not a homework assignment, I have no idea how it is done or if it is possible. Hence. Could you point me in the right direction?

Thanks.
User is offlineProfile CardPM
+Quote Post

bytelogik

RE: VB Communications

4 Nov, 2009 - 10:23 PM
Post #4

D.I.C Head
**

Joined: 6 Oct, 2009
Posts: 63



Thanked: 5 times
My Contributions
"Windows Service written in C++"

Do you mean an DLL written in C++ and the DLL functions called from VB ?
User is offlineProfile CardPM
+Quote Post

(none)

RE: VB Communications

5 Nov, 2009 - 12:00 AM
Post #5

New D.I.C Head
*

Joined: 30 Sep, 2009
Posts: 35

No.

I mean a Windows Service I wrote in C. I need it and a Visual Basic application to communicate with each other and I donīt want to use sockets. I donīt know where to start.

User is offlineProfile CardPM
+Quote Post

bytelogik

RE: VB Communications

5 Nov, 2009 - 03:17 AM
Post #6

D.I.C Head
**

Joined: 6 Oct, 2009
Posts: 63



Thanked: 5 times
My Contributions
Check out. I hope you have not viewed this, although this is for VB.Net

http://msdn.microsoft.com/en-us/library/aa288037(VS.71).aspx

http://www.devarticles.com/c/a/VB.Net/Crea...ce-in-VB.NET/1/

Hope this helps.
User is offlineProfile CardPM
+Quote Post

(none)

RE: VB Communications

5 Nov, 2009 - 04:16 AM
Post #7

New D.I.C Head
*

Joined: 30 Sep, 2009
Posts: 35

Hi thanks.

The first link seems helpful, but the Windows Service has to be written in C and the client has to be written in VB. It still doesnīt seem to address the problem of The Windows Service knowing when a client has connected, seeking its permission before executing some close.

I certainly will read.
User is offlineProfile CardPM
+Quote Post

(none)

RE: VB Communications

5 Nov, 2009 - 10:04 AM
Post #8

New D.I.C Head
*

Joined: 30 Sep, 2009
Posts: 35

Hi.

I am reading. http://www.cplusplus.com/forum/articles/11168/.

Is it possible to connect to a pipe from within Visual Basic, if so this seems like the most ideal solution.
User is offlineProfile CardPM
+Quote Post

bytelogik

RE: VB Communications

5 Nov, 2009 - 11:11 AM
Post #9

D.I.C Head
**

Joined: 6 Oct, 2009
Posts: 63



Thanked: 5 times
My Contributions
Download API-Guide 3.7 from http://allapi.mentalis.org/agnet/appdown.shtml
There is an example for VB6 to create pipe which will be required to send as a parameter to the windows service.




User is offlineProfile CardPM
+Quote Post

(none)

RE: VB Communications

10 Nov, 2009 - 02:36 AM
Post #10

New D.I.C Head
*

Joined: 30 Sep, 2009
Posts: 35

Hi.

I have successfully made the connects, thanks.

The problem I am facing, is if I wrote the C equivient of this I will get all the information from the pipe, however if I use the code below I will only get 1 out of 2, 3 or 4 communications sent through the pipe. I know the problem isn't the server end because of this. Can someone tell me what I am doing wrong?

Thanks.

(none)

CODE

Private Const szPipeName = "\\.\pipe\pipe"
Private Const BufferSize = 65535

Private Declare Function CallNamedPipe Lib "kernel32" Alias "CallNamedPipeA" (ByVal lpNamedPipeName As String, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesRead As Long, ByVal nTimeOut As Long) As Long

Dim Process As Boolean

Private Sub cmdRecvFilenamesStart_Click()
    Dim res As Long
    Dim myStr As String
    Dim i As Long
    Dim cbRead As Long
    Dim numBytes As Long
    Dim bArray() As Byte
    Dim temp As String
    Dim Executions As Long
    
    numBytes = 1024
    Executions = 0
    If numBytes > BufferSize Then numBytes = BufferSize
    ReDim bArray(numBytes)
    Process = True
    While (Process = True)
        DoEvents
        res = CallNamedPipe(szPipeName, 0, 0, bArray(0), numBytes, cbRead, 1)
        If res > 0 Then
            temp = ""
            For i = 1 To cbRead - 1
                If Not Int(bArray(i)) = 0 Then temp = temp & Chr(Int(bArray(i)))
            Next i
            txtRecvFilenames.Text = "(" & Executions & ") " & temp
            Executions = Executions + 1
        Else
            If Not Err.LastDllError = 231 Then
                MsgBox "Error Number " & Err.LastDllError & " attempting to call CallNamedPipe.", vbOKOnly
                Process = False
            End If
        End If
    Wend
End Sub

Private Sub cmdRecvFilenamesStop_Click()
    Process = False
    MsgBox "Process Stopped", vbOKOnly, "Process Stopped"
End Sub

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 02:06PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month