Link to home
Start Free TrialLog in
Avatar of AA69
AA69

asked on

UDT TYPES AGAIN!!!!!!!

Hi,

I have a problem with UDT's. The problem is mainly trying to pass them
around functions as parameters, when the functions receiving them as
parameters need to be generic. The UDTs are required because they represent
C Structures on another UNIX type platform.

Some Code........

In a public .bas file

Public Type TEST1
    str1 as String *10
    str2 as String *20
End Type

Public Type TEST2
    str1 as String *10
    str2 as TEST1
End Type

Public Type TEST4
    str1 as String *10
    str2(21) as TEST2
End Type

In a class module that needs to pass the UDTs around as parameters to other
functions.

Private Type TEST3
    strBuffer as string * len(TEST2) ' I know you can't do this in code but
its here for illustration purposes
End Type

Private Type TEST5
    strBuffer as string * len(TEST4) ' I know you can't do this in code but
its here for illustration purposes
End Type

I can use Lset to do the following
TEST3.strBuffer = "A constant string that represents data in a passed C
structure the length and format of UDT"

Lset TEST4=TEST2
This stuffs TEST2 into TEST4 thereby populating TEST4 with the data in TEST2
in the required format.

However I can't use Lset to do this......

TEST5.strBuffer = "A constant string that represents data in a passed C
structure the length and format of UDT"

Lset TEST4=TEST5

This is supposed to stuff TEST5 into TEST4 thereby populating TEST4 with the
data in TEST2 in the required format.
The problem is that because TEST5 contains an array of UDT's this causes VB
to poke up a type mismatch error.

I can pass around TEST3.strBuffer but not a specific UDT because of the
following

Public Function Test6(strIN as string)

    ' This allows me to pass in any string of any length

End Function

Public Function Test7(udtIN as TEST4)

    ' This allows me to pass in a udt of a predefined specific type
   ' eg TEST4 and doesn't allow me to pass any UDT into this function

End Function

Is there any other way I can do this???

A very fustrated,

Andy
Avatar of RodStephens
RodStephens

If your goal is to pass various objects to a function written in C/C++, you may be able to get there using the Declare statement.

> Lset TEST4=TEST5

If you just want to pass the data in TEST5 into a function that expects a character pointer to the data, declare the function to take a TEST5 object as a parameter. When you call the routine, the address of the TEST5 is passed into the function. It only knows it has received a pointer, not what kind of thing it points to.

> ' eg TEST4 and doesn't allow me to pass any UDT into
> this function

If you want to be able to pass any UDT into a function, either:

1. Try declaring the argument as Any.
2. Make multiple declarations for the function.

Public Declare Function AbortDoc Lib "gdi32" Alias "AbortDoc" (ByVal hdc As Long) As Long

Public Declare Function Whatever1 Lib "C:\test.dll" _
    Alias "Whatever" (ByVal value As TEST1) As Long
Public Declare Function Whatever2 Lib "C:\test.dll" _
    Alias "Whatever" (ByVal value As TEST2) As Long

Then use the right version of the function depending on the argument you want to pass it.
ASKER CERTIFIED SOLUTION
Avatar of ameba
ameba
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>"UDT TYPES AGAIN!!!!!!!"
Here is the link to previous question "UDT TYPES!!!" (20 pts)
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20131345
Avatar of AA69

ASKER

Good point I should have put that link in I'll remember next time. I'll try that code and report back again.
Avatar of AA69

ASKER

Good point I should have put that link in I'll remember next time. I'll try that code and report back again.
Avatar of AA69

ASKER

Hi Sorry for the delay in giving out the points( holidays and all that). Anyway we actually still used lset and didn't need to use the memcopy function we simply built up the UDT using simple for next loops and concatenating the strings as we went it all works just dandy. But your answer is still valid and I might well use that somewhere else so you get the points. Just one thing could you please point me to Rockford Lhotka's book.
Thanks
http://www.lhotka.net/rocky/Publications.aspx
Just click on:  "Professional Visual Basic 6 Distributed Objects" book
Note that book is not quite easy to read / understand.