none
i need to fire events from com dll(not an add-in) and handle it in vba. RRS feed

  • Question

  • here is the code.it works on my machine.

    it crashes on a virtual machine with only win8 and office2013 installed,

    when trying to fire event loginstat in c# dll

    any help will be appreciate

    i've also tried c++ atl, but got error message "method 'value' on object 'range' faile" from vba

    in event RtnExchangeStatus <sub></sub><sup></sup><strike></strike>

    public interface ITradeEvent { [DispId(1)] void LoginStat(int pStatus); [DispId(2)] void RtnExchangeStatus(string pExchange, string pStatus);//this event fires after login

    } [Guid("8A9832E8-8F5F-4FBE-93CF-B1B213F950D2"), ClassInterface(ClassInterfaceType.None), ComSourceInterfaces(typeof(ITradeEvent))] [EventTrackingEnabled(true)] [ComVisible(true)] public class CTrade : ITrade { private Trade trade = null; public event RtnExchangeStatusDelegate RtnExchangeStatus; public event LoginStatDelegate LoginStat; private void trade_OnRspUserLogin(object sender, Trade2015.IntEventArgs e) { if (LoginStat != null) LoginStat(e.Value); } private void trade_OnFrontConnected(object sender, EventArgs e) { ((Trade)sender).ReqUserLogin(); } } public CTrade() { } public int Login(string pInvestor, string pPwd, string pBroker, string server, string dir) { //MessageBox.Show("loggin"); try { fun.SetDllDirectory(dir); trade = new Trade("ctp_trade_proxy.dll") { Server = server, Investor = pInvestor, Password = pPwd, Broker = pBroker, }; trade.OnFrontConnected += trade_OnFrontConnected; trade.OnRspUserLogin += trade_OnRspUserLogin; trade.OnRtnExchangeStatus += RaiseRtnExchangeStatus; trade.ReqConnect();MessageBox.Show("2"); } catch (Exception e) { MessageBox.Show(e.ToString()); } return -1; }

    Private Sub btnn_LoginStat(ByVal pStatus As Long)
        If pStatus = 0 Then
            MsgBox "ok"
        End If
        If pStatus <> 0 Then
            MsgBox "no"

        End If
    End Sub

    Private Sub btnn_RtnExchangeStatus(ByVal s As String, ByVal e As String)
      With Sheet1
        .Range("L1").Value = .Range("L1").Value + 1
      End With
    End Sub


    • Edited by 162380 Friday, February 19, 2016 3:52 AM
    Friday, February 19, 2016 3:33 AM

All replies

  • Hi 162380,

    With the complete code, I could not test with your code. It would be helpful if you could share us a simple demo and details steps to reproduce your issue.

    For a general suggestion, have you register this dll? And I suggest you check whether this dll has been registered correctly in your virtual machine.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, February 22, 2016 7:56 AM