Link to home
Start Free TrialLog in
Avatar of CURRYFREE1983
CURRYFREE1983

asked on

Problems calling an unmanaged DLL written in c from a C#.net interface.

I am redesigning an interface of an existing application with a command driven interface that is written in C.  I am designing the new front end using c#.net to improve the interface with button's and menu's.  I have the source code for the original program and am happy to keep the existing functionality.  I have set up the c code as a DLL and exported a few test functions from it so I can interact with my interface.  The integer values passing from the front end to the DLL and back again with no problem.  I need to pass strings to the DLL to replace the existing drag and drop method of loading with a file open menu.  This generates errors as the types in c are defined as char and I haven't figured out how to pass these suceesfully.

Here is the C#.net code I have tried so far.

private void button5_Click(object sender, System.EventArgs e)
            {

                  string filename;
                  filename = "Testing";
                  textBox5.Text = Win32.testin(filename).ToString();

            }

public class Win32
      {
            
            
            
            [DllImport("Caspian1.dll",CharSet=CharSet.Auto)]
            public static extern string testin(string var1);


      }

Here is the c DLL code

char testin(char var2)
{

      char var3 = var2;
                char var4 = "Test Back";

      return var4;
}

Help would be greatly appreaciated.
ASKER CERTIFIED SOLUTION
Avatar of rajaloysious
rajaloysious

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CURRYFREE1983
CURRYFREE1983

ASKER

Been trying to work through those examples but hard to match up to my situation.  Not sure about pointers as skills a bit limited.  Any actual examples would be a help.