Problems with COM objects

  • Thread starter Thread starter Ben Morrison
  • Start date Start date
B

Ben Morrison

I have a c# application that I am using Com objects to interface with some
map software called FalconView. When i create the COM object FalconView
opens but immediately closes. It seems as if the object is getting removed
even though I have made it global to the class. If I call the same class
the second time everything works fine. Any suggestions on a fix to this???
 
Ben,

What do you mean you are making it global to the class? Can you give an
example of what you mean? The object should not just dissapear. Are they
ActiveX controls, or just regular classes.
 
Here is my code:

using System;
using fvw;

namespace ITS
{
public class FalconView
{
private int hLayer;
private fvw.LayerClass layer;

public FalconView()
{
hLayer = -1;
layer = new LayerClass();
}

public void Open(string clientName,
Int32 windowHandle, object dispatchPtr)
{
int result;
result = layer.RegisterWithMapServer
(clientName,windowHandle,dispatchPtr);
hLayer = layer.CreateLayer("ITS");
}
I have a form that calls this class.
When I call open from my main application I get InvalidCastException
Error. I think this is because layer is null. The reason I say this is
because when I create a new FalconView object. The FalconView software
kicks off and then immediately closes. The leads me to believe that my
object is possibly being cleaned up by the garbage collector. If I bind
the LayerClass object in the open method I dont get this error. Also,
if run the application again then everything runs fine. So this code
basically works every other time that is called. I cant explain why
this is happening.
 
Here is the code:

using System;
using fvw;

public class FalconView
{
private int hLayer;
private fvw.LayerClass layer;

public FalconView()
{
hLayer = -1;
layer = new LayerClass();
}

public void Open(string clientName, Int32 windowHandle,
object dispatchPtr)
{
int result;
result = layer.RegisterWithMapServer
(clientName,windowHandle,dispatchPtr);
hLayer = layer.CreateLayer("ITS");
}
}

I have a main application that calls this class. When I create a
FalconView object from this class, the FalconView software kicks off and
then immediately closes. Then when i call the open method, I get an
InvalidTypeCastException. Which I believe is because layer is null. If
I close FalconView and my main application and run the program again
everything works fine. So this code is working every other time it is
called. I cant explain why this is happening. Also if I instantiate my
LayerClass object inside of the Open method I dont get the
InvalidTypeCast error.
 
Back
Top