Avatar of g_johnson
Flag for United States of America

asked on 

translating vb.net to c# for an external call

This VB.Net code calls up a search screen and properly accepts a value into p_sReturnBuffer:

    Public Declare Function DoSearch Lib "searches.dll" ( _
        ByVal SearchID As String, ByVal Server As String, ByVal Database As String, ByVal unknown1 As String, _
        ByVal unknown2 As String, ByVal username As String, ByVal pass As String, ByVal group As String, _
        ByVal RetBuf As String, ByVal RetLen As Long, ByVal Filter As String) As Boolean

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub
    Private Sub ShopOrderBegSearch()
        Dim p_lReturnBufferLen As Long = 255
        Dim p_sReturnBuffer As String = Space(p_lReturnBufferLen)
        Dim p_bRtnVal As Boolean
        Dim p_sFilter As String = ""
        Dim p_sFilterrtn As String
        Dim p_SSearchID As String = "SHOP-ORDER-NO"
        Dim p_lFilterrtnLen As Long = 8

        p_bRtnVal = DoSearch(p_SSearchID, "WIN-G36452O7", "783", "", "", "", "", "", p_sReturnBuffer, p_lReturnBufferLen, p_sFilter)
        p_sFilterrtn = Strings.Left(p_sReturnBuffer, p_lFilterrtnLen)
        If p_bRtnVal Then
        End If
    End Sub

Open in new window


This is what I think is the equivalent C# code, which does indeed call up the search screen, but p_sReturnBuffer does not get changed from the original 255 character string to the correct return value.  Any idea what I am doing wrong?

        public static extern bool DoSearch(string SearchID, string Server, string Database, string unknown1, string unknown2, string username, string pass, string group, string RetBuf, long RetLen, string Filter);

       private void attempttodosearch()

            long p_lReturnBufferLen = 255;
            string p_sReturnBuffer = new String(' ',255);//Strings.Space(p_lReturnBufferLen);
            bool p_bRtnVal = false;
            string p_sFilter = "";
            string p_sFilterrtn = null;
            string p_SSearchID = "SHOP-ORDER-NO";
            long p_lFilterrtnLen = 8;

            p_bRtnVal = DoSearch(p_SSearchID, "WIN-G36452O7", "783", "", "", "", "", "", p_sReturnBuffer, p_lReturnBufferLen,
            p_sFilterrtn = p_sReturnBuffer.Substring(0, (int)p_lFilterrtnLen);// Strings.Left(p_sReturnBuffer, p_lFilterrtnLen);
            if (p_bRtnVal)

            //string rBuffer = new String(' ', 255);
            //long bLen = 255;
            //string sFilter = "";

            //bool retVal = DoSearch("SHOP-ORDER-NO", this._Server, this._Database, "", "", "", "", "", rBuffer, bLen, sFilter);
            //if (retVal)
            //    string result = rBuffer.Substring(0, Convert.ToInt32(bLen));
            //    MessageBox.Show(result);

Open in new window

Visual Basic.NETC#

Avatar of undefined
Last Comment

8/22/2022 - Mon