解决方案 »
- 我做了类似资源管理器界面,右边是listView显示文件,现在我对listView的双击后,图片自动用我安装的AcdSee编辑器打开了,我能否不让它打开,让其它
- 100分求解:winForm+webservice+sql2000怎样统计在线人数?
- outlookBar的问题,做过的请进
- 做了一个程序,由于运行时间较长,麻烦大了……帮忙看看
- 请问你们谁有Visual Studio .NET 2003 中文专业版(简体)
- Datatable.InsertAt(row,pos) 问题???
- 急,一个小问题??
- 如果用.NET开发ORACLE的程序呢?
- 在mdi中如何实现子窗体只有一个实例?
- 为什么ListBox没有复选框?
- 关于使用notifyIcon问题
- 用c#判断矩形
FillBuffer(ii, bsize,255);
Marshal.FreeHGlobal(ii);code]这样调用
FillBuffer(ii, bsize,255);
Marshal.FreeHGlobal(ii);
你声明dll函数时调用规则填的什么?
DllImport默认的是WinApi (StdCall)
而VC++不明确指出的话默认的就是cdecl.
如果声明错了除了无参数的函数外肯定是要出错的.
//IntPtr ubuffer = Win32.GlobalAlloc(Win32.GMEMFlag.GMEM_FIXED | Win32.GMEMFlag.GMEM_ZEROINIT, bsize);
//IntPtr ubuffer = Marshal.AllocHGlobal(bsize);
GCHandle hbuffer = GCHandle.Alloc(mbuffer, GCHandleType.Pinned);
那就是DLL导出的方式不是StdCall了,是cdecl,你既然有DLL源码,调试DLL的时候就会发现DLL中函数得到的参数恰好是倒序的
无法在 DLL“DynamicDLL.dll”中找到名为“FillBuffer”的入口点。
// 保存快照数据到相应的缓冲区
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASaveBitsToBuf")]
//public static extern bool VCASaveBitsToBuf(Int32 dwCard, IntPtr pDestBuf, ref Int32 dwWidth, ref Int32 dwHeight);
public static extern bool VCASaveBitsToBuf(Int32 dwCard, byte[] pDestBuf, ref Int32 dwWidth, ref Int32 dwHeight);
调用这样写:
byte[] mbuffer = new byte[bsize];
ret = VideoAPI.VCASaveBitsToBuf(frm.DevCur, mbuffer, ref Width, ref Height);仍然出现同样的错误。
//public static extern bool VCASaveBitsToBuf(Int32 dwCard, IntPtr pDestBuf, ref Int32 dwWidth, ref Int32 dwHeight);
public static extern bool VCASaveBitsToBuf(Int32 dwCard, byte[] pDestBuf, ref Int32 dwWidth, ref Int32 dwHeight);
这样才是Cdecl的,你有这样试过没?
我是这样写的:
byte[] mbuffer = new byte[bsize];
unsafe
{
fixed (byte* ubuffer = &mbuffer[0])
{
ret = VideoAPI.VCASaveBitsToBuf(frm.DevCur, ubuffer, ref Width, ref Height);
}
}
希望能通过……都快要绝望了……
DWORD dwHeight = dlgVC->m_dwHeight;
unsigned char *pbuffer = new unsigned char[dwWidth * dwHeight * 3];//RGB24
ret = VCASaveBitsToBuf(dlgVC->m_iCard, pbuffer,dwWidth, dwHeight);
// 保存快照数据到相应的缓冲区
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASaveBitsToBuf", CallingConvention=CallingConvention.Cdecl)]
public static extern bool VCASaveBitsToBuf(Int32 dwCard, IntPtr pDestBuf, ref Int32 dwWidth, ref Int32 dwHeight);
还是同样的错误。
public static extern bool VCASaveBitsToBuf(int dwCard, byte[] pDestBuf, ref int dwWidth, ref int dwHeight);
试试.
上面注明WINAPI了,使用默认的StdCall
public static extern bool VCASaveBitsToBuf(uint dwCard, byte[] pDestBuf, ref uint dwWidth, ref uint dwHeight);
换成无符号的调试时你将dwWidth,dwHeight都设为1,看pDestBuf的长度要为多少才不报错?确定下是不是要为3*1*1?