We help IT Professionals succeed at work.
Get Started

string passed from vb.net express to C DLL is not updated

1,644 Views
Last Modified: 2013-11-27
I am trying to convert a VB Script program to VB.NET (2008 Express). The script uses Automation COM to access HLLAPI under the covers, Jolly Giant QWS3270).  I am currently just trying to get knowledgeable with VB.NET, for a simple console application, calling WinHLLAPI DLL (Jolly Giant's QWS3270).  I have many of the WinHLLAPI functions working just fine. The problem calls are those which require a string buffer to be passed in and that will be updated by the HLLAPI DLL. In each case, the string is not updated but the return code (in pos variable)
is 0 - so WinHLLAPI thinks it did something.

I have reduced my code to a small example below. This calls a HLLAPI function that does not require connecting to a session (just keeping things simple).

I have searched and searched the internet and EE.  Most answers are from C++ perspective.
I am not writing C or C++, I am wrting VB.NET Express code, hopefully there is a VB.NET Express answer to this.  There seem to be plenty of people using VB.NET to call a C/C++ DLL
and pass in a string using ByVal and get the string updated - but I do not seem to be able to.
Hopefully, someone in EE can help.  Thank you

Option Explicit On
Imports System.Runtime.InteropServices

Module Module1

    <DllImport("C:\Program Files\QWS3270 PLUS\whllapi.dll")> _
     Sub WinHLLAPI(ByRef f As Long, ByVal s As String, ByRef l As Long, ByRef r As Long)
    End Sub

    Sub Main()
        Call QuerySystem()
        End
    End Sub

    Public Sub QuerySystem()
        Dim str As String
        Dim pos As Long
        Dim length As Long
        Dim number As Long

        ' HLLAPI function number 10: Query System
        number = 20
        ' preallocated buffer area
        str = Space(35)
        ' the length is not really needed, 35 is implied
        length = Len(str)
        ' position is not needed here
        pos = 0
        ' call hllapi function
        WinHLLAPI(number, str, length, pos)
    End Sub
Comment
Watch Question
CEO/Programmer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 2 Answers and 24 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE