简体   繁体   中英

how do you pass a C# COM interropt DLL as param in vb6

I have a C# DLL that is being used as a class to contain a list of properties about a file.
The C# DLL is COM visible, and is able to be declared and instantiated in VB6.
Inside my vb6 function where I create the object..

Dim fileObj As New MyCSharpClass.FileProperties

I am immediately able to see all the different properties accessible to my C# FileProperties object.
fileObj.(intellisense) shows me the dropdown list of anything available inside the object
But when I pass my object to a function..

GetProperties(fileObj)

When I am inside GetProperties

Public Function GetProperties(ByRef pfileObj As MyCSharpClass.FileProperties)

When I try to have intellisense show me what options are available to me..
it does now recognize pfileObj as a variable I can use, it will not show up in intellisense
If I try to manually type it out, once again intellisense will not show me any options.

pfileObj.

Is there a special way to pass COM interropt objects around to functions they were not delcared in inside of VB6?
Is this simply not possible?
I was trying to avoid creating functions that return strings, and then assign to the object properties one at a time.

The reason is because you need to have .NET create a TypeLib file which you can then reference from VB6. VB6 will use this to display intellisense as well as assist VB6 in how to invoke your C# object. You need to do the following items:

  1. Declare an interface in C# which will publicly expose the properties/methods that you want VB6 to access.
  2. Implement the interface in your C# object using the colon character after your class name.
  3. Create a strong name for your project using the Strong name command line utility. (You can do this in the project properties in Visual Studio .NET).
  4. Use the command line utility regasm.exe to create the necessary TypeLib file.
  5. Use gacutil to add your newly created tlb file to the GAC.
  6. Create a reference to the newly create .tlb file from VB6 (Project > References).

You can find the detailed instructions here: http://www.codeproject.com/Articles/3511/Exposing-NET-Components-to-COM . The article may be old but for the most part it is still applicable to the modern versions of Visual Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM