Creating a COM
-
I have a software which puts all the data in a dll....I want to access this data from MATLAB and I want it to be event driven. For this(event driven operations in MATLAB) I have to create a COM. I have no experience in creating COM. I googled but couldn;t find any good material on COM basics and hwo to create one. :(could anyone tell me how to proceed? thanks -- modified at 16:27 Tuesday 20th December, 2005
-
I have a software which puts all the data in a dll....I want to access this data from MATLAB and I want it to be event driven. For this(event driven operations in MATLAB) I have to create a COM. I have no experience in creating COM. I googled but couldn;t find any good material on COM basics and hwo to create one. :(could anyone tell me how to proceed? thanks -- modified at 16:27 Tuesday 20th December, 2005
Hi Vidyarani, I am currently working on a similar problem it seems. See the message “out-of-process DLL”. If you are trying to transfer data to MATLAB and if you are trying to let your DLL tell MATLAB what to do with the data, then you can/should use the MATLAB engine. I suppose you are writing the DLL not the application, right? There are MATLAB engine library files, which you can link with your DLL project. The MATLAB engine library basically sets up a COM connection with MATLAB with the advantage that you do not have to worry about COM. The MATLAB engine library lets you transfer data to and from MATLAB. Your DLL should transfer data by creating MATLAB data-types (matrixes) using mx-functions, also included in the MATLAB engine library files. To create event driven operation you can first transfer data to MATLAB, and then you can execute .m-functions by letting the MATLAB engine, within your DLL, tell MATLAB which .m-function to execute. In this way, the .m-functions act as a kind of callback-functions. I hope this is the kind of event driven operation you are after. If you also want MATLAB to call back to your DLL in an event driven manner, then you should be looking at COM as well. But to do this from within a DLL is not straightforward. Things to look at in MATLAB help: MATLAB \ External Interfaces/API \ Calling MATLAB from C and Fortran Programs MATLAB \ External Interfaces/API Reference \ C Engine Functions MATLAB \ External Interfaces/API Reference \ C MX-Functions Things to look at in MATLAB root: ..\ MATLAB \ extern “MATLAB engine library files” I hope this will get you going. If it doesn’t and you really want to create COM functions in your DLL and you want MATLAB to call these functions, then you are facing the same problem I have. In that case we can discuss further. Kind regards, Marcel Dijkstra
-
Hi Vidyarani, I am currently working on a similar problem it seems. See the message “out-of-process DLL”. If you are trying to transfer data to MATLAB and if you are trying to let your DLL tell MATLAB what to do with the data, then you can/should use the MATLAB engine. I suppose you are writing the DLL not the application, right? There are MATLAB engine library files, which you can link with your DLL project. The MATLAB engine library basically sets up a COM connection with MATLAB with the advantage that you do not have to worry about COM. The MATLAB engine library lets you transfer data to and from MATLAB. Your DLL should transfer data by creating MATLAB data-types (matrixes) using mx-functions, also included in the MATLAB engine library files. To create event driven operation you can first transfer data to MATLAB, and then you can execute .m-functions by letting the MATLAB engine, within your DLL, tell MATLAB which .m-function to execute. In this way, the .m-functions act as a kind of callback-functions. I hope this is the kind of event driven operation you are after. If you also want MATLAB to call back to your DLL in an event driven manner, then you should be looking at COM as well. But to do this from within a DLL is not straightforward. Things to look at in MATLAB help: MATLAB \ External Interfaces/API \ Calling MATLAB from C and Fortran Programs MATLAB \ External Interfaces/API Reference \ C Engine Functions MATLAB \ External Interfaces/API Reference \ C MX-Functions Things to look at in MATLAB root: ..\ MATLAB \ extern “MATLAB engine library files” I hope this will get you going. If it doesn’t and you really want to create COM functions in your DLL and you want MATLAB to call these functions, then you are facing the same problem I have. In that case we can discuss further. Kind regards, Marcel Dijkstra
Hi Marcel, Thanks for the reply. Let me explain as to what exactly. --------------------------------- | Have Software which sends data | --------------------------------- | | ---------------------------------- -------------------------- | DLL where the data is stored | -------------|other apps accessing data| ---------------------------------- --------------------------- whenever the DLL gets fresh data it can send a notification(or event) . I need to access this data from the DLL i.e want MATLAB to call these functions I really dont want to make any changes to the DLL as there are a lot of other applications which use the DLL. So I will have to build a COM isn't it? Regards, Vidya
-
Hi Marcel, Thanks for the reply. Let me explain as to what exactly. --------------------------------- | Have Software which sends data | --------------------------------- | | ---------------------------------- -------------------------- | DLL where the data is stored | -------------|other apps accessing data| ---------------------------------- --------------------------- whenever the DLL gets fresh data it can send a notification(or event) . I need to access this data from the DLL i.e want MATLAB to call these functions I really dont want to make any changes to the DLL as there are a lot of other applications which use the DLL. So I will have to build a COM isn't it? Regards, Vidya
Hi Vidya, I actually misunderstood your problem. So you are not programming the DLL, but you are thinking about making something in COM for MATLAB. Am I right in assuming that the DLL has already got a COM interface with which other programs can access its data? I assume this is the case because otherwise there would be no use in writing anything in COM if you do not want to change the DLL. How is this event/notification done? Also through COM? Lets assume the DLL exports COM(ActiveX) automation objects then MATLAB can directly connect to these COM server objects in your DLL. Open you registry “
Start-Run-regedit
” then goto ”My Computer \ HKEY_CLASSES_ROOT \ CLSID
”. Select CLSID and search for your DLL or application name. As an example search for “Microsoft Office Excel Application
”. If I do this, regedit finds the key “My Computer \ HKEY_CLASSES_ROOT \ CLSID \ {00024500-0000-0000-C000-000000000046}
”. Now you can find the subkey “ProgID
” with value “Excel.Application.11
” or something similar. Now you can connect to this COM server object by using its ProgID in MATLAB. Type in the command window:e = actxserver('Excel.Application.11'); methodsview(e); e.Help();
Ifactxserver()
succeeds you can usemethodsview()
to see the functions you can access. As an example we can ask the Excel COM object to display help information by callinge.Help()
; I hope this is what you are looking for. Regards, Marcel -
Hi Vidya, I actually misunderstood your problem. So you are not programming the DLL, but you are thinking about making something in COM for MATLAB. Am I right in assuming that the DLL has already got a COM interface with which other programs can access its data? I assume this is the case because otherwise there would be no use in writing anything in COM if you do not want to change the DLL. How is this event/notification done? Also through COM? Lets assume the DLL exports COM(ActiveX) automation objects then MATLAB can directly connect to these COM server objects in your DLL. Open you registry “
Start-Run-regedit
” then goto ”My Computer \ HKEY_CLASSES_ROOT \ CLSID
”. Select CLSID and search for your DLL or application name. As an example search for “Microsoft Office Excel Application
”. If I do this, regedit finds the key “My Computer \ HKEY_CLASSES_ROOT \ CLSID \ {00024500-0000-0000-C000-000000000046}
”. Now you can find the subkey “ProgID
” with value “Excel.Application.11
” or something similar. Now you can connect to this COM server object by using its ProgID in MATLAB. Type in the command window:e = actxserver('Excel.Application.11'); methodsview(e); e.Help();
Ifactxserver()
succeeds you can usemethodsview()
to see the functions you can access. As an example we can ask the Excel COM object to display help information by callinge.Help()
; I hope this is what you are looking for. Regards, MarcelHi Marcel, The DLL has not got a COM interface. I need a COM which can speak to the DLL and MATLAB. So the COM gets the information from the DLL and sends it to MATLAB. I have an example but not able to figure out how to do it myself? So wanted to know if there are more examples? Thanks Vidya
-
Hi Marcel, Thanks for the reply. Let me explain as to what exactly. --------------------------------- | Have Software which sends data | --------------------------------- | | ---------------------------------- -------------------------- | DLL where the data is stored | -------------|other apps accessing data| ---------------------------------- --------------------------- whenever the DLL gets fresh data it can send a notification(or event) . I need to access this data from the DLL i.e want MATLAB to call these functions I really dont want to make any changes to the DLL as there are a lot of other applications which use the DLL. So I will have to build a COM isn't it? Regards, Vidya
Hi Vidya, Correct me if m wrong !!! Whenever the dll gets fresh data its sends some notification/events, its done? Okay so you need to access this data, right ? One possible way to do so is capture the notificaion/events sent by the dll. Another way of doing such thing is use the interfaces exposed by your dll, I mean your dll sends a notification/events, so there must exists some exposed interfaces... To check that your dll has exposed interfaces or not, you can design the sample using ATL... Steps to genertate the sample 1. Select ATL component project 2. Add simple object to project 3. Go to class view tab 3. Right click on class and select implements interface, it will pop up a dialog 4. Click on "AddTypeLib", select your dll's typelib and click "ok" 5. It will show you the list of interfaces exposed by your dll 5. Select the appropriate interface and click ok 6. IDE will generate the source code for interface implementation Ah, I think you should try this... this might ease the difficulty you are facing.... Let me know if I can do ne thing? :) Cheers, Vishal
-
I have a software which puts all the data in a dll....I want to access this data from MATLAB and I want it to be event driven. For this(event driven operations in MATLAB) I have to create a COM. I have no experience in creating COM. I googled but couldn;t find any good material on COM basics and hwo to create one. :(could anyone tell me how to proceed? thanks -- modified at 16:27 Tuesday 20th December, 2005
Perhaps more information on the nuts and bolts of how one actually *writes* this software may be helpful.. I have a step-by-step DCOM tutorial, where I build a simple server which says "Hello, world!" back to the client, may help put some of this in practical perspective... The tutorials are written as a series of separate articles, called Steps, which cover the major breakpoints in the development of the system. Step 1 of the tutorial for VC 6 is at http://www.codeproject.com/com/HelloTutorial1.asp[^] And Step 1 of the turtorial for Visual C++.NET 2003 is at http://www.codeproject.com/useritems/HelloTutorial1NET.asp[^] I tried to write the tutorials in Microsoft-ese, so you can follow along as if you were reading the Scribble tutorial. The VS.NET version is still a work in progress; that's why it's still in "Unedited User Constributions." Not all the Steps have been written for the VS.NET version yet. But I am working on it! Stay tuned! Sincerely Yours, Brian Hart Department of Physics and Astronomy University of California, Irvine