Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:19:04+00:00 2026-06-06T22:19:04+00:00

(Day 2 of learning c#) I am passing a buffer to a C dll

  • 0

(Day 2 of learning c#) I am passing a buffer to a C dll from C#. The C func copies the string “text” into the buffer. Back in the C# code, I compare “text” with what’s in the buffer and it doesn’t compare equal. What am I missing?

    extern "C" __declspec( dllexport )      
    int  cFunction(char *plotInfo, int bufferSize) 
    {
        strcpy(plotInfo, "text");
        return(0);
    }

c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("mcDll.dll", CallingConvention = CallingConvention.Cdecl,
                                                      CharSet=CharSet.Ansi)]
        public static extern int cFunction(StringBuilder theString, int bufSize);

        static void Main(string[] args)
        {
            StringBuilder s = new StringBuilder(55);
            int result = cFunction(s, 55);
            Console.WriteLine(s);

            string zz = "text";
            if (s.Equals(zz))
                Console.WriteLine( "strings compare equal");
            else
                Console.WriteLine("not equal");

            Console.ReadLine();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:19:05+00:00Added an answer on June 6, 2026 at 10:19 pm

    s is a StringBuilder, while zz is a string.

    Try comparing

    s.ToString().Equals(zz);
    

    Generally, Equals() performs a reference comparison for reference types. Some classes (such as String) override Equals() to allow for strings that contain the same characters to be considered equal (though for performance purposes, I believe the actual implementation first checks for reference equality, then compares the contents of each string).

    Your current code is calling the .Equals() method of StringBuilder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I am like one day into learning objective c. I know this
G'Day Programmers, I am from Java background however I have just started learning C++
I'm one day into learning JQuery and have a question about the octothorpe syntax.
My big problem here is that I'm 1 day into learning MacOSX so the
I am having a 'learning' day and am delving into an ASP.NET solution to
G'day all, After learning on here that the Java console doesn't support keyboard input
I'm one day into learning ASM and I've done a few tutorials, and even
I am into day 5 of learning c#, and am trying to figure out
I've been learning SQL for about a day now and I've run into a
I did some all day learning and I figured out how to add rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.