Dword DrawBarcode(Hdc DC,WCHAR* TEXT,WCHAR* Starstopchar,Wchar* facename,Wchar* buffer,Rect* bounds,RECT* barcodematrix,int textwidth,int texheight,int textbobarcode,int textquiezone,int barinflate,Dword color,Dword params)
DoResult = DrawBarcode(0 , L"692345065618", L"A>", L"Arial",
NULL, &rect, Matrix, 8, 24, 4, 24, 0, 0, Params);
vc 调用的参数
DWORD Params = 0x00731000 | (DWORD)NamesList.GetCurSel();// 1-35正整数
SetRect(&rect, 10, 10, 288, 144);
dc.FillSolidRect(rect,RGB(255,255,255));
RECT Matrix[512];
OffsetRect(&rect, 0, 144);
C#
???
[DllImport("Barcode.dll", CharSet = CharSet.Unicode)]
private static extern StringBuilder DrawBarcode(
DC_Rect hdc,
StringBuilder text,
StringBuilder starcode,
StringBuilder facename,
StringBuilder buffer,
Bound_Rect b_rect,
Barcodematrix btrix_rect,
int textwidth,
int texheight,
int textbobarcode,
int textquiezone,
int barinflate,
uint color,
StringBuilder para);
DC_Rect rec_dc = new DC_Rect();
rec_dc.Left = 0;
rec_dc.Right = 0;
rec_dc.Top = 1;
rec_dc.Bottom = 0;
StringBuilder sb_text= new StringBuilder();
sb_text.Append("23432432432");
StringBuilder sb_starcode= new StringBuilder();
sb_starcode.Append(">");
StringBuilder sb_facename= new StringBuilder();
sb_facename.Append("Arial");
StringBuilder sb_buffer= new StringBuilder();
Bound_Rect bound_dc = new Bound_Rect();
bound_dc.Left = 0;
bound_dc.Right = 0;
bound_dc.Top = 1;
bound_dc.Bottom = 0;
Barcodematrix matrix_dc = new Barcodematrix();
matrix_dc.Left = 0;
matrix_dc.Right = 0;
matrix_dc.Top = 1;
matrix_dc.Bottom = 0;
StringBuilder para= new StringBuilder();
para = TranslateStrTo16(18);
try
{
StringBuilder r = DrawBarcode(rec_dc, sb_text, sb_starcode, sb_facename, null, bound_dc, matrix_dc, 8, 24, 4, 24, 0, 0, para);
}
catch (Exception ex)
{ throw ex; }
StringBuilder TranslateStrTo16(int str)
{
StringBuilder resultstr=new StringBuilder() ;
string _s = Convert.ToString(str, 16);
char[] values = _s.ToCharArray();
char[] _values = "0x00731000".ToCharArray();
foreach (char letter in _values)
{
resultstr.Append(letter);
}
int b = 0;
foreach (char letter in values)
{
resultstr.Append(letter);
}
return resultstr;
}
报错
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
------解决思路----------------------
尝试读取受保护的内存。。。
是不是编码错误?
------解决思路----------------------
大多数情况是数据类型转换的原因...
------解决思路----------------------
using DWORD = Int32;
using HDC = Int32;
using LPWSTR = String;
using LPRECT = Rectangle;
public partial class X32
{
[DllImport("Barcode.dll", CharSet = CharSet.Unicode)]
static extern DWORD DrawBarcode(
HDC hDc,
[MarshalAs(UnmanagedType.LPWStr
------解决思路----------------------
UnmanagedType.VBByRefStr)] ref LPWSTR TEXT,
[MarshalAs(UnmanagedType.LPWStr
------解决思路----------------------
UnmanagedType.VBByRefStr)] ref LPWSTR Starstopchar,
[MarshalAs(UnmanagedType.LPWStr
------解决思路----------------------
UnmanagedType.VBByRefStr)] ref LPWSTR facename,
[MarshalAs(UnmanagedType.LPWStr
------解决思路----------------------
UnmanagedType.VBByRefStr)] ref LPWSTR buffer,
ref LPRECT bounds,
ref LPRECT barcodematrix,
int textwidth,
int texheight,
int textbobarcode,
int textquiezone,
int barinflate,
DWORD color,
DWORD @params
);