[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • 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
      {
            
            
            
            [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.
0
CURRYFREE1983
Asked:
CURRYFREE1983
1 Solution
 
rajaloysiousCommented:
Check if this helpful...
you should be using char for c type char
http://www.thecodeproject.com/dotnet/PInvoke.asp

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

cheers
0
 
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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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