打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c#调用进程外Com组件Intptr参数问题
1.最近在解决64位应用程序调用32位dll的问题,想使用进程外Com来解决,编写了相应的Demo,当接口方法的参数是string或int时程序都能正常运行,但接口方法的参数含有IntPtr类型时程序报错
2.接口方法: public void TestPtr(IntPtr p)
{
MessageBox.Show("1111111111");
}

外部调用:
System.Type t = Type.GetTypeFromProgID("TestComServer.TestComVisibleClass");
dynamic o = Activator.CreateInstance(t);
string iCameraID = txtCameraIndexCode.Text;//"12345678001310000017";
System.IntPtr ptrCertFile = Marshal.StringToBSTR(iCameraID);
o.TestPtr(ptrCertFile);
3.报错内容
未处理System.InvalidCastException
  _HResult=-2147467262
  _message=OleAut 报告了类型不匹配。
  HResult=-2147467262
  IsTransient=false
  Message=OleAut 报告了类型不匹配。
  RemoteStackTrace=   在 Microsoft.Win32.OAVariantLib.ChangeTypeEx(Variant& result, Variant& source, Int32 lcid, IntPtr typeHandle, Int32 cvType, Int16 flags)
   在 Microsoft.Win32.OAVariantLib.ChangeType(Variant source, Type targetClass, Int16 options, CultureInfo culture)
   在 System.OleAutBinder.ChangeType(Object value, Type type, CultureInfo cultureInfo)
   在 System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
   在 System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   在 System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   在 System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

  Source=mscorlib
  StackTrace:
       在 Microsoft.Win32.OAVariantLib.ChangeTypeEx(Variant& result, Variant& source, Int32 lcid, IntPtr typeHandle, Int32 cvType, Int16 flags)
       在 Microsoft.Win32.OAVariantLib.ChangeType(Variant source, Type targetClass, Int16 options, CultureInfo culture)
       在 System.OleAutBinder.ChangeType(Object value, Type type, CultureInfo cultureInfo)
       在 System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
       在 System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
       在 System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
       在 System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       在 System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
       在 CallSite.Target(Closure , CallSite , ComObject , IntPtr )
       在 System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
       在 CallSite.Target(Closure , CallSite , Object , IntPtr )
       在 System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
       在 TestDeviceSDK.MainForm.button5_Click(Object sender, EventArgs e) 位置 c:\TestComServer\新建文件夹\Test8300SDK\MainForm.cs:行号 160
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 TestDeviceSDK.Program.Main() 位置 c:\TestComServer\新建文件夹\Test8300SDK\Program.cs:行号 16
       在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

请各位大神帮忙解决,谢谢
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#模拟键盘鼠标事件 - 护马 - 博客园
关于程序正常运行一断时间后,进行任何操作,都可能内存溢出问题的解决,谢谢。
C Sharp与.net学习笔记(二)
(C#)利用反射动态调用类成员-程序开发-红黑联盟
关于 c#把word文档转换成html后取出html文件中的内容的问题【中国IT软件知识库...
griddata 绑定根据字段得到想要的结果,如 根据状态不同显示不用的图片
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服