Windows XP style Explorer Bar使用问题说明

在VS2005中使用CodeProject上的XPExplorerBar项目时,遇到PInvokeStackImbalance错误,原因是C#中long与WinAPI中long的数据长度不匹配。解决办法是将NativeMethods.LoadBitmap方法中的long参数改为int。此问题在VS2003中未被捕捉,但在VS2005中必须处理。提供了解决方案的详细步骤和相关参考资料链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要想在vs2005中实现这样的效果,是没有相应的组件的,我使用的是codeproject

Mathew Hall上的Windows XP style Explorer Bar  将XPExplorerBar.dll添加到工具箱后,在使用时

但是会出现如下错误:

in visual studio 2005:
PInvokeStackImbalance was detected
Message: A call to PInvoke function 'XPExplorerBar!XPExplorerBar.NativeMethods::LoadBitmap' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

the error is raised in the following line in GetResourceBMP method
IntPtr hBitmap = NativeMethods.LoadBitmap(hModule, Int32.Parse(resourceName));

 

这是由于winAPI中的long是32位,C#long是64位,生成可以成功,但是在执行后当然会出现堆栈不平衡的问题,在 vs2003中是捕获不出来的,但是在vs2005中是必须要处理的。

解决方法:

NativeMethods.cs中将

static extern IntPtr LoadBitmap(IntPtr hInstance, long resourceID)

中的long  换为int再重新生成即可。

我已经生成好.dll 文件并发布到我的资源里。

 

如有问题大家可以给我发邮件。

 

下载地址:

http://www.codeproject.com/cs/miscctrl/XPTaskBar.asp?select=1931404&df=100&forumid=55377#__comments

 

参考网站:

http://pinvoke.net/default.aspx/user32.LoadBitmap

.NET1.1升级到.NET2.0时出现的PInvokeStackImbalance错误

http://blog.youkuaiyun.com/virlene/archive/2006/05/29/761412.aspx

http://www.cnblogs.com/jillzhang/archive/2007/03/05/664657.aspx

 

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值