Closed dreamershl closed 9 years ago
You can't make RTD calls from a ribbon callback (in particular, you can't call the CAPI (XlCall.RTD) in that context.
You can't start the RTD server yourself - Excel does so when the first topic is created. It looks like you need an extra layer of abstraction between the Excel RTD server and your own data service.
-Govert
On 12 Oct 2015, at 03:08, Shen liang notifications@github.com<mailto:notifications@github.com> wrote:
It is a strange error. It is all right to invoke the RTD in the UDF, which call the UDF in the excel sheet cell . But if call it in the ribbon, the exception will be raised. In the debugger, I can see the request is processed properly by RTD. Just before return, the following exception will be raised.
UDF:
public static class UserDefinedFunctions { [ExcelFunction(Description = "start the RTD server for order submission & price data")] public static object startServer(String IP, int port) { return XlCall.RTD("ExcelTradeGateway.FIXRTDServer", null, new string[] { "CONFIG", IP, port.ToString()}); } }
UI:
Code to call RTD, which will cause the exception
[ComVisible(true)] public class Ribbon : ExcelRibbon {
public void OnServerChange(IRibbonControl control, string text)
{
object val = UserDefinedFunctions.startServer(text, 123);
}
}
Exception detail:
Exception thrown: 'System.AccessViolationException' in ExcelDna.Loader.dll ExcelDna.Integration Error: 5 : The RTD server of type ExcelTradeGateway.FIXRTDServer required by add-in ExcelTradeGateway could not be registered. This is an unexpected error. Error message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. RtdRegistration.RTD exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at ExcelDna.Loader.XlCallImpl.TryExcelImpl12(Int32 xlFunction, Object& result, Object[] parameters) in V:\GitHub\ExcelDna\Source\ExcelDna.Loader\XlCallImpl.cs:line 154 at ExcelDna.Loader.XlCallImpl.TryExcelImpl(Int32 xlFunction, Object& result, Object[] parameters) in V:\GitHub\ExcelDna\Source\ExcelDna.Loader\XlCallImpl.cs:line 80 at ExcelDna.Integration.ExcelIntegration.TryExcelImpl(Int32 xlFunction, Object& result, Object[] parameters) in V:\GitHub\ExcelDna\Source\ExcelDna.Integration\ExcelIntegration.cs:line 43 at ExcelDna.Integration.XlCall.TryExcel(Int32 xlFunction, Object& result, Object[] parameters) in V:\GitHub\ExcelDna\Source\ExcelDna.Integration\XlCall.cs:line 1113 at ExcelDna.Integration.Rtd.RtdRegistration.TryCallRTD(Object& result, String progId, String server, String[] topics) in V:\GitHub\ExcelDna\Source\ExcelDna.Integration\ExcelRtd.cs:line 176 at ExcelDna.Integration.Rtd.RtdRegistration.TryRTD(Object& result, String progId, String server, String[] topics) in V:\GitHub\ExcelDna\Source\ExcelDna.Integration\ExcelRtd.cs:line 142
— Reply to this email directly or view it on GitHubhttps://github.com/Excel-DNA/ExcelDna/issues/39.
Thanks for the info. I have came out another layer for this. Thanks again
It is a strange error. It is all right to invoke the RTD in the UDF, which call the UDF in the excel sheet cell . But if call it in the ribbon, the exception will be raised. In the debugger, I can see the request is processed properly by RTD. Just before return, the following exception will be raised.
UDF:
UI:
Code to call RTD, which will cause the exception
Exception detail: