c# - How can I use the WinFax Pro COM objects from a .NET app? -


i know, winfax pro 1998.

(note: not winfax.dll, apparently part of windows. winfax pro, separate commercial add-on app delrina, , later acquired symantec).

i'm working in office still uses winfax pro operational system. have customer fax numbers stored in winfax pro "phonebook", , use notify customers of service visits. way works is, looks @ (printed) schedule, generated mac calendar, clicks on appropriate entries in winfax phonebook, send notification fax.

this used call "swivel chair" integration, referred 2 screens. isn't 2 screens - it's 1 sheet of paper , 1 screen.

anyway i'm trying automate , having trouble.

the news:
- winfax pro exposes functions com objects: winfax.sdksend fax sxending engine; winfax.sdkphonebook address book, , on.
- winfax pro ships type library, wfxctl32.tlb, describes these various com objects. - able use winfax.sdksend object .net (c#), via wrappers generated tlbimport. (i'm using .net 3.5, can't .net 4.0) .

the bad news:
haven't been able invoke of methods on winfax com objects other winfax.sdksend. signatures don't more complicated in winfax.sdksend, keep getting exceptions.

the c# code:

public void run() {     var pb = new wfxctl32.csdkphonebook();     string id = pb.getfolderlistfirst(1, ""); } 

the exception:

exception: system.invalidcastexception: unable cast com object of type 'wfxctl32.csdkphonebookclass' interface type 'wfxctl32.isdkphonebook'. operation failed because queryinterface call on com component interface iid '{a67fcc81-9949-11d0-961e-444553540000}' failed due following error: no such interface supported (exception hresult: 0x80004002 (e_nointerface)).

at system.runtimetype.invokedispmethod(string name, bindingflags invokeattr, object target, object[] args, boolean[] byrefmodifiers, int32 culture, string[] namedparameters)
@ system.runtimetype.invokemember(string name, bindingflags bindingflags, binder binder, object target, object[] providedargs, parametermodifier[] modifiers, cultureinfo culture, string[] namedparams)
@ system.runtimetype.forwardcalltoinvokemember(string membername, bindingflags flags, object target, int32[] awrappertypes, messagedata& msgdata)
@ wfxctl32.csdkphonebookclass.getfolderlistfirst(int16 standardfolder, string folderid)

i opened the oleview tool, part of windows sdk, , can see com interface winfax.sdkphonebook not present on object. hmm, surprise. interface described type library, , tlbimport.exe generates wrapper it. interface documented in winfax pro sdk pdf doc. not find single example of using early-bound interface winfax.sdkphonebook.

when tried javascript calling com object, worked fine.

function say(x){ wscript.echo(x); }  var folder = function(id) {     this.id = id;     this.displayname = null;     this.parent = null; };  folder.prototype.getfoldername = function() {     if (this.displayname === null) {         this.displayname = comobject.getfolderdisplayname(this.id);     }     return (this.parent === null) ? this.displayname         : this.parent.getfoldername() + "/" + this.displayname; };  var comobject = new activexobject("winfax.sdkphonebook");  var getpbfoldersforid = function(firstid) {     // stage 1 - searches folders     var list = [];     var id = firstid;     {         list.push(new folder(id));         id = comobject.getfolderlistnext();     } while (id != "");      // stage 2 - subfolders, if any, each folder     var subs =[];     (var i=0; i<list.length; i++) {         id = comobject.getfolderlistfirst(0,list[i].id);         if (id != "") {             var = getpbfoldersforid(id);  // recurse             (var j=0; j < a.length; j++) {                 if (a[j].parent === null) {a[j].parent = list[i];}                 subs.push(a[j]);             }         }     }      (var k=0; k<subs.length; k++) {         list.push(subs[k]);     }      return list; // list of folders };  var id = comobject.getfolderlistfirst(1, ""); folders = getpbfoldersforid(id);  (var k=0; k<folders.length; k++) {     say(folders[k].getfoldername()); } 

that led me conclude winfax pro com interfaces not dual interfaces - idispatch (late bound) only, , accessible naturally vb6, vbscript, javascript, perl, python, , other late-bound languages, not directly .net languages c# or vb.net.


does c# .net support idispatch late binding? tells me how connect idispatch interfaces c#. using that, can this:

public sealed class phonebook // singleton {     object comobject;     type type;      private readonly static phonebook _instance = new phonebook();     public static phonebook instance  { { return _instance; } }      private phonebook()     {         var t = type.gettypefromprogid("winfax.sdkphonebook");         if (t == null)             throw new argumentexception("winfax pro not installed.");         comobject = activator.createinstance(t);         type = comobject.gettype();     }      public string getusergroupfirst(int flavor, string id)     {         var parameters = new object[2];         parameters[0] = flavor;         parameters[1] = id;         string s = type.invokemember("getusergroupfirst",                                      bindingflags.invokemethod,                                      null,                                      comobject,                                      parameters) string;         return s;     } .... 

the phonebook class wrapper on idispatch interface. wrote 1 wrapper method each method , property in typelib. think kinda .net 4.0 automagically me. in case, worked me.

i'm posting q&a here other people deal winfax pro might have information. searched on intertubes , couldn't find information, i'm putting out there.


edit - .net code running in aspnet mvc app, allowing users lookup entries , send faxes web page or rest client.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -