C++的dll
1.1 BOOL InitBCDll()当要dll库中的其它条码接口之前,应先调用此函数,它初始化了一些库中的变量。
1.2 BOOL SetBCBaseParam(BASEOPTIONS * pBaseOption)
1.3 BOOL SetBCEachParam(void * pEachOption, int nType)
1.4 void * GetImagePtr()
1.5 BITMAPFILEHEADER* GetBitmapFileHeader()
1.6 BITMAPINFO * GetBitmapInfo()
2.1 BASEOPTIONS
struct BASEOPTIONS 
{
int  nBCStyle;      
BYTE *  lpszBCData; 
Int   nLens;
int  nPrinterDpi;
FontStruct  szFont; 
BOOL  bStandard;
BYTE  Reversed[10]; 
}
-------------------------------------------
C#部分我翻译的
public struct QRCODEOPTIONS
        {
            public int Ecp;//说明:设置QR条码的纠错级别。值:默认值为0,取值范围0到3。
            public int MaskNumber;//说明:设置QR条码的掩模号。值:默认值:0,取值范围0-8,8代表自动设置掩模。
            public int ModuleWidth;//设置QR条码的单模块宽度。值:默认值:20(Dots),取值范围 1到500。
        };
        //字体结构 
       public struct FontStruct
        {
            int nHeight;               // height of font   
            int nWidth;                // average character width
            int nEscapement;           // angle of escapement
            int nOrientation;          // base-line orientation angle
            int fnWeight;              // font weight
            UInt32 fdwItalic;           // italic attribute option
            UInt32 fdwUnderline;        // underline attribute option
            UInt32 fdwStrikeOut;        // strikeout attribute option
            UInt32 fdwCharSet;          // character set identifier
            UInt32 fdwOutputPrecision;  // output precision
            UInt32 fdwClipPrecision;    // clipping precision
            UInt32 fdwQuality;          // output quality
            UInt32 fdwPitchAndFamily;   // pitch and family
            string lpszFace;          // typeface name
        };
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
       public struct BASEOPTIONS
        {
        public int nBCStyle;           //条码类型,依据宏定义 
            public IntPtr lpszBCData;      //存放数据信息
            public int nLens;     //信息的长度
            public int nPrinterDpi; //打印机dpi
        FontStruct szFont;      //字体结构 
            public bool bStandard; //是否采用国标
            public byte[] Reversed;  //预留,现用于标记是否非标码,以及非标码的状态
        };         [DllImport("NLSCodeMid.dll", CharSet = CharSet.Auto)]
        public static extern bool InitBCDll();
        bool bRet =InitBCDll();
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Ansi)]
        public static extern bool SetBCBaseParam(out IntPtr pBaseOption);
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Ansi)]
        public static extern bool SetBCEachParam(IntPtr pEachOption, int nType);
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr GetImagePtr();
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Auto)]        public static extern string BCGetLastError();
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Auto)]        public static extern bool GenBarCode();
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Auto)]
        public static extern bool FreeMemory();
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Auto)]
        public static extern bool Rotary(int nDegrees);
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Auto)]
        public static extern bool SaveTo(string szFile, string szImageType);
        [DllImport("NLSCodeMid.dll", CharSet = CharSet.Auto)]
        public static extern int GetBCLastError();
 private void button1_Click(object sender, EventArgs e)
        {
            BASEOPTIONS option=new BASEOPTIONS();
            QRCODEOPTIONS QRCODE = new QRCODEOPTIONS();
            IntPtr entryPtrs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BASEOPTIONS)));
           // Marshal.StructureToPtr(option, entryPtrs, true);
            IntPtr entryPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(QRCODEOPTIONS)));
             Marshal.StructureToPtr(QRCODE, entryPtr, true);
           // IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LVITEM)));
            option.nBCStyle =1;
            /*base.nBCStyle = _PDF417; //设置条码类型
base.lpszBCData =(BYTE*)( m_strBCData.GetBuffer(m_strBCData.GetLength())); //设置条码的数据
base.nLens = m_strBCData.GetLength(); //设置条码数据长度
base.bStandard = FALSE; //设置是否以国标为准则,对于二维码,这个参数可不设
base.nPrinterDpi = 1000; //设置条码的打印机DPI*/
            //  option.lpszBCData =(byte*)(this.textBox1.GetBuffer(m_strBCData.GetLength())); Marshal.StringToHGlobalAuto
            option.lpszBCData = Marshal.StringToHGlobalAuto(this.textBox1.Text.ToString());
            option.nLens = this.textBox1.Text.Length;
            option.bStandard = false;
            option.nPrinterDpi = 1000;
            QRCODE.Ecp = 0;
            QRCODE.MaskNumber = 0;
            QRCODE.ModuleWidth = 20;
            SetBCBaseParam(out entryPtrs);
            SetBCEachParam(entryPtr, 1);            if (!GenBarCode())
            {
                MessageBox.Show("生成出错");
                int error = 0;
                error = GetBCLastError();
                return;
            }
            Marshal.FreeHGlobal(entryPtrs);
            Marshal.FreeHGlobal(entryPtr);
        }
