How can I use WinFax Pro COM objects from a .NET application?

I know that WinFax Pro is 1998.

(note: this is not WinFax.dll, which apparently is part of Windows. It is WinFax Pro, a separate commercial add-on application from Delrina, and later acquired by Symantec).

I work in an office that still uses WinFax Pro as its operating system. They have customer fax numbers stored in WinFax Pro's Phone Book and use it to notify customers of service visits. Now it works, someone looks at the (printed) schedule generated from the Mac calendar, then clicks on all the relevant entries in the WinFax phonebook to send a fax message.

This is similar to what we called the integration of the "swivel chair", but it concerned 2 screens. This is not even 2 screens - it is one sheet of paper and one screen.

Anyway, I'm trying to automate it and have problems.

The good news:
- WinFax Pro provides its functions of COM objects: WinFax.SDKSend for the fax sending mechanism; WinFax.SDKPhoneBook for address book, etc.
- WinFax Pro sends a type library, wfxctl32.tlb, which describes these various COM objects. - I can successfully use the WinFax.SDKSend object from .NET (C #), through wrappers created from tlbimport. (I am using .NET 3.5, I cannot run .NET 4.0).

:
- COM- WinFax, WinFax.SDKSend. , WinFax.SDKSend, .

#:

public void Run()
{
    var pb = new wfxctl32.CSDKPhoneBook();
    string id = pb.GetFolderListFirst(1, "");
}

:

: System.InvalidCastException: COM- 'wfxctl32.CSDKPhoneBookClass' 'Wfxctl32.ISDKPhoneBook. , QueryInterface COM- IID '{A67FCC81-9949-11D0-961E-444553540000}' - : ( HRESULT: 0x80004002 (E_NOINTERFACE)).

System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object [] args, Boolean [] byrefModifiers, Int32, String [] namedParameters)
   System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object [] Args, ParameterModifier [] , CultureInfo , String [] namedParams)
   System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags, Object target, Int32 [] aWrapperTypes, MessageData & msgData)
   wfxctl32.CSDKPhoneBookClass.GetFolderListFirst(Int16 standardFolder, String folderID)

+3
3

OleView, SDK Windows, , COM- WinFax.SDKPhoneBook . , . , tlbimport.exe . PDF- WinFax Pro SDK PDF. WinFax.SDKPhoneBook.

javascript COM-, .

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 - do searches for folders
    var list = [];
    var id = firstId;
    do {
        list.push(new Folder(id));
        id = comObject.GetFolderListNext();
    } while (id != "");

    // stage 2 - get subfolders, if any, for each folder
    var subs =[];
    for (var i=0; i<list.length; i++) {
        id = comObject.GetFolderListFirst(0,list[i].Id);
        if (id != "") {
            var a = GetPbFoldersForId(id);  // recurse
            for (var j=0; j < a.length; j++) {
                if (a[j].Parent === null) {a[j].Parent = list[i];}
                subs.push(a[j]);
            }
        }
    }

    for (var k=0; k<subs.length; k++) {
        list.push(subs[k]);
    }

    return list; // a list of folders
};

var id = comObject.GetFolderListFirst(1, "");
Folders = GetPbFoldersForId(id);

for (var k=0; k<Folders.length; k++) {
    say(Folders[k].GetFolderName());
}

, WinFax Pro COM - IDispatch ( ) VB6, VBScript, Javascript, Perl, Python , .NET-, # VB.NET.


#.NET IDispatch? , IDispatch #. , - :

public sealed class PhoneBook // a singleton
{
    Object comObject;
    Type type;

    private readonly static PhoneBook _instance = new PhoneBook();
    public static PhoneBook Instance  { get { return _instance; } }

    private PhoneBook()
    {
        var t = Type.GetTypeFromProgID("WinFax.SDKPhoneBook");
        if (t == null)
            throw new ArgumentException("WinFax Pro is 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) as String;
        return s;
    }
....

PhoneBook IDispatch. typelib. , , .NET 4.0 . , .

Q & A , , WinFax Pro, . , .


EDIT - .NET ASPNET MVC, - REST.

+1

, COM- Winfax ++ (, , VB6), , .Net-. , , COM .Net- .., .

0

, , COM- com dll "", .NET , , ( .. 64- 64- ).

Almost all COM files are 32-bit DLL files, especially commercial ones, so you have to force the application to always create 32-bit data by setting the CPU type in the project settings from "Any" to "32 bit".

0
source

Source: https://habr.com/ru/post/1787727/


All Articles