473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

.NET server COM client interop problem (I think?)

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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
4 1300
Victoria,

Since ClassArgs needs to be used by the call to FunctionToCall, you
should export that correctly in COM like you would any other class. You
should change the method definition to take a type of IClassArgs, and define
IClassArgs as a separate interface, and pass around instances of that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Victoria Penrice" <vi*******@sytelco.com> wrote in message
news:u%***************@tk2msftngp13.phx.gbl...
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Thank you for your reply, Nicholas, I have now redefined my ClassArgs as
follows:

[Guid("13A803AF-CA7D-46b6-8485-9C3D1A549B00")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)]
public interface ClassArgsInterface
{
void SetFileName( string FileName );
}
[ClassInterface(ClassInterfaceType.None)]
public class ClassArgs : ClassArgsInterface
{
public ClassArgs(){}
public string m_FileName = "";

public void SetFileName( string FileName )
{
m_FileName = FileName;
}
}
...and redefined my FunctionToCall in ClassFunc as:
void FunctionToCall( ref ClassArgsInterface args )
{
//...
}

But now, how do we approach the problem of passing of the interface to
FunctionToCall()? How do we get a "pointer" to ClassArgsInterface in
VB6, please?

Thank you.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Victoria,

Why are you passing it by ref? You don't need the ref.
"Victoria Penrice" <vi*******@sytelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thank you for your reply, Nicholas, I have now redefined my ClassArgs as
follows:

[Guid("13A803AF-CA7D-46b6-8485-9C3D1A549B00")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)]
public interface ClassArgsInterface
{
void SetFileName( string FileName );
}
[ClassInterface(ClassInterfaceType.None)]
public class ClassArgs : ClassArgsInterface
{
public ClassArgs(){}
public string m_FileName = "";

public void SetFileName( string FileName )
{
m_FileName = FileName;
}
}
..and redefined my FunctionToCall in ClassFunc as:
void FunctionToCall( ref ClassArgsInterface args )
{
//...
}

But now, how do we approach the problem of passing of the interface to
FunctionToCall()? How do we get a "pointer" to ClassArgsInterface in
VB6, please?

Thank you.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

I got rid of "ref" in my C# code... and I also got rid of "As ClassArgs"
in:

Dim args As ClassArgs: Set args = New ClassArgs

...so now it looks like

Dim args
Set args = new ClassArgs

...and it works a treat! =)

Thanks to all for your help!!!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Dolheguy | last post by:
I am in desperate need to get help in answering some questions in regards to building a DCOM Server using C#. I need to create a DCOM server using C#.NET, I realise that you first need to create...
6
by: Chris | last post by:
Hi, - How can I open an existing word document from a C#-client and manipulate that document from within the C#-client ? - How can I open an excel document that is embedded in a word-document...
4
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property...
16
by: glenn | last post by:
I've gotten a COM server written in C# and I can call it from a VBScript just fine and it works perfectly. However, I import it into Delphi 6 or Delphi 2005 and I can not get access to any of the...
5
by: Dave A | last post by:
I am writing an ASP.NET tool that will allow the client to create their own online froms. ie the client can add tect boxes, text, drop downs,etc with absolutely no technical skill what so ever....
3
by: Hari Menon | last post by:
I am writing a C# client (using .NET 1.1) to a web service built on Apache Axis. The server returns an array using multirefs but the C# client does not seem to be able to recognize it. I read...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
9
by: oleggus | last post by:
I hope, I misunderstood some basics here and it is easy to solve.. I need a singleton object running on server which can be used(write and read) by different client interfaces - for example there...
0
by: user2008 | last post by:
Hi everybody, I'm working on exposing a .Net (C#) COM Server. Manage Code is exposting an interface with two methods. These methods take an IN/OUT Struct as parameter. Requirement is that the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.