[2005] Interface with C++
I'm trying to interface with a C++ app. I have everyone tlking to each other but the data that I am sending from VB seems to be byval versus byref.
From the ProbeValue_click event I am calling the C++ interface with sVal = 1.5. I can step through the code and see the 1.5 value when I reach the C++ function. I can also watch the value change to 3.444 in the C++ code.
The intent is to call byRef so the the value in VB equals the value set by C++. The ^ character in C++ (VS8) is the same as the old C/C++ reference character *. So, from what i can tell C++ is expecting a reference but VB is send a value.
What am I missing?
vb Code:
Private Sub BtnProbeValue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProbeValue.Click
Dim sVar, sVal, sError As String
Dim sts As Integer
sVar = "Hoppy"
sVal = 1.5
sts = SimIFace.ProbeGetValue(sVar, sVal, sError)
End Sub
Code:
int SimIFaceNET::ProbeGetValue(String^ sVar, String^ sVal, String^ sError)
{
sVal = "3.444";
sError = sError->Empty;
return -1;
}
Re: [2005] Interface with C++
you need to declare your function and refernece that dll. You can then call the function.
Something like this...
vb.net Code:
Declare Function ProbeGetValue Lib "SimIFaceNET.dll" (ByVal sVar As String, _
ByVal sVal As String, _
ByRef sError As String) As Int32
Then add the dll to the app directory
Edit: I just kind of read your post again and am kind of confused. Is that c++ function doing anything besides setting sError to empty and returning -1? I am not all that familiar with c++, but I have used c++ dll's in my vb.net projects. If you want all variables to be byRef then declare them as ByRef like so
vb.net Code:
Declare Function ProbeGetValue Lib "SimIFaceNET.dll" (Byref sVar As String, _
ByRef sVal As String, _
ByRef sError As String) As Int32
Re: [2005] Interface with C++
Ah, that makes sense. Kind of like making a declare to an API.
Quote:
Is that c++ function doing anything besides setting sError to empty and returning -1?
That was a simplifed test case. We had a huge function written but it didn't work because it did not update the variables. As soon as I verify that this works, I'll return the true functionality of the code.
Thanks