Click to See Complete Forum and Search --> : user defined structure problem


cksiow
October 11th, 2001, 11:04 PM
I encounter the following error, what could be the cause ?? thanks

Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types


This error has the following cause and solution:

You attempted to use a public user defined type as a parameter or return type for a public procedure of a class module, or as a field of a public user defined type. Only public user defined types that are defined in a public object module can be used in this manner.



HTH

cksiow
http://vblib.virtualave.net - share our codes

Cakkie
October 12th, 2001, 01:45 AM
This happens when you have declared a userdefined type as public, and try to pass it to / return from a sub/function. For one reason or another, VB doesn't allow you to do this unless you place the userdefined type in a "public object modules". The only way I have got this working, was by placing the types in a seperate dll, and then refference the dll from the project. Pretty stupid I guess. What you can also do is pass the type back as variant, which does not require that, but doesn't give you the ease of programming, because it won't show its members when accessing it.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Cimperiali
October 12th, 2001, 02:18 AM
Cakkie said it right the first. It will not work simply as variant, you *must*
declare it in a dll class with instancing => creatable (=ie: multisue).
Then you can use it where you want, provided you add a reference to the dll,
and in your standard exe declare it as

private/public myUdt as mydllClassName.myInDllUdt.

Yes, it is silly, but this works. Remember: the "public module" message is
speaking about it is not a .bas module, but a class module with instancing
which must allow the creatabily.

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

cksiow
October 12th, 2001, 03:07 AM
thanks for the reply. however, I actually creating an activeX in VC++ which whereby I need to modify the object defination file .odl that generated by the wizard... so, actually creating a separate dll in VB doesn't help me in this case.

I understand why when u place the type in separate dll, it will work, probably because VB generate a unique UUID for the type and register it in registry. But actually I try it as well, I try to create a type library that contains the structure with unique UUID and hope that it will work, but failed... maybe I miss out something...

Anyway, thanks.


HTH

cksiow
http://vblib.virtualave.net - share our codes

Cimperiali
October 12th, 2001, 03:15 AM
You sure creating a separate dll will not help? youmay create it easily and see if adding it to references in vb will let you pass the udt to your C component (it should)

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

cksiow
October 12th, 2001, 03:53 AM
haven't try it out yet.. probably not the best solution as if I create the dll, I need to figure out a way to reference the dll in my vc components.... further, the user will need to add two reference into the projects, which is not good for lazy user.

I looking to bind the type information directly into the vc component and when the user add the component in vb project, it should have all the type info for that structure.... still finding solution.....

thanks.


HTH

cksiow
http://vblib.virtualave.net - share our codes