Reputation: 15
i've written a DLL in C# (.NET v4) which I want to use in a VB6.0 Projekt. I basicly followed the tutorial at http://msdn.microsoft.com/de-de/library/ms227568(v=vs.80).aspx and ended up with this class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CRUFL_CS_ExchangeRate
{
[Serializable]
[ComVisible(true), ClassInterface(ClassInterfaceType.None), Guid("F5DCE88F-AD38-4a9a-9A69-0F8DC0EDB4E3")]
public class ExchangeUfl : IExchangeUfl
{
public double ConvertUSDollarsToCDN(double usd)
{
return (usd * 1.45);
}
public void bla()
{
}
public string t2()
{
return "t2";
}
public String test()
{
return "test";
}
}
}
and this Interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CRUFL_CS_ExchangeRate
{
[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("F6B3D6DB-E4C8-48A9-B9B5-324012E2E93F")]
interface IExchangeUfl
{
[DispId(1)]
double ConvertUSDollarsToCDN(double usd);
[DispId(2)]
String test();
[DispId(3)]
string t2();
[DispId(4)]
void bla();
}
}
My AssemblyInfo.cs look like this
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("CRUFL_CS_ExchangeRate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("CRUFL_CS_ExchangeRate")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: Guid("912fe53d-dfc9-4eec-bbca-7f2ed29d95dc")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
I've turned on the strong name signing in the project properties and the COM-Interopt registration is off.
I created the project and registered the DLL via "regasm.ex C:\path\to\the\lib.dll /codebase" and it shows up in the GAC (i'm using RegDllView from www.nirsoft.net)
In the VB project I can create the object, so i assume the registration works properly. But when i call one of the methods i got a Run-time error ‘438’: Object doesn’t support this property or method
My VB Code looks like this:
Dim testi As Object
Dim fab As Object
Set fab = CreateObject("CRUFL_CS_ExchangeRate.ExchangeUfl")
Set testi = fab.t2()
It doesnt matter which method i call, i always get the same error :( Am I missing something? Have I done something wrong? Any ideas?
Thanks :)
Upvotes: 0
Views: 1275
Reputation: 10855
Skip the GAC, and do use the /codebase option.
When you register the .NET assemble using RegAsm, also export the typelib using the /tlb
option.
As a double-check, look in the registry for the objects you just registered in HKCR.
In your VB6 project, don't use the CreateObject
syntax. Instead, add a refernce to the typelib you exported earlier.
TIP: Avoid underscores in COM public signatures / class names. VB6 treats the underscore with special meaning in some edge cases. It is best to nip that in the bud.
Upvotes: 2