c# - Decimal marshaling in COM-Interop -


i have com object method signature

hresult _stdcall method1([in] int ms);

next, call method c# reflection:

  ...  decimal ms = 100.5m; comtype.invokemember("method1", flags, null, comobject, new object[] { ms });   ... 

is call correct ? mean how decimal ms marshaled int ?

this code works if create instance activator

  var comtype= type.gettypefromprogid("mycom.server", false); var comobject= activator.createinstance(comtype);  

thanks!

the first snippet makes early-bound call, using runtime callable wrapper created when added reference com server. not going enjoy passing decimal when argument type int, reflection won't convert argument values you.

the second snippet makes late-bound call, using idispatch::invoke(). decimal converted variant of type vt_dec. idispatch implementation in com server converts variant required argument type. com automation helper function vari4fromdec() that, depends if server implemented idispatch or left stock implementation.

since using rcw, neither code snippet makes sense. use comobject.method1(ms). c# compiler coerce decimal you. if favor using late binding, slow safe, want favor dynamic keyword in c# version 4 , up.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -