2
votes

Entry level programmer here trying to implement a COM interface. I am working on a program that interfaces with the Aloha point of sale system. Aloha uses COM to work with external programs. I am trying to intercept card data from the mag card reader, which is an OPOS reader, not a keyboard wedge. The documentation I have doesn't explain how to implement this particular interface, but it does explain how to implement a similar one. I have tried to follow this example but I am getting no where. Support from Aloha is non-existent, their documentation is poor, outdated and sometimes just wrong, even though I have paid for a license.

I tried to make a simple app just to test this functionality. Here is what I did:

1) create a new project in vc++ 6.0 using ATL COM app wizard 2) server type dll 3) insert new atl object -> simple object 4) right click on my new class and choose implement interface 5) browse for type library, chose Iber.tlb (Aloha's tlb) 6) chose the interface I want to implement

That made a .h, .cpp and .rgs file.

The .h file has:

public:
// IInterceptMagcard
    STDMETHOD(InterceptMagcard)(BSTR bstrAccountNumber, BSTR bstrCustomerName, BSTR bstrExpirationDate, BSTR bstrTrack1Info, BSTR bstrTrack2Info, BSTR bstrTrack3Info, BSTR bstrRawMagcardData, LONG * bWasDataHandled)
    {
        if (bWasDataHandled == NULL)
            return E_POINTER;

        return E_NOTIMPL;
    }

Is that where I implement my code? I put some test code in there to write out to a txt file just to test it. I then used:

HRESULT hr = CoCreateInstance(CLSID_AlohaMag, NULL, CLSCTX_INPROC_SERVER,
                                IID_IAlohaMag, (void **) &g_pIInterceptMagcard);

where g_pIInterceptMagcard is a pointer to my interface class created with the wizard above.

When I try to register I get the following HRESULT: 0x80040112 That is "class not licensed for use."

Does that mean my program didn't make the necessary registry entries?

1
This doesn't explain your problem but: the g_pIInterceptMagcard variable should not be a pointer to your interface class since CoCreateInstance will overwrite it with a pointer to the class implementing CLSID_AlohaMag. - Frank Boyne
@Frank: Not quite sure what you mean. On return, g_pIInterceptMagcard will point to the IAlohaMag interface of an AlohaMag object. I don't think your term "interface class" is clear because the separation of interface from implementation is crucial in COM. (There's no such thing as an "interface class".) And the returned pointer points to an object, not to a class. (There's no such thing as a pointer to a class in COM or C++.) - Ciaran Keating
@ciaran: the OP says "where g_pIInterceptMagcard is a pointer to my interface class created with the wizard above". I took that to mean something like g_pIInterceptMagcard = new MyInterceptMagcard() was executed before the CoCreateInstance call. What I was trying to point out was that any attempt to assign g_pIInterceptMagcard before calling CoCreateInstance is wasted effort because CoCreateInstance overwrites the contents of the last parameter (i.e., g_pIInterceptMagcard ) with a pointer to the interface requested. - Frank Boyne
@Frank: Ah yes, I didn't spot that it was Bob's term, not yours. Sorry. - Ciaran Keating
@Bob To be more explicit, if you set g_pIInterceptMagcard to NULL you should find that CoCreateInstance still returns the error. Your test case failure probably has nothing to do with your implementation of IInterceptMagcard you are just having trouble creaing an instance of the CLSID_AlohaMag class. - Frank Boyne

1 Answers

1
votes

It probably means there is a license you have to install before their custom class factory will create an instance of the class. Did you try running your program on a fully working POS system with the magnetic card swipe licensed for use? Maybe there is some other license that you need to do this type of thing?

If it was a problem of the class not being registered, the result would be "class not registered". It sounds like you've done the necessary steps via the wizard to implement the interface and have it generate the correct registry entries.