07-12-2017 05:05 PM
I have a c# app that runs as a command that creates a windows form with a Map View control on it. It works fine. So now I'm trying to create a command line utility that opens the same form and does something with the map. However, when I set the map view control legend using a named legend, the legend property fails silently. The property remains null.
I've attached the project file.
So the only difference that comes to mind, is the app command runs within the GeoMedia exe process, whereas the command line utiltiy does not. Maybe a com interop issue?
Or, maybe I'm missing a reference?
Solved! Go to Solution.
07-17-2017 08:26 AM
Well, I have reviewed the code and it looks like you are facing classical marshaling problem - so you are right, the legend object is created in GM memory space, while the MapView is in your application memory space. I don't know an easy solution. The only which I can think of is to recreate all objects in the application memory space - starting with connection, recordsets, legend, legend entries and symbology. Although some steps might not be necessary. Perhaps it would only be sufficient to create the legend, legend entries and symbology, and assign the existing recordsets from GeoMedia memory space. This should be a subject of tests.
07-17-2017 10:02 AM
I found that if I set the mapView.Legend to new Legend it's ok. So, as a workaround I tried to copy all the properties from the Named Legend to a new Legend. The Copy method failed, so I tried doing it Legend Entry prop by Legend Entry prop. I got as far as setting a Legend Entry Style property from a copy of the Named Legend Legend Entry Style.
This part seems ok:
PView.StyleDefinition style = (PView.StyleDefinition)le.Style;
But then this part fails:
namedLegendEntry.Style = style;
Exception from HRESULT: 0x80040202
Once again, I noticed that setting the LegendEntry style to a New StyleDefinition() works. Just fails when I copied it over from the Named Legend.
I tried using the style Copy method as well, to no avail.
I guess maybe I could try iterating recursively through all the Style props and copying them over one at a time as well. I suspect as long as they are primitive types it might work.
So, I'm curious though. What do custom app developers do? There must be custom apps pulling legends from a Named Legend.
07-17-2017 12:21 PM
What you are trying to do is by no mean a standard programming task. This is so called driving type application and I would recommend you to avoid it if possible, just because of the problems you are experiencing.
If you need to exchange some information with a geoworkspace, then I would recommend you to output the gws information you need into a library. Then using library API, you can quickly recreate the gws content as stored in the library, without a need to instantiate GeoMedia application. All objects will be created in your app memory space and there will be no problems. So I suggest you to look at Library automation API to investigate whether it could solve your problem or not.
07-18-2017 11:41 AM
Thanks for your suggestions on this. Your suggestion about the library got me thinking about how to cross that boundary, and I decided to try something else so I wouldn't have to do that.
Here's what I came up with.
First step is to save the command line args to a special file.
Next, call the GeoMedia application object's InvokeCommand method to launch my command.
When my command Activates, I look for the file. If it exists, I operate in command line mode and pull the args from the file.
If not, I operate as normal.
Doing this everything operates within the context of the GeoMedia process, and I now have it working.