locked
Dll import in c# RRS feed

  • Question

  • Any one can show a simple example which describe 

    a method implemented in c++ saved in a dll

    call method in c#using dllimport?

    what are the project type in c++ to make a dll?

    in c# i want to use Console application.

    i need to pass one int parameter through the method please help me...



    please

    Wednesday, August 15, 2012 10:12 AM

Answers

  •         [System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
            private static extern System.IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
            [System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
            private static extern bool DeleteObject(System.IntPtr hObject);

    To call:

    System.IntPtr ptrBorder = CreateRoundRectRgn(0, 0, this.Width, this.Height, _BorderRadius, _BorderRadius);
    
    DeleteObject(ptrBorder);

    You want to use a class library project for your dll.
    • Edited by Steven_Schultz Wednesday, August 15, 2012 10:25 AM
    • Proposed as answer by Lisa Zhu Thursday, August 16, 2012 2:07 AM
    • Marked as answer by Lisa Zhu Tuesday, August 21, 2012 10:31 AM
    Wednesday, August 15, 2012 10:22 AM

All replies

  • Wednesday, August 15, 2012 10:20 AM
  •         [System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
            private static extern System.IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
            [System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
            private static extern bool DeleteObject(System.IntPtr hObject);

    To call:

    System.IntPtr ptrBorder = CreateRoundRectRgn(0, 0, this.Width, this.Height, _BorderRadius, _BorderRadius);
    
    DeleteObject(ptrBorder);

    You want to use a class library project for your dll.
    • Edited by Steven_Schultz Wednesday, August 15, 2012 10:25 AM
    • Proposed as answer by Lisa Zhu Thursday, August 16, 2012 2:07 AM
    • Marked as answer by Lisa Zhu Tuesday, August 21, 2012 10:31 AM
    Wednesday, August 15, 2012 10:22 AM