c# - How do I handle var (or ref) parameters in COM Interop? -


i have stand-alone application exposes com interfaces/coclasses/enums, etc. 1 of interfaces exports following function:

procedure findtask(const taskid: widestring; var task: olevariant); safecall; 

note: task exposed coclass.
note: task [in, out]

so far, legacy application, written in delphi, had been able communicate stand-alone application. consider stand-alone app out-of-proc com server , consider legacy app client app.

as rewriting old delphi app (client) in c#, have use com interop in c# communicate application. therefore, made use of tlbimp.exe translate com interfaces c# interfaces.

that method translated following:

void findtask(string, taskid, ref object task); 

how can call findtask , receive result of existent task signature?

i've tried this: (task coclass type)

sctask target = new cstask(); scheduler.findtask("a guid value", ref target); 

but compiler yelled type, since there no overload class type (the translated method receives object)

could this, instead?

object target = new object(); scheduler.findtask("a guid value", ref target); sctask translated = (sctask) target; 

how can call method expects var (in, out) variant *, therefore translated object, have more precise type?

it rather looks me though parameter out parameter. don't appear attempting pass in. method appears returning different object. in c# ought be:

void findtask(string taskid, out object task); 

you'd call this:

you'd need change type library specify out semantics.

if in/out you'd keep use of ref , call method this:

object target = null; scheduler.findtask("a guid value", ref target); sctask translated = (sctask) target; 

or possibly pass in actual object meaningful state if that's how designed work.


Comments

Popular posts from this blog

What Are The Best Universities In The World?

The Ten Most Livable Cities In The World

Hard vs. Soft Water: What's The Difference?