--------------------------------------------------
感谢高手帮帮忙啊..orz不然要收拾回家了.5555

解决方案 »

  1.   

    FontStruct是啥东西?BASEOPTIONS 不对
          public struct BASEOPTIONS 
            { 
            public int nBCStyle;          //条码类型,依据宏定义 
                public IntPtr lpszBCData;      //存放数据信息 
                public int nLens;     //信息的长度 
                public int nPrinterDpi; //打印机dpi 
              FontStruct szFont;      //字体结构 
                public int bStandard; //是否采用国标 
                [ MarshalAs( UnmanagedType.ByValArray, SizeConst=10 )]             public byte[] Reversed;  //预留,现用于标记是否非标码,以及非标码的状态 
            }; 
      

  2.   


    public static extern bool SetBCBaseParam(ref BASEOPTIONS pBaseOption); 
      

  3.   

    FontStruct是设置字体的,那个没关系的.
      

  4.   

    1.3 BOOL SetBCEachParam(void * pEachOption, int nType) 
    1.4 void * GetImagePtr() 这两个俺都不会咧
      

  5.   

    Reversed字段定义的不对,应该[ MarshalAs( UnmanagedType.ByValArray, SizeConst=10 )] 
      

  6.   

    void *用IntPtr来对应就可以了
      

  7.   

     BASEOPTIONS option=new BASEOPTIONS(); 
                QRCODEOPTIONS QRCODE = new QRCODEOPTIONS(); 
                IntPtr entryPtrs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BASEOPTIONS))); 
              // Marshal.StructureToPtr(option, entryPtrs, true); 
                IntPtr entryPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(QRCODEOPTIONS))); 
                Marshal.StructureToPtr(QRCODE, entryPtr, true); 
              // IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LVITEM))); 
                option.nBCStyle =1; 
                /*base.nBCStyle = _PDF417; //设置条码类型 
    base.lpszBCData =(BYTE*)( m_strBCData.GetBuffer(m_strBCData.GetLength())); //设置条码的数据 
    base.nLens = m_strBCData.GetLength(); //设置条码数据长度 
    base.bStandard = FALSE; //设置是否以国标为准则,对于二维码,这个参数可不设 
    base.nPrinterDpi = 1000; //设置条码的打印机DPI*/ 
                //  option.lpszBCData =(byte*)(this.textBox1.GetBuffer(m_strBCData.GetLength())); Marshal.StringToHGlobalAuto 
                option.lpszBCData = Marshal.StringToHGlobalAuto(this.textBox1.Text.ToString()); 
                option.nLens = this.textBox1.Text.Length; 
                option.bStandard = false; 
                option.nPrinterDpi = 1000; 
                QRCODE.Ecp = 0; 
                QRCODE.MaskNumber = 0; 
                QRCODE.ModuleWidth = 20; 
                SetBCBaseParam(out entryPtrs); 
                SetBCEachParam(entryPtr, 1); ------------------------------
    我这段代码总是不行..
      

  8.   

    int SetBCEachParam(IntPtr pEachOption,int nType) 
    IntPtr GetImagePtr();
      

  9.   

    BASEOPTIONS option=new BASEOPTIONS(); 
                QRCODEOPTIONS QRCODE = new QRCODEOPTIONS(); 
                IntPtr entryPtrs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BASEOPTIONS)));             IntPtr entryPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(QRCODEOPTIONS))); 
                Marshal.StructureToPtr(QRCODE, entryPtr, true);             option.nBCStyle =1; 
                
                option.lpszBCData = Marshal.StringToHGlobalAuto(this.textBox1.Text.ToString()); 
                option.nLens = this.textBox1.Text.Length; 
                option.bStandard = false; 
                option.nPrinterDpi = 1000; 
                QRCODE.Ecp = 0; 
                QRCODE.MaskNumber = 0; 
                QRCODE.ModuleWidth = 20; 
                SetBCBaseParam(out entryPtrs); 
                SetBCEachParam(entryPtr, 1); 
      

  10.   

     private void button1_Click(object sender, EventArgs e)的东西..咋整的呢..哎呀..初次接触这个东西.今天上司还催了.急坏了
      

  11.   

    http://msdn.microsoft.com/zh-cn/library/sd10k43k.aspx
    自己查去
      

  12.   

    SetBCEachParam(IntPtr pEachOption,int nType) 
    IntPtr pEachOption:参数是什么样的啊.我没找到..