tags:

views:

59

answers:

4
+1  Q: 

C# and com for vb6

Hi all

I have an issue with C# and COM. :(

[Guid("f7d936ba-d816-48d2-9bfc-c18be6873b4d")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Process : IProcess
{

    public Process()
    {
    }

    public int UpdateBalance(string accountNumber, string adminEventDescription, decimal curAmount)
    {
        return 10;
    }
}

[ComVisible(true)]
[Guid("5c640a0f-0dce-47d4-87df-07cee3b9a1f9")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IProcess
{
    int UpdateBalance(string accountNumber, string adminEventDescription, decimal curAmount);
}

And the VB code

Private Sub Command1_Click()
    Dim test As Object
    Set test = New Forwardslash_PlayerTrackingSystem_Api.Process
End Sub

I get the following

ActiveX component can't create object?

+1  A: 

Have you ticked the "Register for COM interop" box in the project properties?

Paolo
Yes I did :) but its not working :)
Jim
+1  A: 

Do you have the ProgID Forwardslash_PlayerTrackingSystem_Api.Process defined in the C# source as well? Your example code does not seem to include it. (Or are you working with an existing type library and creating the object in VB by GUID somehow?)

And is the C# component registered correctly in the registry on the machine where the VB code runs? See the answer by Paolo for a way to have VisualStudio do this for you when you build and/or register it yourself using the regasm.exe tool. This tool is equivalent to regsrv32.exe for "real" COM objects, but then registers an appropriately built .NET assembly in the registry for use from COM.

peSHIr
If I do regasm on the local machine then I get a automation error. That saysThe system cannot find the file specified
Jim
@Jim "The system cannot find the file specified" <-- you can't just ignore that ^^ Verify the registry entries and make sure they match up with reality. Make sure there is no stale data, duplicated CLSID, or shadow of machine vs. user CRs, etc.
pst
+1  A: 

Your [InterfaceType] attribute is wrong. VB6 requires an IDispatch interface, it cannot handle an IUnknown interface. It likes ComInterfaceType.InterfaceIsDual best, that produces a full type library, enables IntelliSense in the VB6 editor and is roughly a 1000 times faster than the late-bound IDispatch.

Hans Passant
A: 

Using regasm's /codebase switch is mandatory if the assembly is not registered in GAC.

wqw