Pergunta

I have a piece of third-party software that is an out-of-process ActiveX server. This application was developed, I'm guessing, in VB6 and the documentation uses VB as the example client.

After fighting with C# to get this to work, I thought I would try it in VB.NET and, to my surprise, what seems like identical code in VB.NET works whereas in C# it does not.

The method in question has signature

short oleProvider.GiveMeGlobalDB(ref iGenericDB ptr)

The remaining interface types are defined in the ActiveX component.

VB.NET (This works!)

' defined in a module '
Public pWV As iGenericDB        ' Interface iGenericDB  '
Public pProvider As oleProvider ' Interface oleProvider '

' in a class '
Public Class clsWatView
    Public Sub StartUp()
        pProvider = New oleProvider  ' returns a COM object '            
        pProvider.GiveMeGlobalDb(pWV)        
        ' pWV gets interface pointer to COM object '
    End Sub    
End Class

C#

public static class clsWatView
{
    public static iGenericDB pWV;          // interface iGenericDB
    public static oleProvider pProvider;   // interface oleProvider

    static void StartUp()
    {
        pProvider = new oleProvider();  // This returns a COM object (OK)
        pProvider.GiveMeGlobalDb(pWV);  // executes, but pWV remains null
    }
}

My question is - What is different about these two pieces of code? VB.NET ends up with pWV pointing to a valid COM object and C# ends up with null. What is VB.NET doing differently from C# here?

Foi útil?

Solução

I would try this:

pProvider.GiveMeGlobalDb(ref pWV);

Outras dicas

Maybe try a "out" keyword on C# ?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top