• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

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
            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.
1 Solution
Check if this helpful...
you should be using char for c type char

Also see the site: http://www.csharphelp.com/archives/archive52.html
Go to the bottom... there it talks about char* and c# handling of a windows dll which is verymuch like your c dll

CURRYFREE1983Author Commented:
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.
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now