Link to home
Start Free TrialLog in
Avatar of kluyl
kluyl

asked on

VB to call and get return value from C++ functions on Unix

Dear experts,

Am working on VB application intended to access Unix and get information on system status, unix process/thread information(my sets of C++ programs) and able to get the return value from the Unix builtin functions or my own utilities functions in C++.

Objectives,
1) A sets of C++ functions (resides in UNIX) already built and i want to re-use them.
2) VB application on windows able to 'access/call' the functions in 1)
3) if direct function calling 2) is not achievable, any other alternatives?
4) Is there a way to expose C/C++ functions as object in Unix, and let Window appl to access via TCP and perhaps instantiate an object, just like java RMI(but i dun prefer Java) for this project.
5) Sample code if any

Thanks very much! Your kind advise is very much appreciated

-kluyl

Avatar of vinnyd79
vinnyd79

Most Unix boxes run rexec daemon on port 512 for remote execution of commands. You can connect to the rexec port and have the results of the command returned to VB. You can accomplish this using the winsock control. I'll see if I can throw an example together.
Here's a simple example. Add a Winsock control, a Textbox called Text1, a Textbox called Text2 with the Multiline Property set to True and 2 command buttons to a form.

Then paste this into the form and edit the machine ip,username and password.

To use the example type the command into Text1 and then click Command1.The results of the command should be in Text2.
To disconnect click Command2.


Private Sub Command1_Click()
    Winsock1.RemotePort = 512
    Winsock1.RemoteHost = "192.168.1.105" ' unix machine
    Winsock1.Connect
End Sub

Private Sub Command2_Click()  ' close connection
Winsock1.Close
End Sub

Private Sub WinSock1_Connect()
    Text2.Text = ""
    sendData Text1.Text, "vinny", "mypassword"
End Sub

Private Sub sendData(rsData As String, Optional rsUserId As String, Optional rsPwd As String)
Dim lRet As Long
    Winsock1.sendData (Chr(0))
   
    If Not IsMissing(rsUserId) Then
        Winsock1.sendData rsUserId & Chr(0)
    End If
   
    If Not IsMissing(rsPwd) Then
        Winsock1.sendData rsPwd & Chr(0)
    End If
   
    Winsock1.sendData rsData & Chr(0)
End Sub

Private Sub WinSock1_DataArrival(ByVal bytesTotal As Long)
    Dim sData As String
    Winsock1.GetData sData, vbString
    Text2.Text = Text2.Text & vbCrLf & sData
    Text2.Text = Replace(Text2.Text, vbLf, vbCrLf)
End Sub

Private Sub WinSock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    MsgBox Description, vbInformation, "reporting communication error"
End Sub
Avatar of kluyl

ASKER

vinnyd79,

1) how do check if the rexec is running on Unix ? If not, how do i set it up?
2) do i get the return value of C functions in Unix via sData as above mentioned?
for instance, i hv a own function that return a 'Y' or 'N' ..char check_serv_start(char* servtype); residing in Unix. This sData wil able to tell me the return value of check_serv_start(char* servtype)?

Please advise. Thanks.

-kluyl
Avatar of kluyl

ASKER

vinnyd79,

result if i run  ps -ef | grep rexecd =
  lnvdev 27742 39492   1 18:03:52  pts/0  0:00 grep rexecd

-kluyl
Avatar of kluyl

ASKER

vinnyd79,
What happened? Are you still there?

Moderator,
Pls do something... Are we going to stop here?

Avatar of DanRollins
Although this multi-part question was not answered in full, and the Expert did not return to provide needed additional help, I feel that the code posted answered an important part of the question and is thus PAQworthy.
-- DanRollins, EE Cleanup Volunteer
Avatar of kluyl

ASKER

Dan,

Am very disappointed with your comment. I hv been SOS for answer since 13-Apr, but the it was deserted or ignored, however you described it. After 1 month, then you now just pop-up and say i'm not responsible?? Please be rational.

-kluyl
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial