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
        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

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?


[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);
            //}
        }

Open in new window

LVL 4
g_johnsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
Don't specify a space on the string; e.g. -
[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 = string.Empty;
            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);
            //}
        }

Open in new window

-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
g_johnsonAuthor Commented:
Hi saige -- that breaks the DLL as in getting a "stopped working" message.
0
g_johnsonAuthor Commented:
We found out that the error is actually a warning that can be ignored.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.