How do I call a COM object in C# that I registered using RegistrationServices -


i'm experimenting com objects , created simple com service acts calculator add, subtract, multiply, divide (details not important).

i wrote code register dynamically c# application

assembly asm = assembly.loadfile("c:\\...comcalc.dll"); registrationservices regasm = new registrationservices(); bool bresult = regasm.registerassembly(asm, assemblyregistrationflags.setcodebase); 

after registering i've been able use service ie browser in javascript.

var num1 = 2 var num2 = 2 var objtest = new activexobject("comcalc.comcalc") alert(num1 + " - " + num2 + " = " + objtest.subtract(num1,num2)) 

i'd able test c# application can have register, unregister, , test method com object. i've struggled find documentation how this. ideas?

bonus: access guid defined in com object opposed comcalc.

   regasm.registerassembly(asm, assemblyregistrationflags.setcodebase) 

by writing own custom registration method, missing out on normal way com client programs or unit testers exercise code. they'll use type library of com component, machine-readable file describes types expose component. com equivalent of .net metadata.

you type library using normal way register, either using project's "register com interop" setting or running regasm.exe /tlb option. or running tlbexp.exe generate manually.

this not let test component c# unit test, you'd use project > add reference > browse , pick .tlb file. ide refuses accept it, can see type library created .net assembly. insists use normal assembly reference instead, picking dll instead.

there's reason that. can fool ide using late binding not fool clr. in other words, not testing com interop @ all. might use normal way add .net assembly reference. testing component requires using com client written in non-.net language. not many practical ones around anymore, use scripting language javascript or vbscript. closer actual language , runtime environment going use component, better. if going use in browser selenium or htmlagilitypack wise choice.

nobody ever likes hear advice that. fool ide late binding, similar did in browser:

type type = type.gettypefromprogid("comcalc.comcalc"); dynamic obj = activator.createinstance(type); dynamic result = obj.subtract(2, 1); 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -