ANVIL API (Assent) Developer Thread

Discussion in 'Trading Software' started by ctarmor-et, Dec 10, 2007.

  1. jeffweng

    jeffweng

    Anyone knows how exactly proactive orders work?
    Do they differ in different ECNs? Or perform in the same way?

    Thanks!
     
    #171     Aug 1, 2008
  2. jeffweng

    jeffweng

    Hi ctarmor-et,

    After reading your previous post about hooking into Anvil main thread, I successfully got Anvil main thread listening to WM_USER* messages. But somehow the filter function was called twice when I just post one message to main thread.

    Following is the hooking codes, message posting codes and filter function,
    any advice will be appreciated.

    Hooking codes:
    UINT threadId = GetWindowThreadProcessId(AfxGetMainWnd()->GetSafeHwnd(), NULL);

    mHook = SetWindowsHookEx( WH_GETMESSAGE, (HOOKPROC)ANVILThreadMainMessageProcHook, NULL, threadId );
    ----------------------------------------
    Message Posting codes:
    AfxGetMainWnd()->PostMessage(MY_TRADE_SEND_ORDER,0,0);

    -------------------------------------------
    filter function:
    LRESULT CALLBACK ANVILThreadMainMessageProcHook(
    int nCode,
    WPARAM wParam,
    LPARAM lParam)
    {
    if (nCode < 0) {
    return CallNextHookEx(mHook, nCode, wParam, lParam);
    }
    if(HC_ACTION == nCode) {
    MSG* msg = (MSG*)lParam;
    UINT msgId = msg->message;

    switch(msgId) {
    case MY_TRADE_SEND_ORDER:
    AfxMessageBox("SEND_ORDER");
    return NULL;
    break;
    }
    }
    LRESULT RetVal = CallNextHookEx( mHook, nCode, wParam, lParam );

    return RetVal;

    }


    thanks,

    Jeff
     
    #172     Aug 27, 2008
  3. You want to process the message when it is being removed from the msg queue checking PM_REMOVE == wParam


    if ( PM_REMOVE == wParam )
    {
    switch ( pMsg->message )
    {
    // Process your message .......
    }
    }
     
    #173     Aug 28, 2008
  4. jeffweng

    jeffweng

    It works!
    Thank you very much!
     
    #174     Aug 28, 2008
  5. tfjield

    tfjield

    I don't use this method anymore, but I did experiment with it for a while. How do you guys unhook from the main window when you want to close the app?

    The problem is if you just click close on the app, the message gets processed by the main window with your hook as part of the call chain.

    I tried unhooking on the close message, then sending it again, but if the user then pressed No on the "are you sure?" query, the app would keep running, but I was unhooked.

    The only way I could figure out to do it was to unload my DLL before I closed the app... This is why I went with the MFC dialog, since the framework handles "unhooking" gracefully.

    I'm just curious in case I have to do it with a window hook in the future, for some reason.
     
    #175     Aug 28, 2008
  6. jeffweng

    jeffweng

    Is the app you mentioned Anvil.exe? I don't use it except for the dll embeded in Anvil.exe.
    What I do is creating a singleton class and do the hooking in the initialize method of its only instance. Write the unhooking codein the destructor and delete this instance in the TerminateAnvilExtension method. I'm not 100% sure that TerminateAnvilExtension will be called whatever happens to Anvil.exe or my own dll, but it works well so far.
     
    #176     Aug 28, 2008
  7. I unhook at the termnateextension() call:

    UnhookWindowsHookEx( hookhandle );

    It seemed to be wroking fine until the latest version of ANVIL...
     
    #177     Aug 28, 2008
  8. tfjield

    tfjield

    Hi jeffweng, yes, I'm referring to Anvil.exe. I use it the same way, just to host my DLL, but I'm talking about when I close Anvil without explicitly unloading the extension DLL first.

    The problem I had with these methods is that the TerminateAnvilExtension() call gets called from a function when your hook is already in the call stack... For example, WM_CLOSE gets sent by the OS, you don't do anything in your hook function but just pass the message on... Some message handler in Anvil queries if you really want to exit, and you say yes, and then it calls TerminateAnvilExtension(). So if you unhook there, then as the functions are returning back up the call stack, when it gets to your hook (which isn't present anymore) it throws an exception.

    ctarmor-et, is it possible that you were always generating an exception on exit and you just didn't catch it?
     
    #178     Aug 28, 2008
  9. Has anyone has any issues ANVIL terminating the main thread lately ?

    There is not real exception other that a "corrupted virtual call" dialog and anvil terminates.

    I been looking in my extension but I cannot find anythig wrong.

    Just wondering if anyone is having similar problems ...
     
    #179     Sep 19, 2008
  10. tfjield

    tfjield

    Nope, no problems here...
     
    #180     Sep 19, 2008