Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. LOGFONT in C#

LOGFONT in C#

Scheduled Pinned Locked Moved C#
csharpc++help
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VCsamir
    wrote on last edited by
    #1

    Hi friends & seniors, i have a Vc++ dll in which i return a struct of LOGFONT menbers

    struct xyzStruct
    {
    LOGFONT a;
    }

    extern "c" __dllspec ... xyzStruct a()

    this data is populated in vc++ dll and passed to a C# form in the C# side i have created

    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
    public class LOGFONT
    {
    public int lfHeight = 0;
    public int lfWidth = 0;
    public int lfEscapement = 0;
    public int lfOrientation = 0;
    public int lfWeight = 0;
    public byte lfItalic = 0;
    public byte lfUnderline = 0;
    public byte lfStrikeOut = 0;
    public byte lfCharSet = 0;
    public byte lfOutPrecision = 0;
    public byte lfClipPrecision = 0;
    public byte lfQuality = 0;
    public byte lfPitchAndFamily = 0;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
    public string lfFaceName = string.Empty;
    }

    then i make pinvoke to the DLL

    [StructLayout(LayoutKind.Sequential)]
    public class xyzStruct
    {
    public lOGFONT a;
    }
    [dllImport ("Dll name")]
    public static extern xyzStruct a();

    i get error "methods signature is not pinvoke comaptible" i try using int in struct in both dll and form everything works fine. thanks in advance Regards Samir

    _ R 2 Replies Last reply
    0
    • V VCsamir

      Hi friends & seniors, i have a Vc++ dll in which i return a struct of LOGFONT menbers

      struct xyzStruct
      {
      LOGFONT a;
      }

      extern "c" __dllspec ... xyzStruct a()

      this data is populated in vc++ dll and passed to a C# form in the C# side i have created

      [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
      public class LOGFONT
      {
      public int lfHeight = 0;
      public int lfWidth = 0;
      public int lfEscapement = 0;
      public int lfOrientation = 0;
      public int lfWeight = 0;
      public byte lfItalic = 0;
      public byte lfUnderline = 0;
      public byte lfStrikeOut = 0;
      public byte lfCharSet = 0;
      public byte lfOutPrecision = 0;
      public byte lfClipPrecision = 0;
      public byte lfQuality = 0;
      public byte lfPitchAndFamily = 0;
      [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
      public string lfFaceName = string.Empty;
      }

      then i make pinvoke to the DLL

      [StructLayout(LayoutKind.Sequential)]
      public class xyzStruct
      {
      public lOGFONT a;
      }
      [dllImport ("Dll name")]
      public static extern xyzStruct a();

      i get error "methods signature is not pinvoke comaptible" i try using int in struct in both dll and form everything works fine. thanks in advance Regards Samir

      _ Offline
      _ Offline
      _Erik_
      wrote on last edited by
      #2

      Make your method in the C++ library return a pointer to a LOGFONT instead, import the method in C# with IntPtr as return type and use Marshal.PtrToStructure to get the structure in C#.

      1 Reply Last reply
      0
      • V VCsamir

        Hi friends & seniors, i have a Vc++ dll in which i return a struct of LOGFONT menbers

        struct xyzStruct
        {
        LOGFONT a;
        }

        extern "c" __dllspec ... xyzStruct a()

        this data is populated in vc++ dll and passed to a C# form in the C# side i have created

        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
        public class LOGFONT
        {
        public int lfHeight = 0;
        public int lfWidth = 0;
        public int lfEscapement = 0;
        public int lfOrientation = 0;
        public int lfWeight = 0;
        public byte lfItalic = 0;
        public byte lfUnderline = 0;
        public byte lfStrikeOut = 0;
        public byte lfCharSet = 0;
        public byte lfOutPrecision = 0;
        public byte lfClipPrecision = 0;
        public byte lfQuality = 0;
        public byte lfPitchAndFamily = 0;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
        public string lfFaceName = string.Empty;
        }

        then i make pinvoke to the DLL

        [StructLayout(LayoutKind.Sequential)]
        public class xyzStruct
        {
        public lOGFONT a;
        }
        [dllImport ("Dll name")]
        public static extern xyzStruct a();

        i get error "methods signature is not pinvoke comaptible" i try using int in struct in both dll and form everything works fine. thanks in advance Regards Samir

        R Offline
        R Offline
        RaviRanjanKr
        wrote on last edited by
        #3

        Please Reformat your code to make it readability use Code-Block to Wrap your code. :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups