c# com object cant get ref object values

0

We are trying to get values returned from a COM object, the function is:

bool AxSB100BPC.GetEnrollData(int dwMachineNumber,
int dwEnrollNumber,
int dwEMachineNumber,
int dwBackupNumber,
ref int dwMachinePrivilege,
ref object dwEnrollData,
ref int dwPassWord

We are calling this function as:

vRet = axSB100BPC1.GetEnrollData(mMachineNumber,
                                 vEnrollNumber,
                                 vEMachineNumber,
                                 vFingerNumber,
                                 ref vPrivilege,
                                 ref oglngEnrollData,
                                 ref glngEnrollPData);

The problem is with oglngEnrollData which is type of ref object. It is declared as object oglngEnrollData;.

The error is:

System.Runtime.InteropServices.COMException was unhandled
HResult=-2147352571
Message=Tür uyuşmazlığı. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
Source=mscorlib
ErrorCode=-2147352571
StackTrace:
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName,           BindingFlags          flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at SB100BPCLib._DSB100BPC.GetEnrollData(Int32 dwMachineNumber, Int32 dwEnrollNumber, Int32 dwEMachineNumber, Int32 dwBackupNumber, Int32& dwMachinePrivilege, Object& dwEnrollData, Int32& dwPassWord)
   at AxSB100BPCLib.AxSB100BPC.GetEnrollData(Int32 dwMachineNumber, Int32 dwEnrollNumber, Int32 dwEMachineNumber, Int32 dwBackupNumber, Int32& dwMachinePrivilege, Object& dwEnrollData, Int32& dwPassWord)
   at enrolldata.Form1.button2_Click(Object sender, EventArgs e) in f:\enrolldata\Form1.cs:line 196
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at enrolldata.Program.Main() in f:\enrolldata\Program.cs:line 19
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Any ideas are welcomed

c#
object
com
marshalling
asked on Stack Overflow Feb 11, 2013 by kayhan yüksel • edited Feb 11, 2013 by GSerg

1 Answer

1

This question on another forum seems to be dealing the same problem for the same interface.

This is just a guess based on that thread, but the problem seems to be that the dwEnrollData parameter is actually a variant type (not a managed System.Object type) in which case you should try using System.Runtime.InteropServices.VariantWrapper to wrap the parameter value you are passing into the method.

answered on Stack Overflow Feb 11, 2013 by Mike Zboray

User contributions licensed under CC BY-SA 3.0