AllExperts > Experts 
Search      

C#

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More C# Answers
Question Library

Ask a question about C#
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Srini Nagarajan
Expertise
can answer any kind of questions in ASP.NET, C#, VB.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience
Contact me if you need any custom development on ASP.NET, ASP, Coldfusion, Powerbuilder
 
   

You are here:  Experts > Computing/Technology > C/C++ > C# > C Data Structure in C#

Topic: C#



Expert: Srini Nagarajan
Date: 10/19/2005
Subject: C Data Structure in C#

Question
I have a DLL that is written in C. I have to use it from within C# code.

Some of the available DLL functions must be implemented as callbacks. This means that when a given DLL function is called from C# managed code, the DLL unmanaged code will "callback" a method implemented in C# managed code.

For this purpose I have managed to use C# delegates with sucess for simple String datatypes (in C that would be a char *).

For example, the following code works just fine:

// Delegate
public delegate int OnCodeLine(String codeline);
[DllImport(DLL)]
private static extern int rdOnCodeLine(OnCodeLine codeline);

// Install the callback
public void Callback()
{
   OnCodeLine codeline = new OnCodeLine OnCodeLineImplementation);
   int rtnval = rdOnCodeLine(codeline);
}

// Implement the callback
public int OnCodeLineImplementation(String codeline)
{
   System.Console.WriteLine("Codeline Debug: " + codeline);
   return 1;
}

Things get out of hand when a given callback implementation must access a C complex data structure (defined has a struct).

The callback in question returns to the managed code a pointer to a data structure.

How can I acess the data stored inside the C data structure?

Please, if you require any detailed code just let me know.

Regards.

Joćo


Answer
Hi

I haven't really worked with Unsafe/Unmanaged code interact with C#

May be this article will help you on this..

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

Happy programming!!

-srini

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.