Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Sending User Defined Types over COM Interface

Sending User Defined Types over COM Interface

Scheduled Pinned Locked Moved COM
questioncomhelptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChemmieBro
    wrote on last edited by
    #1

    Hello, I'm pretty new to using COM and have run into a problem. I have a large structure, consisting of integers, user defined enumerations, several sub-structures and several dynamic arrays. How can I send this user defined type though COM? I'm trying to write my .idl file now to accept this structure... what needs to be done? My struct is much larger, but this small example should be enough to get me on the right track. //Example Struct: typedef struct { int index1; Image_Struct *Image_List; } My_Struct; //Image_Struct definition typedef struct { float pixel_x; float pixel_y; float pixel_z; } Image_Struct; Thank you!

    A L 2 Replies Last reply
    0
    • C ChemmieBro

      Hello, I'm pretty new to using COM and have run into a problem. I have a large structure, consisting of integers, user defined enumerations, several sub-structures and several dynamic arrays. How can I send this user defined type though COM? I'm trying to write my .idl file now to accept this structure... what needs to be done? My struct is much larger, but this small example should be enough to get me on the right track. //Example Struct: typedef struct { int index1; Image_Struct *Image_List; } My_Struct; //Image_Struct definition typedef struct { float pixel_x; float pixel_y; float pixel_z; } Image_Struct; Thank you!

      A Offline
      A Offline
      Andy Moore
      wrote on last edited by
      #2

      Take a look at this article on Code Project. http://www.codeproject.com/atl/udtdemo.asp Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons

      1 Reply Last reply
      0
      • C ChemmieBro

        Hello, I'm pretty new to using COM and have run into a problem. I have a large structure, consisting of integers, user defined enumerations, several sub-structures and several dynamic arrays. How can I send this user defined type though COM? I'm trying to write my .idl file now to accept this structure... what needs to be done? My struct is much larger, but this small example should be enough to get me on the right track. //Example Struct: typedef struct { int index1; Image_Struct *Image_List; } My_Struct; //Image_Struct definition typedef struct { float pixel_x; float pixel_y; float pixel_z; } Image_Struct; Thank you!

        L Offline
        L Offline
        Lim Bio Liong
        wrote on last edited by
        #3

        Hello ChemmieBro, You basically have to define your structs as User-Defined Types (UDT) in your IDL file. Listed below are examples of My_Struct and Image_Struct defined as UDTs : typedef [ uuid(C1B33DAB-A011-41ca-83E0-A7F5AEB01E52), version(1.0), helpstring("Image_Struct") ] struct Image_Struct // Image_Struct definition { [helpstring("X pixel position.")] float pixel_x; [helpstring("Y pixel position.")] float pixel_y; [helpstring("Z pixel position.")] float pixel_z; } Image_Struct; typedef [ uuid(AC11F3A5-855D-495d-B9CF-17EBA35ACC79), version(1.0), helpstring("My_Struct") ] struct My_Struct // Example Struct { [helpstring("index.")] int index1; [helpstring("The Image_Struct struct.")] Image_Struct* Image_List; } My_Struct; It is important that the UDT has got a GUID defined for it. This is defined in the "typedef" attribute for the struct. Also important is that all your fields -should- be (but not necessarily) automation-compatible types. Only so will your UDT be usable in VB. After this is done, define your interface and methods normally. Include My_Struct and/or Image_Struct types as parameters as per normal. Listed below is an example interface that refers to My_Struct : [ object, uuid(8F75662A-3CC4-42D1-8F2F-0C98E42594A6), dual, helpstring("IImageStructProcessor Interface"), pointer_default(unique) ] interface IImageStructProcessor : IDispatch { [id(1), helpstring("method ProcessMyStruct")] HRESULT ProcessMyStruct([in, out] My_Struct* pMyStruct); [id(2), helpstring("method FreeMyStructContents")] HRESULT FreeMyStructContents([in] My_Struct* pMyStruct); }; I have created some working example codes based on My_Struct, Image_Struct and the IImageStructProcessor interface. Send an email to me if you want a copy of the example codes. My email address is : bio_lim_2004@yahoo.com Best Regards, Bio.

        L 1 Reply Last reply
        0
        • L Lim Bio Liong

          Hello ChemmieBro, You basically have to define your structs as User-Defined Types (UDT) in your IDL file. Listed below are examples of My_Struct and Image_Struct defined as UDTs : typedef [ uuid(C1B33DAB-A011-41ca-83E0-A7F5AEB01E52), version(1.0), helpstring("Image_Struct") ] struct Image_Struct // Image_Struct definition { [helpstring("X pixel position.")] float pixel_x; [helpstring("Y pixel position.")] float pixel_y; [helpstring("Z pixel position.")] float pixel_z; } Image_Struct; typedef [ uuid(AC11F3A5-855D-495d-B9CF-17EBA35ACC79), version(1.0), helpstring("My_Struct") ] struct My_Struct // Example Struct { [helpstring("index.")] int index1; [helpstring("The Image_Struct struct.")] Image_Struct* Image_List; } My_Struct; It is important that the UDT has got a GUID defined for it. This is defined in the "typedef" attribute for the struct. Also important is that all your fields -should- be (but not necessarily) automation-compatible types. Only so will your UDT be usable in VB. After this is done, define your interface and methods normally. Include My_Struct and/or Image_Struct types as parameters as per normal. Listed below is an example interface that refers to My_Struct : [ object, uuid(8F75662A-3CC4-42D1-8F2F-0C98E42594A6), dual, helpstring("IImageStructProcessor Interface"), pointer_default(unique) ] interface IImageStructProcessor : IDispatch { [id(1), helpstring("method ProcessMyStruct")] HRESULT ProcessMyStruct([in, out] My_Struct* pMyStruct); [id(2), helpstring("method FreeMyStructContents")] HRESULT FreeMyStructContents([in] My_Struct* pMyStruct); }; I have created some working example codes based on My_Struct, Image_Struct and the IImageStructProcessor interface. Send an email to me if you want a copy of the example codes. My email address is : bio_lim_2004@yahoo.com Best Regards, Bio.

          L Offline
          L Offline
          Logan from Singapore
          wrote on last edited by
          #4

          Hi Bio, u seem quite activity in this COM section, have seen quite a few of your reply while I was searching for a solution to my problem. Hope you can help me with this. In your reply earlier, Lim Bio Liong wrote: Also important is that all your fields -should- be (but not necessarily) automation-compatible types. Only so will your UDT be usable in VB. So does this works for enum also? I think the initial question also include enum as on of the data type. I am also hoping to use some enum in my COM DLL. If it works for enum also, can other languages using my DLL be able to use this struct. Because I was hoping my COM DLL will works with as my languages as possible and not just VB only. Truth is not always popular, but it is always right.

          L 1 Reply Last reply
          0
          • L Logan from Singapore

            Hi Bio, u seem quite activity in this COM section, have seen quite a few of your reply while I was searching for a solution to my problem. Hope you can help me with this. In your reply earlier, Lim Bio Liong wrote: Also important is that all your fields -should- be (but not necessarily) automation-compatible types. Only so will your UDT be usable in VB. So does this works for enum also? I think the initial question also include enum as on of the data type. I am also hoping to use some enum in my COM DLL. If it works for enum also, can other languages using my DLL be able to use this struct. Because I was hoping my COM DLL will works with as my languages as possible and not just VB only. Truth is not always popular, but it is always right.

            L Offline
            L Offline
            Lim Bio Liong
            wrote on last edited by
            #5

            Hello w_logan, >> So does this works for enum also? Yes. It works also for enum. The following is an example of how to define an automation-compatible enum in IDL : typedef [uuid(B5051CD9-A577-451b-BDD8-17AC68ED27BB)] enum { enum_value_0 = 0, enum_value_1 = 1, enum_value_2 = 2, enum_value_3 = 3 } EnumValue; Yes, the "typedef" keyword and the "uuid" attribute is necessary for proper definition of the enum type so that it is automation-compatible. Thereafter, you may include EnumValue as a type that can be used in your automation-compatible struct, e.g. : typedef [ uuid(1F2AFC9C-2ACB-4fc3-A415-8E0736B3C4BB), version(1.0), helpstring("My_Struct_VB_2") ] struct My_Struct_VB_2 // Example Struct { [helpstring("index.")] int index1; [helpstring("The Image_Struct struct.")] Image_Struct Image_List; [helpstring("EnumValue value.")] EnumValue ev1; } My_Struct_VB_2; >> can other languages using my DLL be able to use this struct. Because I was hoping my COM DLL will works with as my languages as possible and not just VB only. This very much depends on the language's IDE. VB and the Visual C# IDE do support most if not all of the automation-compatible IDL constructs. I haven't used Delphi or the other language IDEs yet so I wouldn't be able to comment on those. Send me an email and I can send you my sample program. Best Regards, Bio.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups