Using c library in C#

This is a discussion on Using c library in C# within the C# Programming forums, part of the General Programming Boards category; First of all, I'm an absolute C# newbie. But I want to start using the language for development. My question ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059

    Using c library in C#

    First of all, I'm an absolute C# newbie. But I want to start using the language for development. My question is, Can I use a library written for C in C#? If so, can someone provide a simple example on how to do this?

    Thanx

    Bob

  2. #2
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    http://msdn.microsoft.com/library/de...ClassTopic.asp

    Example:
    Code:
    using System;
    using System.Runtime.InteropServices;
    
    namespace TextColor
    {
        class MainClass
        {
            [DllImport("kernel32.dll")]
            public static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, int wAttributes);
            [DllImport("kernel32.dll")]
            public static extern IntPtr GetStdHandle(uint nStdHandle);
    
            public static void Main(string[] args)
            {
                uint STD_OUTPUT_HANDLE = 0xfffffff5;
                IntPtr hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
                for (int k = 1; k < 255; k++)
                {
                    SetConsoleTextAttribute(hConsole, k);
                    Console.WriteLine("{0:d3}  http://www.cprogramming.com", k);
                }
                SetConsoleTextAttribute(hConsole, 236);
    
                Console.WriteLine("Press Enter to exit ...");
                Console.Read();
            }
        }
    }

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    BMJ,

    Thanx for the example

    Bob

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. better c string functions
    By samps005 in forum C Programming
    Replies: 8
    Last Post: 11-04-2003, 12:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21