Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have created one application in VC++ which creates bitmap data according to Text
and I have exported the function from VC++ dll.

In C#, i am accessing this function by using DllImport
I want to pass LOGFONT structure as a parameter to VC++ application through C#.

How can i pass this?

Please Refer to Code sample
VC++
C++
Exported Function looks like this
void MyDllMethod(BYTE *pbByteArray,char* a_sMessage,int a_eHorizontalAllignment, bool a_bDrawVertical,LOGFONT m_winLogFont);


c#
LOGFONT structure is defined as
C#
public struct LOGFONT
    {
        public int lfHeight;
        public int lfWidth;
        public int lfEscapement;
        public int lfOrientation;
        public int lfWeight;
        public byte lfItalic;
        public byte lfUnderline;
        public byte lfStrikeOut;
        public byte lfCharSet;
        public byte lfOutPrecision;
        public byte lfClipPrecision;
        public byte lfQuality;
        public byte lfPitchAndFamily;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string lfFaceName;

        public LOGFONT(bool test)
        {
            lfHeight = 0;
            lfWidth = 0;
            lfEscapement = 0;
            lfOrientation = 0;
            lfWeight = 0;
            lfItalic = 0;
            lfUnderline = 0;
            lfStrikeOut = 0;
            lfCharSet = 0;
            lfOutPrecision = 0;
            lfClipPrecision = 0;
            lfQuality = 0;
            lfPitchAndFamily = 0;
            lfFaceName = "Arial";
        }
    }

[DllImport("Bitmap Creation.dll", EntryPoint = "MyDllMethod", ExactSpelling = false,CallingConvention = CallingConvention.Cdecl)]

public static extern void MyDllMethod(IntPtrbyteArray,                                               [MarshalAs(UnmanagedType.LPStr)]string message,
           int a_eHorizontalAllignment, bool a_bDrawVertical,LOGFONT a_logFont);

But in VC++ application, I am getting some garbaouge values in LOGFONT structure.
Please Help..... waiting for your reply...
Posted
Updated 13-Jun-12 20:14pm
v4

Have your tryed to put a class instead of "Enum" :
C#
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
       public class LOGFONT


Take a look at this link, may be it can help you
http://www.pinvoke.net/default.aspx/Structures/LOGFONT.html[^]
 
Share this answer
 
I think you need to use the StructLayoutAttribute[^] class, to ensure the LOGFONT elements are positioned exactly the same as the C++ structure.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900