Results 1 to 3 of 3

Thread: [2005] Interface with C++

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    [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:
    1. Private Sub BtnProbeValue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProbeValue.Click
    2.     Dim sVar, sVal, sError As String
    3.     Dim sts As Integer
    4.  
    5.     sVar = "Hoppy"
    6.     sVal = 1.5
    7.     sts = SimIFace.ProbeGetValue(sVar, sVal, sError)
    8.  
    9.   End Sub

    Code:
    int SimIFaceNET::ProbeGetValue(String^ sVar, String^ sVal, String^ sError)
    {
      sVal = "3.444";
      sError = sError->Empty;
      return -1;
    }

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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:
    1. Declare Function ProbeGetValue Lib "SimIFaceNET.dll" (ByVal sVar As String, _
    2.                                 ByVal sVal As String, _
    3.                                 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:
    1. Declare Function ProbeGetValue Lib "SimIFaceNET.dll" (Byref sVar As String, _
    2.                                 ByRef sVal As String, _
    3.                                 ByRef sError As String) As Int32
    Last edited by bmahler; Apr 18th, 2007 at 01:12 PM.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: [2005] Interface with C++

    Ah, that makes sense. Kind of like making a declare to an API.

    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

Posting Permissions

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



Click Here to Expand Forum to Full Width