?
Solved

Working with C dll

Posted on 2005-04-12
1
Medium Priority
?
214 Views
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 c#.net 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++ c#.net 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 c#.net.

      public class Win32
      {
            
            [DllImport("Caspian1.dll")]
            public static extern string test();
               }


textBox4.Text = Win32.test();


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

Accepted Solution

by:
novitiate earned 1000 total points
ID: 13769818
I guess you have to use CharSet

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

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconCharSetObjectField.asp

_novi_
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses

864 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