Passing a simple structure from VB6 to VB.Net Options

B

Bully

Hi

I have created a simple COM Class in VB.Net containing a simple
structure and function:

Public Structure MyStruct
Dim Param1 As Byte
End Structure

Public Function ShowStruct(ByRef MyPassedStruct As MyStruct)

' Do nothing

End Function


In VB6, I want to call the .Net function and pass the structure.

Public Type MyStruct
Param1 As Byte
End Type

Private Sub Command1_Click()
Dim netCall as New netDll
Dim testStruct as MyStruct

testStruct.Param1 = 10

Call netCall.ShowStruct(testStruct)

End Sub


When I try and comple my VB app it gives me an error saying 'ByRef
Argument Mismatch'. What am I doing wrong?


I have managed to pass integers and strings ok, I'm just having a
problem with structures.


Thanks
Jon
 
S

Steve Gerrard

Bully said:
Hi

I have created a simple COM Class in VB.Net containing a simple
structure and function:

Public Structure MyStruct
Dim Param1 As Byte
End Structure

In VB6, I want to call the .Net function and pass the structure.

Public Type MyStruct
Param1 As Byte
End Type
When I try and comple my VB app it gives me an error saying 'ByRef
Argument Mismatch'. What am I doing wrong?

You can't define MyStruct again in VB6. That makes it a different structure
(regardless of name or how much they look alike).

After removing that, you're VB6 Call needs declare an instance of MyStruct as
defined in your dll.
It might look something like

Private Sub Command1_Click()
Dim netCall as New netDll
Dim testStruct as netDll.MyStruct

testStruct.Param1 = 10

Call netCall.ShowStruct(testStruct)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top