troubleshooting Question

translating vb.net to c# for an external call

Avatar of g_johnson
g_johnsonFlag for United States of America asked on
Visual Basic.NETC#
3 Comments1 Solution96 ViewsLast Modified:
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
        ShopOrderBegSearch()
    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
            MessageBox.Show(Trim(p_sFilterrtn))
        End If
    End Sub
       



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?


[DllImport("searches.dll")]
        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_sFilter);
            p_sFilterrtn = p_sReturnBuffer.Substring(0, (int)p_lFilterrtnLen);// Strings.Left(p_sReturnBuffer, p_lFilterrtnLen);
            if (p_bRtnVal)
            {
                MessageBox.Show(p_sFilterrtn.Trim());
            }

            //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);
            //}
        }
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros