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
Ask a Question
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

troubleshooting Question

translating vb.net to c# for an external call

Avatar of g_johnson
g_johnsonFlag for United States of America asked on
C#Visual Basic.NET
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
Avatar of it_saige
it_saigeFlag of United States of America imageDeveloper
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers