Clarification about ComServer.DllRegisterServer()

243 views
Skip to first unread message

Johnny24

unread,
Apr 21, 2021, 9:23:37 AM4/21/21
to Excel-DNA
Hello,
Can ComServer.DllRegisterServer() be used outside a .xll?

I'm trying to build an out-of-process COM server, running in another application. A new Excel instance should see the registration into the system?
and I found that the project still builds .xll files. What if the DLL is loaded and executed by another program?
Are DllRegisterServer and DllUnRegisterServer still effective? Or the COM registration is limited to the running Excel instance having xll loaded?

thanks in advance

Govert van Drimmelen

unread,
Apr 21, 2021, 11:50:01 AM4/21/21
to exce...@googlegroups.com

The DllRegisterServer call just registers the .xll as the ‘server’ library for the COM objects.

So that is not linked to Excel.

But there are various parts of the .xll initialization that depends on it running inside Excel, so it won’t work as an out-of-process COM server.

 

For making a .NET library that you can access via COM in another program, you don’t need Excel-DNA though.

This functionality is part of .NET anyway.

If you search for “RegAsm” you’ll find the .NET-specific COM registration tool, and related documentation and articles from there.,

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/cb791271-d179-4c98-abff-eefa99d73722n%40googlegroups.com.

Johnny24

unread,
Apr 21, 2021, 12:05:01 PM4/21/21
to Excel-DNA
Thanks fo replying - I know COM is a supported .NET feature, and I'm still using it.
I was looking if Excel-DNA let me, in order:
- start a .NET that is referencing the DLL using ExcelDNA. This DLL exposes the COM server.
- start an instance of MS Excel and call the 'late bound' COM server from VBA, allowing me to access data in the running .NET exe.
In other words, a real-time link to my app.

From what I understood until now, this cannot depend on the registered DLL, because using registered types Excel will load a separate (and "empty") instance of COM server.

Is there a way in Excel-DNA to link running applications to Excel (with of without COM)?

Govert van Drimmelen

unread,
Apr 21, 2021, 12:11:23 PM4/21/21
to exce...@googlegroups.com

Excel-DNA .xll libraries can only be used inside the Excel process, and the Excel-DNA COM support only provides InProc COM server support.

 

So for your scenario you need to implement your own inter-process communication.

Then the ‘client’ part of the communication that runs inside Excel can be implemented as an Excel-DNA add-in, and you have some other ‘server’ part that is running outside Excel and implemented without Excel-DNA.

You might of course have the same .NET assemblies (independent of Excel-DNA) that are used on both sides of the communication.

 

For real-time feed into Excel, you add-in can implement an RTD server or expose a data stream based on the IObservable interfaces.

Johnny24

unread,
Apr 21, 2021, 1:41:31 PM4/21/21
to Excel-DNA
Thanks, it's clear.
It seems a good idea to use RTD, however I need RTD from VBA. I tested this VBA code in Samples\RtdPerformance, but gives errors:

Sub test()
Dim obj As Object
obj = CreateObject("RtdPerformance.Server")
MsgBox obj.rtdHello()
End Sub

The error is related to  NonComVisibleBaseClass  (sorry this is in Italian):
Assistente al debug gestito 'NonComVisibleBaseClass' : 'Effettuata chiamata QueryInterface che richiede l'interfaccia IDispatch predefinita della classe gestita visibile COM 'RtdPerformance.RtdServer'. Poiché la classe non dispone di un'interfaccia predefinita esplicita e deriva dalla classe visibile non COM 'ExcelDna.Integration.Rtd.ExcelRtdServer', la chiamata QueryInterface avrà esito negativo per impedire che la classe base visibile non COM sia vincolata dalle regole di versione COM.'

Any hint on this? Is this a limit of RTD?

I already tried by adding [ClassInterface(ClassInterfaceType.AutoDispatch)] to the class, but nothing changed.

Govert van Drimmelen

unread,
Apr 21, 2021, 3:47:04 PM4/21/21
to exce...@googlegroups.com

For the case where you want to push data to VBA you would not use the Excel RTD server, but just raise events from the C# COM server.

See this discussion and snippets: https://groups.google.com/g/exceldna/c/lwJYjBA7XF0

 

You need to be very careful about the threading though, you need to be sure that the events are raised on the main Excel thread, and at a time where Excel and VBA is happy to process such events.

 

So you’re getting to the edge of complexity for integrating a .NET COM server with Excel and VBA safely.

Johnny24

unread,
Apr 22, 2021, 10:13:59 AM4/22/21
to Excel-DNA
Thanks for reply, I analyzed also the other discussion.

Then I must revert to COM server, but it's still unclear to me how to do it in my running app:
1. by using pure COM model in .NET, I need to register in the system the DLL (or the EXE) and then I'm stuck - how to connect the excel instance to running code? we're in different app domains.
or
2. by using ExcelDNA.AddIn, but in this case I cannot call Excel from my application (and calling instead my app from excel is not possible in my case)
or
3. by using Excel RTD server, and call the functions from VBA by using Evaluate. In such case, (if I understood well) Events would be used as to refresh the data passed to Excel, but I need to write a sort of wrapper of every function I need.

The only thing I need is to call from VBA the functions exposed as COM in the running application. If there's no running application, such functions wouldn't return anything useful, and that's why I cannot use the common COM model as it is, because it's relying on a new instance of COM lib, totally independent from the running app.
As far as I understand, COM model does not allow to exchange data from one app to another. I used pipelines in the past, but they need precise signals and are not so easy to implement - I believed this was (possible and) simpler to do in Excel.

What's your point of view on that? I'm definitely looking for your advice

Craig Crevola

unread,
Apr 23, 2021, 5:42:56 AM4/23/21
to exce...@googlegroups.com

Hi

 

If you are looking at a two way coms or pub/sub you could use zeromq. From your description it sounds like you are after a pub/sub solution with your .Net App publishing to Excel Instances, either way zeromq can handle it. I had written a pub sub demo using zmq and ExcelDNA, essentially connecting two xll’s via tcp port. The demo code is here: https://github.com/ccrevola/Excel-DNA-Samples/tree/master/ExcelDnaZmq

 

Check out the zmq documentation: https://zeromq.org

 

Hope this helps

 

Craig.

Johnny24

unread,
Apr 23, 2021, 2:09:44 PM4/23/21
to Excel-DNA
Thanks a lot, I'll have a look - it seems what I was looking for

Vladimir Kozlov

unread,
Jan 31, 2023, 3:58:49 AM1/31/23
to Excel-DNA
Craig, thank you. What a great idea and cool project. BTW how you debug it? the idea behind is to use all excel functions in real time by server response -- all packed in single dll or via open tcp port, without excel opened

пятница, 23 апреля 2021 г. в 21:09:44 UTC+3, Johnny24:

Vladimir Kozlov

unread,
Jan 31, 2023, 4:22:12 AM1/31/23
to Excel-DNA
in my config publisher is Excel, subscriber is a win service

вторник, 31 января 2023 г. в 11:58:49 UTC+3, Vladimir Kozlov:

Craig Crevola

unread,
Feb 2, 2023, 8:34:01 PM2/2/23
to exce...@googlegroups.com
Hi Vlad

The easiest way to debug it is to set both projects to Startup Projects. Then when you run them, ensure you enable the xll if challenged by Excel security notice (depends on your version of excel etc). Create 2 new excel sheets (as they open in new windows). Set your breakpoints appropriately, then in one sheet utilise the Publish function (i.e. formula: =Publish("test", "message") ). In the other sheet utilise the subscribe function (i.e. formula: =Subscribe("test") )

Each time you change the value in Publish (2nd param), if using the example you'll see the message updated in the second sheet. Its pretty quick, it dispatches 1000 messages in the example proj.

Here are some screen shots to help:
Set Startup Projects (Debug->Set Startup Projects)
image.png

Break Point sample (Subscriber.cs):
image.png


You don't necessarily need to run two sheets, if both add-ins are loaded in the Excel Instance then you can use both functions in the one sheet. Internally it utilizes port 5555.

Hope that answers your question.

Thanks

Craig.

Reply all
Reply to author
Forward
0 new messages