423,867 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,867 IT Pros & Developers. It's quick & easy.

VB6 automation error trying to use a COM-exposed C# DLL

P: n/a
Hi,

I have two PCs:
PC1: Visual Studio 2005 (including .NET framework 2.0.
PC2: Visual Studio 6 (using Visual Basic 6) + .NET framework 2.0 installed separately.

On PC1 I wrote and built a C# DLL (see code below), and created one .tlb and one .reg file to expose
its methods to COM.

On PC2 I copied the .dll, .tlb and .reg into WINDOWS\system32, and executed the .reg to insert new
entries to the registry. In Visual Basic 6, I created a new project, and added a reference to the
..tlb. So far, everything seems to be ok. I can see the class in the object inspector, and browse its
methods and enumerations. Also, the tool that shows as I type the valid methods and parameters works
ok. Compilation to exe works fine. Problems start at run time. Just trying to instantiate one
instance of the COM exposed class gives me a "Run-time error '-2147024894 (80070002) Automation
error'". See VB6 code below, too. Both listings have dummy code.

Any hint about what can this be due to?

Thank you,
Tremendo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace N_Proc_CC1100_Test
{
public enum RadiobandTypes
{
RadiobandR =0,
RadiobandRC,
RadiobandRCS,
RadiobandT
}
// ================================================== =======================
[GuidAttribute("AEB5062F-6695-4484-B07A-53C37A99E92B")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface _C_Proc_CC1100_Test
{
[DispIdAttribute(1)]
bool EnterTestMode(int RadiobandType);

[DispIdAttribute(2)]
bool LeaveTestMode();

[DispIdAttribute(3)]
bool GetSoftwareVersion(out int version);

[DispIdAttribute(4)]
bool TestRF(out double PeakFrequency_MHz,out double PeakPower_dBm);

[DispIdAttribute(5)]
bool SetOutputs(int outputs);

[DispIdAttribute(6)]
bool GetInputs(out int inputs);
}
// ================================================== =======================
[GuidAttribute("A9BA5B44-A432-44ab-9AFA-6C8058B20AA8")]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ProgIdAttribute("N_Test.C_Test")]
public class C_Proc_CC1100_Test : _C_Proc_CC1100_Test
{
public RadiobandTypes RadiobandType;
public bool InTestMode;
// .................................................. ...................
public C_Proc_CC1100_Test()
{
RadiobandType =RadiobandTypes.RadiobandR;
InTestMode =false;
}
// .................................................. ...................
public bool EnterTestMode(int RadiobandType)
{
this.RadiobandType =(RadiobandTypes)RadiobandType;

InTestMode =true;
return(true);
}
// .................................................. ...................
public bool LeaveTestMode()
{
InTestMode =false;
return(true);
}
// .................................................. ...................
public bool GetSoftwareVersion(out int version)
{
version =(int)0x1234;
return(true);
}
// .................................................. ...................
public bool TestRF(out double PeakFrequency_MHz,out double PeakPower_dBm)
{
PeakFrequency_MHz =868.9;
PeakPower_dBm =-65.0;
return(true);
}
// .................................................. ...................
public bool SetOutputs(int outputs)
{
return(true);
}
// .................................................. ...................
public bool GetInputs(out int inputs)
{
inputs =(int)0x5678;
return(true);
}
// .................................................. ...................
} // C_Proc_CC1100_Test
// ================================================== =======================
} // N_Proc_CC1100_Test

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%

Private Sub Command1_Click()

Dim oXXX As C_Proc_CC1100_Test
Set oXXX = New C_Proc_CC1100_Test

End Sub

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%

Feb 7 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Tremendo" <no****@hatespam.comwrote in message
news:04********************************@4ax.com...
Hi,

I have two PCs:
PC1: Visual Studio 2005 (including .NET framework 2.0.
PC2: Visual Studio 6 (using Visual Basic 6) + .NET framework 2.0 installed separately.

On PC1 I wrote and built a C# DLL (see code below), and created one .tlb and one .reg file
to expose
its methods to COM.

On PC2 I copied the .dll, .tlb and .reg into WINDOWS\system32, and executed the .reg to
insert new
entries to the registry. In Visual Basic 6, I created a new project, and added a reference
to the
.tlb. So far, everything seems to be ok. I can see the class in the object inspector, and
browse its
methods and enumerations. Also, the tool that shows as I type the valid methods and
parameters works
ok. Compilation to exe works fine. Problems start at run time. Just trying to instantiate
one
instance of the COM exposed class gives me a "Run-time error '-2147024894 (80070002)
Automation
error'". See VB6 code below, too. Both listings have dummy code.

Any hint about what can this be due to?

Thank you,
Tremendo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace N_Proc_CC1100_Test
{
public enum RadiobandTypes
{
RadiobandR =0,
RadiobandRC,
RadiobandRCS,
RadiobandT
}
// ================================================== =======================
[GuidAttribute("AEB5062F-6695-4484-B07A-53C37A99E92B")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface _C_Proc_CC1100_Test
{
[DispIdAttribute(1)]
bool EnterTestMode(int RadiobandType);

[DispIdAttribute(2)]
bool LeaveTestMode();

[DispIdAttribute(3)]
bool GetSoftwareVersion(out int version);

[DispIdAttribute(4)]
bool TestRF(out double PeakFrequency_MHz,out double PeakPower_dBm);

[DispIdAttribute(5)]
bool SetOutputs(int outputs);

[DispIdAttribute(6)]
bool GetInputs(out int inputs);
}
// ================================================== =======================
[GuidAttribute("A9BA5B44-A432-44ab-9AFA-6C8058B20AA8")]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ProgIdAttribute("N_Test.C_Test")]
public class C_Proc_CC1100_Test : _C_Proc_CC1100_Test
{
public RadiobandTypes RadiobandType;
public bool InTestMode;
// .................................................. ...................
public C_Proc_CC1100_Test()
{
RadiobandType =RadiobandTypes.RadiobandR;
InTestMode =false;
}
// .................................................. ...................
public bool EnterTestMode(int RadiobandType)
{
this.RadiobandType =(RadiobandTypes)RadiobandType;

InTestMode =true;
return(true);
}
// .................................................. ...................
public bool LeaveTestMode()
{
InTestMode =false;
return(true);
}
// .................................................. ...................
public bool GetSoftwareVersion(out int version)
{
version =(int)0x1234;
return(true);
}
// .................................................. ...................
public bool TestRF(out double PeakFrequency_MHz,out double PeakPower_dBm)
{
PeakFrequency_MHz =868.9;
PeakPower_dBm =-65.0;
return(true);
}
// .................................................. ...................
public bool SetOutputs(int outputs)
{
return(true);
}
// .................................................. ...................
public bool GetInputs(out int inputs)
{
inputs =(int)0x5678;
return(true);
}
// .................................................. ...................
} // C_Proc_CC1100_Test
// ================================================== =======================
} // N_Proc_CC1100_Test

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%

Private Sub Command1_Click()

Dim oXXX As C_Proc_CC1100_Test
Set oXXX = New C_Proc_CC1100_Test

End Sub

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%


You need to regasm the dll on the target system. You should also not install this in a
private folder not in a system folder like System32, use the "/codebase " option when
running regasm or register the dll in the GAC if you need this server to be accessible from
multiple clients.

Willy.

Feb 7 '07 #2

P: n/a
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:eM**************@TK2MSFTNGP03.phx.gbl...
"Tremendo" <no****@hatespam.comwrote in message
news:04********************************@4ax.com...
>error'". See VB6 code below, too. Both listings have dummy code.
Any hint about what can this be due to?
You need to regasm the dll on the target system. You should also not install this in a
private folder not in a system folder like System32, use the "/codebase " option when
running regasm or register the dll in the GAC if you need this server to be accessible
from multiple clients.

Willy.

Oh, and make sure you don't need other dependencies on the target machine. Or - the joy of
posting dummy code.

Willy.

Feb 7 '07 #3

P: n/a
"Tremendo" <no****@hatespam.comschrieb
Hi,

I have two PCs:
PC1: Visual Studio 2005 (including .NET framework 2.0.
PC2: Visual Studio 6 (using Visual Basic 6) + .NET framework 2.0
installed separately.

On PC1 I wrote and built a C# DLL (see code below), and created one
.tlb and one .reg file to expose its methods to COM.

On PC2 I copied the .dll, .tlb and .reg into WINDOWS\system32, and
executed the .reg to insert new entries to the registry. In Visual
Basic 6, I created a new project, and added a reference to the .tlb.
So far, everything seems to be ok. I can see the class in the object
inspector, and browse its methods and enumerations. Also, the tool
that shows as I type the valid methods and parameters works ok.
Compilation to exe works fine. Problems start at run time. Just
trying to instantiate one instance of the COM exposed class gives me
a "Run-time error '-2147024894 (80070002) Automation error'". See
VB6 code below, too. Both listings have dummy code.

Any hint about what can this be due to?
I don't know whether the .reg file is a replacement, but I usually only
deploy the DLL, then use regasm.exe /tlb to register the files on the client
machine and to have the tlb file created.

Armin
PS: I don't see the relation to VB.Net.

Feb 7 '07 #4

P: n/a
On Wed, 7 Feb 2007 11:42:25 +0100, "Willy Denoyette [MVP]" <wi*************@telenet.bewrote:
>You need to regasm the dll on the target system. You should also not install this in a
I guess you meant "You should also install", right? I assumed that, and installed the dll in a
private folder, as you can read in my other post.
>private folder not in a system folder like System32, use the "/codebase " option when
running regasm or register the dll in the GAC if you need this server to be accessible from
multiple clients.
Ok, this seems to work. I run "regasm Prod_CC1100_Test.dll /codebase /tlb", and it works for me. It
seems to need the "/codebase" option.

I didn't need to do anything with the GAC. Only one client will need to access that COM object (is
that the name?).

Thank you very much!

Feb 8 '07 #5

P: n/a
"Tremendo" <no****@hatespam.comwrote in message
news:p3********************************@4ax.com...
On Wed, 7 Feb 2007 11:42:25 +0100, "Willy Denoyette [MVP]" <wi*************@telenet.be>
wrote:
>>You need to regasm the dll on the target system. You should also not install this in a

I guess you meant "You should also install", right? I assumed that, and installed the dll
in a
private folder, as you can read in my other post.
Yep, that's what I meant.
>>private folder not in a system folder like System32, use the "/codebase " option when
running regasm or register the dll in the GAC if you need this server to be accessible
from
multiple clients.

Ok, this seems to work. I run "regasm Prod_CC1100_Test.dll /codebase /tlb", and it works
for me. It
seems to need the "/codebase" option.
The codebase option is all you need, just make sure you got your assembly signed.
I didn't need to do anything with the GAC. Only one client will need to access that COM
object (is
that the name?).
Multiple native COM clients can acces that COM server without the need to install it in the
GAC. The GAC is only required if you have multiple managed clients (or a mix of
native/managed) accessing the assembly.

Willy.

Feb 8 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.