Working with C dll

Posted on 2005-04-12
Last Modified: 2012-05-05
I have an apllication that has been written as a dos based command driven interface in c code.  I am trying to redesign the interface within the .net environment.  I have created a dll with the existing c source code and have exported the necessary functions that I need to interact with the interface.  I was using for testing if I could pass between the dll and the new interface.  Integers are passing find but I am having problems with the strings as c defines these as chars and c++ refer to them as string types.  I was hope to pass these as values, but maybe it would be possible using pointers?

Below shows some of the coding I have tried in

      public class Win32
            public static extern string test();

textBox4.Text = Win32.test();

Any advice at all would be greatly appreciated.
Question by:CURRYFREE1983
    1 Comment
    LVL 8

    Accepted Solution

    I guess you have to use CharSet

    [DllImport("dllname", CharSet=CharSet.Ansi)]
    [DllImport("dllname", CharSet=CharSet.Unicode)]
    [DllImport("dllname", CharSet=CharSet.Auto)]
    [DllImport("dllname", CharSet=CharSet::Ansi)]
    [DllImport("dllname", CharSet=CharSet::Unicode)]
    [DllImport("dllname", CharSet=CharSet::Auto)]


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

    732 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

    17 Experts available now in Live!

    Get 1:1 Help Now