V
Victoria Penrice
Dear all,
I've written a dll (in C#), to be used as a COM object in VB6. Say (for
simplicity) I've defined two classes in that dll: ClassFunc and
ClassArgs. One of the functions in ClassFunc (say, called
"FunctionToCall") takes an instance of ClassArgs as a parameter, like
this:
public void FunctionToCall( ClassArgs arg )
Now, imagine we are in VB6. We've created instances of both classes, and
successfully initialised them. But as soon as we try to use
FunctionToCall, we get an error. If we redefine FunctionToCall and make
it take a string (for example), everything works fine.
To expand, here's how I defined the first class:
public class ClassArgs
{
public ClassArgs(){}
private string m_FileName = "";
public void SetFileName( string FileName )
{
m_FileName = FileName;
}
}
...then the second class:
[Guid("13A803AF-CA7D-46b6-8485-9C3D1A549B09")]
public interface ClassFuncInterface
{
void FunctionToCall( ClassArgs ags );
}
//... some code for events omitted here
[Guid("4749F529-744E-4642-AF71-BDA6C8068D8B")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class ClassFunc: ClassFuncInterface
{
public ClassFunc(){}
private string FILE_NAME = "ComTestOk.txt";
public virtual void FunctionToCall( ClassArgs args )
{
StreamWriter sr = File.CreateText(args.GetFileName());
sr.Close();
}
//... some code for events omitted here
}
//********************************************************
I register my dll with COM and provide a ref to the corresponding tlb in
my VB6 app, where I use my classes as follows:
Dim WithEvents Func As ClassFunc
Private Sub Command1_Click()
Set Func = New ClassFunc
Dim Args As ClassArgs: Set Args = New ClassArgs
Args.SetFileName ("SomeFile.txt")
Func.FunctionToCall (Args)
End Sub
//********************************************************
I am getting an "Invalid procedure call or argument" error at line:
Func.FunctionToCall (Args)
Any ideas, please?
Thank you.
I've written a dll (in C#), to be used as a COM object in VB6. Say (for
simplicity) I've defined two classes in that dll: ClassFunc and
ClassArgs. One of the functions in ClassFunc (say, called
"FunctionToCall") takes an instance of ClassArgs as a parameter, like
this:
public void FunctionToCall( ClassArgs arg )
Now, imagine we are in VB6. We've created instances of both classes, and
successfully initialised them. But as soon as we try to use
FunctionToCall, we get an error. If we redefine FunctionToCall and make
it take a string (for example), everything works fine.
To expand, here's how I defined the first class:
public class ClassArgs
{
public ClassArgs(){}
private string m_FileName = "";
public void SetFileName( string FileName )
{
m_FileName = FileName;
}
}
...then the second class:
[Guid("13A803AF-CA7D-46b6-8485-9C3D1A549B09")]
public interface ClassFuncInterface
{
void FunctionToCall( ClassArgs ags );
}
//... some code for events omitted here
[Guid("4749F529-744E-4642-AF71-BDA6C8068D8B")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class ClassFunc: ClassFuncInterface
{
public ClassFunc(){}
private string FILE_NAME = "ComTestOk.txt";
public virtual void FunctionToCall( ClassArgs args )
{
StreamWriter sr = File.CreateText(args.GetFileName());
sr.Close();
}
//... some code for events omitted here
}
//********************************************************
I register my dll with COM and provide a ref to the corresponding tlb in
my VB6 app, where I use my classes as follows:
Dim WithEvents Func As ClassFunc
Private Sub Command1_Click()
Set Func = New ClassFunc
Dim Args As ClassArgs: Set Args = New ClassArgs
Args.SetFileName ("SomeFile.txt")
Func.FunctionToCall (Args)
End Sub
//********************************************************
I am getting an "Invalid procedure call or argument" error at line:
Func.FunctionToCall (Args)
Any ideas, please?
Thank you.