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

Posted on 2005-04-07
Last Modified: 2010-04-16
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 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 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.
Question by:CURRYFREE1983
    LVL 8

    Accepted Solution

    Check if this helpful...
    you should be using char for c type char

    Also see the site:
    Go to the bottom... there it talks about char* and c# handling of a windows dll which is verymuch like your c dll


    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now