Results 1 to 12 of 12

Thread: Variable uses an automation type not supported in Visual Basic

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    126

    Variable uses an automation type not supported in Visual Basic

    Hi to All

    I have some problem calling a com dll from VB6.

    In the object Browser i See:
    Code:
    Sub CreateIterator(iid As GUID, ppv As Any)
    I think the problem is the GUID.(in stdole)

    This is the IDL description:

    Code:
       [
        object,
        uuid(1E8701D0-258F-43ED-9EDC-434FD16E922D),
        helpstring("Switcher Object")
    ] interface IBMDSwitcher : IUnknown
    {
        HRESULT CreateIterator([in] REFIID iid, [out] LPVOID* ppv);
    I can't call CreateIterator from vb6. I get the error
    "Variable uses an automation type not supported in Visual Basic"

    How I can get this interface?


    Please Help me.

    Thanks to all
    Last edited by Nanni; Apr 23rd, 2012 at 01:39 AM.

  2. #2
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Variable uses an automation type not supported in Visual Basic

    My view is that you're going to need to declare the GUID in IDL, and, also, redeclare LPVOID* as long*, and then derference to get to the actual value.

    A similar problem occurs when you try to grab hold of the IUnknown interface - which you *can* redeclare and is useful for storing arrays of objects and making sure when the array goes out of scope - and therefore the objects contained within them go out of scope, that you can call IUnknown->Release.

    Code:
    [
      uuid(F8EA7708-1EAA-11DA-8CD6-0800200C9A66),
      version(1.0),
      helpstring("SomeLibrary")
    ]
    library SomeLibrary
    {
    
        interface IUnknownUnrestricted;
    
        typedef struct tagVBGUID {
            long Data1;
            short Data2;
            short Data3;
            unsigned char Data4[8];
        } VBGUID;
    
        [
          odl,
          uuid(00000000-0000-0000-C000-000000000046)
        ]
        interface IUnknownUnrestricted {
            long QueryInterface([in] VBGUID* riid, [in, out] long* ppvObj);
            long AddRef();
            long Release();
        };
    };
    Hope it helps. If I recall correctly you can't compile this with MIDL and have to use some form of ODL compiler for this fragment - declaring your VBGUID should work in MIDL though.

    Y
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    126

    Re: Variable uses an automation type not supported in Visual Basic

    Hello
    thanks for reply and suggestions.

    I have modified the IDL by adding GUID struct:

    Code:
    typedef struct GUID {
            long Data1;
            short Data2;
            short Data3;
            unsigned char Data4[8];
        } GUID;
    and modifying:
    Code:
    HRESULT CreateIterator([in] REFIID iid, [out] LPVOID* ppv);
    in
    Code:
    HRESULT CreateIterator([in] GUID* iid, [out] long*  ppv);
    Now I can call CreateIterator without problem...but another problem

    I have to Get/Set value:
    there is no problem to get the values ​​from the dll , but when
    I try to set the values ​​, I get (for for any datatype)
    the error 5:Invalid procedure call or argument

    This is the IDL description: BlockPropertyId are constant

    Code:
        HRESULT SetFlag([in] BlockPropertyId propertyId, [in] BOOL value);
        HRESULT GetFlag([in] BlockPropertyId propertyId, [out] BOOL* value);
        HRESULT SetInt([in] BlockPropertyId propertyId, [in] LONG value);
        HRESULT GetInt([in] BlockPropertyId propertyId, [out] LONG* value);
        HRESULT SetFloat([in] BlockPropertyId propertyId, [in] double value);
        HRESULT GetFloat([in] BlockPropertyId propertyId, [out] double* value);
        HRESULT SetString([in] BlockPropertyId propertyId, [in] BSTR value);
        HRESULT GetString([in] BlockPropertyId propertyId, [out] BSTR* value);
    Do you have any idea about this error ?

    Thanks for Help

  4. #4
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Variable uses an automation type not supported in Visual Basic

    You have to use the [PropGet], and [PropSet] attributes if you want VB to see them as native properties, and you must use 'known' datatypes.

    For instance - here's one I made earlier,

    Code:
    // string.idl
    // (c) ******** April 2006
    //
    // Interface(s) to support string handling. BSTR's are fine
    // for small strings, but we'll need to implement much faster
    // code than VB's native stuff in order to create large
    // strings efficiently and manipulate them.
    
    [
    	uuid(8a4bb590-c9fc-11da-a94d-0800200c9a66),
    	version(1.0),
    	helpstring ("******** Interfaces String")
    ]
    
    library InterfacesString
    {	
    	importlib("stdole2.tlb");
    
    	// Forward declare interfaces
    	interface IString;
    	interface IStringIterator;
    
    	// Interface IGlyph
    	[
    		object,
    		uuid(8a4bb591-c9fc-11da-a94d-0800200c9a66),
    		version(1.0),
    		helpstring ("****** Interface String")
    	]
    	interface IString : IUnknown
    	{
    		//Read/Write Properties
    		[propput] HRESULT Size ([in,out] long* Value);
    		[propget] HRESULT Size ([out,retval] long*);
    
    		//Methods
    		HRESULT Append ([in,out] BSTR* Value);
    		HRESULT Value ([out,retval] BSTR*);
    		HRESULT Clear();
    		HRESULT StrPtr ([out,retval] long*);
    		HRESULT CopyData ([in,out] long* Source, [in,out] long* Length);
    	};
    
    	//Interface IStringIterator
    	[
    		object,
    		uuid(8a4bdca0-c9fc-11da-a94d-0800200c9a66),
    		version(1.0),
    		helpstring ("*******Interface String Iterator")
    	]
    	interface IStringIterator : IUnknown
    	{
    		// Read/Write Properties
    		[propput] HRESULT Item([in,out] BSTR*);
    		[propget] HRESULT Item([out,retval] BSTR*);
    		
    		//Methods
    		HRESULT Succ();
    		HRESULT Pred();
    		HRESULT First();
    		HRESULT Last();
    		HRESULT IsDone([out,retval] VARIANT_BOOL*);
    	};
    };
    You certainly need to try and avoid using BOOL, and change your stuff to use VARIANT_BOOL. And I would certainly advise that you use the [PropGet], and [PropSet] attribiutes rather than the pseudo Java-camel-hump style method naming convention if you want to use this with VB/VBA.

    Please redefine the UUID's I include them only so you can get a compilation unit for messing around with

    Cheers,

    Y
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    126

    Re: Variable uses an automation type not supported in Visual Basic

    Hello

    I'm sorry ... but I would not be annoying.
    I 'm trying to use a third-party com dll.
    I don't have source of this dll,but I have c++ and C# code
    that successfully use this dll.

    I have the IDL description of this dll.
    I 'm trying to modify this IDL for use dll from vb6.

    Using :
    Code:
    HRESULT SetString([in] BlockPropertyId propertyId, [in] BSTR value);
    I see in the object browser:
    Code:
    Sub SetString(propertyId As BlockPropertyId, value As String)
    Why I can't use this code in vb6:
    Code:
    Object.SetString propertyId, "Hello"
    I get the error 5:Invalid procedure call or argument


    I have tried with [propput] [propget] but without success.
    Can you show me how to change this IDL description using [propput]?
    Code:
    HRESULT SetString([in] BlockPropertyId propertyId, [in] BSTR value);
    Why I can use :
    Code:
    HRESULT GetString([in] BlockPropertyId propertyId, [out] BSTR* value);
    In vb6:
    Code:
    Dim strValue as string
    Object.GetString propertyId, strValue
    without problems ?


    Sorry,but I am very frustrated after days of failure.
    Thanks for Help

    Regards

  6. #6
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Variable uses an automation type not supported in Visual Basic

    Is this a COM DLL, or a bog-standard DLL like something you might see in the Win API? Where is the datatype BlockPropertyId defined? What is it?
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    126

    Re: Variable uses an automation type not supported in Visual Basic

    Hello

    This is the Original Partial IDL for the COM dll:

    Code:
    import "unknwn.idl";
    
    [uuid(8A92B919-156C-4D61-94EF-03F9BE4004B0),
    version(1.0), helpstring("Switcher API Library")]
    library SwitcherAPI
    {
    
    // Type Declarations
    
    typedef LONGLONG SwitcherInputId;
    
    // Enumeration Mapping
    
    cpp_quote("#if 0")
    cpp_quote("#endif")
    
    typedef [v1_enum] enum	_SwitcherInputPropertyId {
        SwitcherInputPropertyIdPortType                           = /* 'prtp' */ 0x70727470,	// Int type (SwitcherPortType), Get only
        SwitcherInputPropertyIdInputAvailability                  = /* 'avlb' */ 0x61766C62,	// Int type (SwitcherInputAvailability), Get only
        SwitcherInputPropertyIdShortName                          = /* 'shnm' */ 0x73686E6D,	// String type, Get only
        SwitcherInputPropertyIdLongName                           = /* 'lgnm' */ 0x6C676E6D		// String type, Get only
    } SwitcherInputPropertyId;
    
    typedef [v1_enum] enum	_SwitcherInputAvailability {
        SwitcherInputAvailabilityMixEffectBlock0                  = 0x00000001,
        SwitcherInputAvailabilityMixEffectBlock1                  = 0x00000002
    } SwitcherInputAvailability;
    
    typedef [v1_enum] enum	_SwitcherPortType {
        SwitcherPortTypeExternal                                  = /* 'extn' */ 0x6578746E,
        SwitcherPortTypeBlack                                     = /* 'blak' */ 0x626C616B,
        SwitcherPortTypeColorBars                                 = /* 'colb' */ 0x636F6C62,
        SwitcherPortTypeColorGenerator                            = /* 'colg' */ 0x636F6C67,
        SwitcherPortTypeMediaPlayerFill                           = /* 'mpfl' */ 0x6D70666C,
        SwitcherPortTypeMediaPlayerCut                            = /* 'mpct' */ 0x6D706374,
        SwitcherPortTypeSuperSource                               = /* 'ssrc' */ 0x73737263,
        SwitcherPortTypeMixEffectBlockOutput                      = /* 'mebo' */ 0x6D65626F,
        SwitcherPortTypeAuxOutput                                 = /* 'auxo' */ 0x6175786F
    } SwitcherPortType;
    
    typedef [v1_enum] enum	_BlockPropertyId {
        BlockPropertyIdProgramInput              = /* 'pgip' */ 0x70676970,	// Int type (SwitcherInputId), Get/Set
        BlockPropertyIdPreviewInput              = /* 'pvip' */ 0x70766970,	// Int type (SwitcherInputId), Get/Set
        BlockPropertyIdTransitionPosition        = /* 'tsps' */ 0x74737073,	// Float type, Get/Set
        BlockPropertyIdTransitionFramesRemaining = /* 'tfrm' */ 0x7466726D,	// Int type, Get only
        BlockPropertyIdInTransition              = /* 'iits' */ 0x69697473,	// Flag type, Get only
        BlockPropertyIdFadeToBlackFramesRemaining = /* 'ffrm' */ 0x6666726D,	// Int type, Get only
        BlockPropertyIdInFadeToBlack             = /* 'iifb' */ 0x69696662,	// Flag type, Get only
        BlockPropertyIdPreviewLive               = /* 'pvlv' */ 0x70766C76,	// Flag type, Get only
        BlockPropertyIdPreviewTransition         = /* 'pvts' */ 0x70767473,	// Flag type, Get/Set
        BlockPropertyIdFadeToBlackRate           = /* 'ftbr' */ 0x66746272	// Int type, Get/Set
    } BlockPropertyId;
    
    interface SwitcherEffectBlockCallback;
    interface SwitcherEffectBlock;
    interface SwitcherInputCallback;
    interface SwitcherInput;
    interface SwitcherInputIterator;
    interface SwitcherEffectBlockIterator;
    interface SwitcherCallback;
    interface Switcher;
    
    [
        object,
        uuid(8E583D89-0BAF-4447-AB8C-6A12CD8724CB),
        helpstring("Base Switcher Input Object Callback")
    ] interface SwitcherInputCallback : IUnknown
    {
        HRESULT PropertyChanged([in] SwitcherInputPropertyId propertyId);
    };
    
    [
        object,
        uuid(66F3D466-8C8C-4DB4-B313-8DD2EC665DBB),
        helpstring("Base Switcher Input Object")
    ] interface SwitcherInput : IUnknown
    {
        HRESULT AddCallback([in] SwitcherInputCallback* callback);
        HRESULT RemoveCallback([in] SwitcherInputCallback* callback);
        HRESULT SetFlag([in] SwitcherInputPropertyId propertyId, [in] BOOL value);
        HRESULT GetFlag([in] SwitcherInputPropertyId propertyId, [out] BOOL* value);
        HRESULT SetInt([in] SwitcherInputPropertyId propertyId, [in] LONGLONG value);
        HRESULT GetInt([in] SwitcherInputPropertyId propertyId, [out] LONGLONG* value);
        HRESULT SetFloat([in] SwitcherInputPropertyId propertyId, [in] double value);
        HRESULT GetFloat([in] SwitcherInputPropertyId propertyId, [out] double* value);
        HRESULT SetString([in] SwitcherInputPropertyId propertyId, [in] BSTR value);
        HRESULT GetString([in] SwitcherInputPropertyId propertyId, [out] BSTR* value);
        HRESULT GetInputId([out] SwitcherInputId* inputId);
    };
    
    [
        object,
        uuid(92AB7A73-C6F6-47FC-92A7-C8EEADC9EAAC),
        helpstring("Input Iterator")
    ] interface SwitcherInputIterator : IUnknown
    {
        HRESULT Next([out] SwitcherInput** input);
        HRESULT GetById([in] SwitcherInputId inputId, [out] SwitcherInput** input);
    };
    [
        object,
        uuid(1E8701D0-258F-43ED-9EDC-434FD16E922D),
        helpstring("Switcher Object")
    ] interface Switcher : IUnknown
    {
        HRESULT CreateIterator([in] REFIID iid, [out] LPVOID* ppv);
        HRESULT AddCallback([in] SwitcherCallback* callback);
        HRESULT RemoveCallback([in] SwitcherCallback* callback);
        HRESULT SetFlag([in] SwitcherPropertyId propertyId, [in] BOOL value);
        HRESULT GetFlag([in] SwitcherPropertyId propertyId, [out] BOOL* value);
        HRESULT SetInt([in] SwitcherPropertyId propertyId, [in] LONGLONG value);
        HRESULT GetInt([in] SwitcherPropertyId propertyId, [out] LONGLONG* value);
        HRESULT SetFloat([in] SwitcherPropertyId propertyId, [in] double value);
        HRESULT GetFloat([in] SwitcherPropertyId propertyId, [out] double* value);
        HRESULT SetString([in] SwitcherPropertyId propertyId, [in] BSTR value);
        HRESULT GetString([in] SwitcherPropertyId propertyId, [out] BSTR* value);
    };
    ...and this is the Modified IDL:

    Code:
    import "unknwn.idl";
    
    [uuid(8A92B919-156C-4D61-94EF-03F9BE4004B0),
    version(1.0), helpstring("Switcher API Library")]
    library SwitcherAPI
    {
    
    // Type Declarations
    
    typedef LONG SwitcherInputId;
    
    // Enumeration Mapping
    
    cpp_quote("#if 0")
    cpp_quote("#endif")
    
    typedef [v1_enum] enum	_SwitcherInputPropertyId {
        SwitcherInputPropertyIdPortType                           = /* 'prtp' */ 0x70727470,	// Int type (SwitcherPortType), Get only
        SwitcherInputPropertyIdInputAvailability                  = /* 'avlb' */ 0x61766C62,	// Int type (SwitcherInputAvailability), Get only
        SwitcherInputPropertyIdShortName                          = /* 'shnm' */ 0x73686E6D,	// String type, Get only
        SwitcherInputPropertyIdLongName                           = /* 'lgnm' */ 0x6C676E6D		// String type, Get only
    } SwitcherInputPropertyId;
    
    typedef [v1_enum] enum	_SwitcherInputAvailability {
        SwitcherInputAvailabilityMixEffectBlock0                  = 0x00000001,
        SwitcherInputAvailabilityMixEffectBlock1                  = 0x00000002
    } SwitcherInputAvailability;
    
    typedef [v1_enum] enum	_SwitcherPortType {
        SwitcherPortTypeExternal                                  = /* 'extn' */ 0x6578746E,
        SwitcherPortTypeBlack                                     = /* 'blak' */ 0x626C616B,
        SwitcherPortTypeColorBars                                 = /* 'colb' */ 0x636F6C62,
        SwitcherPortTypeColorGenerator                            = /* 'colg' */ 0x636F6C67,
        SwitcherPortTypeMediaPlayerFill                           = /* 'mpfl' */ 0x6D70666C,
        SwitcherPortTypeMediaPlayerCut                            = /* 'mpct' */ 0x6D706374,
        SwitcherPortTypeSuperSource                               = /* 'ssrc' */ 0x73737263,
        SwitcherPortTypeMixEffectBlockOutput                      = /* 'mebo' */ 0x6D65626F,
        SwitcherPortTypeAuxOutput                                 = /* 'auxo' */ 0x6175786F
    } SwitcherPortType;
    
    typedef [v1_enum] enum	_BlockPropertyId {
        BlockPropertyIdProgramInput              = /* 'pgip' */ 0x70676970,	// Int type (SwitcherInputId), Get/Set
        BlockPropertyIdPreviewInput              = /* 'pvip' */ 0x70766970,	// Int type (SwitcherInputId), Get/Set
        BlockPropertyIdTransitionPosition        = /* 'tsps' */ 0x74737073,	// Float type, Get/Set
        BlockPropertyIdTransitionFramesRemaining = /* 'tfrm' */ 0x7466726D,	// Int type, Get only
        BlockPropertyIdInTransition              = /* 'iits' */ 0x69697473,	// Flag type, Get only
        BlockPropertyIdFadeToBlackFramesRemaining = /* 'ffrm' */ 0x6666726D,	// Int type, Get only
        BlockPropertyIdInFadeToBlack             = /* 'iifb' */ 0x69696662,	// Flag type, Get only
        BlockPropertyIdPreviewLive               = /* 'pvlv' */ 0x70766C76,	// Flag type, Get only
        BlockPropertyIdPreviewTransition         = /* 'pvts' */ 0x70767473,	// Flag type, Get/Set
        BlockPropertyIdFadeToBlackRate           = /* 'ftbr' */ 0x66746272	// Int type, Get/Set
    } BlockPropertyId;
    
    typedef struct GUID {
            long Data1;
            short Data2;
            short Data3;
            unsigned char Data4[8];
        } GUID;
    
    
    interface SwitcherEffectBlockCallback;
    interface SwitcherEffectBlock;
    interface SwitcherInputCallback;
    interface SwitcherInput;
    interface SwitcherInputIterator;
    interface SwitcherEffectBlockIterator;
    interface SwitcherCallback;
    interface Switcher;
    
    [
        object,
        uuid(8E583D89-0BAF-4447-AB8C-6A12CD8724CB),
        helpstring("Base Switcher Input Object Callback")
    ] interface SwitcherInputCallback : IUnknown
    {
        HRESULT PropertyChanged([in] SwitcherInputPropertyId propertyId);
    };
    
    [
        object,
        uuid(66F3D466-8C8C-4DB4-B313-8DD2EC665DBB),
        helpstring("Base Switcher Input Object")
    ] interface SwitcherInput : IUnknown
    {
        HRESULT AddCallback([in] SwitcherInputCallback* callback);
        HRESULT RemoveCallback([in] SwitcherInputCallback* callback);
        HRESULT SetFlag([in] SwitcherInputPropertyId propertyId, [in] BOOL value);
        HRESULT GetFlag([in] SwitcherInputPropertyId propertyId, [out] BOOL* value);
        HRESULT SetInt([in] SwitcherInputPropertyId propertyId, [in] LONG value);
        HRESULT GetInt([in] SwitcherInputPropertyId propertyId, [out] LONG* value);
        HRESULT SetFloat([in] SwitcherInputPropertyId propertyId, [in] double value);
        HRESULT GetFloat([in] SwitcherInputPropertyId propertyId, [out] double* value);
        HRESULT SetString([in] SwitcherInputPropertyId propertyId, [in] BSTR value);
        HRESULT GetString([in] SwitcherInputPropertyId propertyId, [out] BSTR* value);
        HRESULT GetInputId([out] SwitcherInputId* inputId);
    };
    
    [
        object,
        uuid(92AB7A73-C6F6-47FC-92A7-C8EEADC9EAAC),
        helpstring("Input Iterator")
    ] interface SwitcherInputIterator : IUnknown
    {
        HRESULT Next([out] SwitcherInput** input);
        HRESULT GetById([in] SwitcherInputId inputId, [out] SwitcherInput** input);
    };
    [
        object,
        uuid(1E8701D0-258F-43ED-9EDC-434FD16E922D),
        helpstring("Switcher Object")
    ] interface Switcher : IUnknown
    {
        HRESULT CreateIterator([in] GUID* iid, [out] long*  ppv);
        HRESULT AddCallback([in] SwitcherCallback* callback);
        HRESULT RemoveCallback([in] SwitcherCallback* callback);
        HRESULT SetFlag([in] SwitcherPropertyId propertyId, [in] BOOL value);
        HRESULT GetFlag([in] SwitcherPropertyId propertyId, [out] BOOL* value);
        HRESULT SetInt([in] SwitcherPropertyId propertyId, [in] LONG value);
        HRESULT GetInt([in] SwitcherPropertyId propertyId, [out] LONG* value);
        HRESULT SetFloat([in] SwitcherPropertyId propertyId, [in] double value);
        HRESULT GetFloat([in] SwitcherPropertyId propertyId, [out] double* value);
        HRESULT SetString([in] SwitcherPropertyId propertyId, [in] BSTR value);
        HRESULT GetString([in] SwitcherPropertyId propertyId, [out] BSTR* value);

    I can CreateIterator (Switcher Object) and get SwitcherInputIterator.
    Then SwitcherInputIterator.next for enum the SwitcherInput Objects.

    I can call SwitcherInput.getString, SwitcherInput.GetInputId
    but I get the error 5 for SwitcherInput.GetInt,SwitcherInput.SetString,
    SwitcherInput.SetInt ecc

    Please Help
    Thanks for your time

    Regards

  8. #8
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Variable uses an automation type not supported in Visual Basic

    Redeclare the BlockPropertyId in the same style as the GUID one earlier, and pass in the BlockProperty variable as [in] BlockPropertyId* PropertyId

    VB passes UDTS around as a pointer, not as a contiguous type.
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    126

    Re: Variable uses an automation type not supported in Visual Basic

    Hi

    Maybe I did not understand.

    You mean that I have to change the enum ?
    Code:
    typedef [v1_enum] enum	_BlockPropertyId
    like This?

    Code:
    typedef
    [
    uuid(????????-????-????-????-????????????),
    helpstring("BlockPropertyId enum declaration."),
    v1_enum,
    version(1.0)
    ]
    enum _BlockPropertyId {
    BlockPropertyIdProgramInput = 0x70676970,
    BlockPropertyIdPreviewInput = 0x70766970,
    BlockPropertyIdTransitionPosition = 0x74737073,
    ...
    ...
    } BlockPropertyId ;

    Can you explain better or show an example?

    Thanks for your patience!
    Last edited by Nanni; May 20th, 2012 at 12:46 PM.

  10. #10
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Variable uses an automation type not supported in Visual Basic

    Here's the last one I wrote (some years ago, I might add) that bound an unmanaged and non-COM DLL to COM via IDL so that it is useable in VB6. You should be able to figure it all out from there,

    Code:
    library Win32API {
    
    	importlib ("stdole2.tlb");
    	module CONSTANTS {
    		
    		[
    			helpstring ("Constants used by this type library")
    		]
    
    		const long REGISTRY_MAXIMUM_VALUE_SIZE_BYTES		=254;
    		const long ENVIRONMENT_MAXIMUM_BUFFER_SIZE_BYTES	=254;
    		const long MAXIMUM_CLASS_ENUMERATION				=512;
    		const long MAX_WSADescription						=256;
    		const long MAX_WSASYSStatus							=128;
    		const long HEAP_ZERO_MEMORY							=0x8;
    		const long STATUS_NO_MEMORY							=0xc0000017;
    		const long STATUS_ACCESS_VIOLATION					=0xc0000005;
    		const long KEY_WOW64_64KEY							=0x0100;	// this is not good, needed for WOW services
    		const long LOGPIXELSY								=0x5a;
    		const long MM_ISOTROPIC								=7;
    
    	}
    
    	typedef
    		[
    			uuid(9C8CC2E4-D61D-4653-AF22-4C9EEE2966A4),
    			helpstring("Event log types")
    		]
    		enum WIN32_EVENTLOG_TYPES {
    			EVENTLOG_SUCCESS						=0x0,
    			EVENTLOG_ERROR_TYPE						=0x1,
    			EVENTLOG_WARNING_TYPE					=0x2,
    			EVENTLOG_INFORMATION_TYPE				=0x4,
    			EVENTLOG_AUDIT_SUCCESS					=0x8,
    			EVENTLOG_AUDIT_FAILURE					=0x10
    		} WIN32_EVENTLOG_TYPES;
    
    
    	typedef
    		[
    			uuid(8a06358e-70b7-44ce-a2d0-f41eb668ae28),
    			helpstring ("Win32 Registry Root Keys")
    		]
    		enum WIN32_REG_ROOT_KEYS {
    			HKEY_CLASSES_ROOT		=0x80000000,
    			HKEY_CURRENT_USER		=0x80000001,
    			HKEY_LOCAL_MACHINE		=0x80000002,
    			HKEY_USERS				=0x80000003,
    			HKEY_PERFORMANCE_DATA	=0x80000004,
    			HKEY_CURRENT_CONFIG		=0x80000005,
    			HKEY_DYN_DATA			=0x80000006
    		} WIN32_REG_ROOT_KEYS;
    
    	typedef
    		[
    			uuid(81c41f67-c620-4a48-aaa3-24b2c8b8bfca),
    			helpstring ("Win32 Registry Open/Create Options")
    		]
    		enum WIN32_REG_OPENCREATE_OPTIONS {
    			REG_OPTION_RESERVED			=0x0,
    			REG_OPTION_NON_VOLATILE		=0x0,
    			REG_OPTION_VOLATILE			=0x1,
    			REG_OPTION_CREATE_LINK		=0x2,
    			REG_OPTION_BACKUP_RESTORE	=0x4,
    			REG_OPTION_OPEN_LINK		=0x8
    		} WIN32_REG_OPENCREATE_OPTIONS;
    
    	typedef
    		[
    			uuid(ac9d6a1e-2950-45e8-9e5b-9f84a154b0f8),
    			helpstring("Win32 Specific Access Rights")
    		]
    		enum WIN32_REG_ACCESS_RIGHTS {
    			KEY_QUERY_VALUE			=0x1,
    			KEY_SET_VALUE			=0x2,
    			KEY_CREATE_SUB_KEY		=0x4,
    			KEY_ENUMERATE_SUB_KEYS	=0x8,
    			KEY_NOTIFY				=0x10,
    			KEY_CREATE_LINK			=0x20
    		} WIN32_REG_ACCESS_RIGHTS;
    
    	typedef
    		[
    			uuid(e01b832f-65ff-4e45-838d-9033e5075acd),
    			helpstring ("Win32 Registry Datatypes")
    		]
    		enum WIN32_REG_DATATYPES {
    			REG_BINARY				=0x3,
    			REG_DWORD				=0x4,
    			REG_DWORD_BIG_ENDIAN	=0x5,
    			REG_DWORD_LITTLE_ENDIAN	=0x4,
    			REG_EXPAND_SZ			=0x2,
    			REG_LINK				=0x6,
    			REG_MULTI_SZ			=0x7,
    			REG_NONE				=0x0,
    			REG_RESOURCE_LIST		=0x8,
    			REG_SZ					=0x1
    		} WIN32_REG_DATATYPES;
    
    	typedef
    		[
    			uuid(BCF4A54B-03B6-416E-87AD-58D13C5091B6),
    			helpstring("lDispostion return values")
    		]
    		enum WIN32_REG_DISPOSITION {
    			REG_CREATED_NEW_KEY		=0x1,
    			REG_OPENED_EXISTING_KEY	=0x2
    		} WIN32_REG_DISPOSITION;
    
    
    	typedef
    		[
    			uuid(1944A5CC-0462-49F7-8673-3B601645A638),
    			helpstring("Draw Text Constants")
    		]
    	enum WIN32_DRAW_TEXT {
    		DT_BOTTOM				=0x8,
    		DT_CALCRECT				=0x400,
    		DT_CENTER				=0x1,
    		DT_EXPANDTABS			=0x40,
    		DT_EXTERNALLEADINEDGER	=0x200,
    		DT_LEFT					=0x0,
    		DT_NOCLIP				=0x100,
    		DT_NOPREFIX				=0x800,
    		DT_RIGHT				=0x2,
    		DT_SINGLELINE			=0x20,
    		DT_TABSTOP				=0x80,
    		DT_TOP					=0x0,
    		DT_VCENTER				=0x4,
    		DT_WORDBREAK			=0x10,
    		DT_RTLREADING			=0x20000
    	} WIN32_DRAW_TEXT;
    
    	typedef
    		[
    			uuid(F0995818-43C1-4453-8DB3-D4020ADAFA14),
    			helpstring("Locale Constants")
    		]
    	enum WIN32_LOCALE {
    		LOCALE_SCURRENCY		=0x14,
    		LOCALE_SINTLSYMBOL		=0x15,
    		LOCALE_IDIGITS			=0x11,
    		LOCALE_ILZERO			=0x12,
    		LOCALE_INEGNUMBER		=0x1010,
    		LOCALE_SGROUPING		=0x10,
    		LOCALE_SDECIMAL			=0xe,
    		LOCALE_STHOUSAND		=0xf,
    		LOCALE_INEGCURR			=0x1c,
    		LOCALE_SMONDECIMALSEP	=0x16,
    		LOCALE_SMONTHOUSANDSEP	=0x17,
    		LOCALE_ICURRENCY		=0x1b
    	} WIN32_LOCALE;
    
    	///////////////////////////////////////////////
    	// WIN32 Structs used in this type library ...
    	///////////////////////////////////////////////
    		struct FILETIME {
    			long dwLowDateTime;
    			long dwHighDatetime;
    		};
    
    		struct SAFEARRAY1D {
    			short	cDims;
    			short	fFeatures;
    			long	cbElements;
    			long	cLocks;
    			long	pvData;
    			long	cElement;
    			long	lLBound;
    		};
    
    		struct SAFEARRAYBOUNDS {
    			long	LBound;
    			long	UBound;
    		};
    
    		struct ICMP_OPTIONS {
    			unsigned char	Ttl;
    			unsigned char	Tos;
    			unsigned char	Flags;
    			unsigned char	OptionsSize;
    			long			OptionsData;
    		};
    
    		struct ICMP_ECHO_REPLY {
    			long					Address;
    			long					Status;
    			long					RoundTripTime;
    			short					Datasize;
    			short					Reserved;
    			long					DataPointer;
    			struct ICMP_OPTIONS 	Options;
    			BSTR					Data; //initialise to length 250 before using
    		};
    
    		struct WSADATA {
    			short						wVersion;
    			short						wHighVersion;
    			SAFEARRAY (unsigned char)	szDescription; //initialise to MAX_WSADESCRIPTION
    			SAFEARRAY (unsigned char)	szSystemStatus;//initialise to MAX_WSASYSStatus
    			long						wMaxSockets;
    			long						wMaxUDPDG;
    			long						dwVendor;
    		};
    
    		struct HOSTENT {
    			long	hName;
    			long	hAliases;
    			short	hAddrType;
    			short	hLen;
    			long	hAddrList;
    		};
    
    		struct DOCINFO {
    			long pDocName;
    			long pOutputFile;
    			long pDatatype;
    		};
    
    		struct POINTAPI {
    			long x;
    			long y;
    		};
    
    		struct SIZE {
    			long cx;
    			long cy;
    		};
    
    		struct RECT {
    			long Left;
    			long Top;
    			long Right;
    			long Bottom;
    		};
    
    		struct LOGFONT {
    			long lfHeight;
    			long lfWidth;
    			long lfEscapment;
    			long lfOrientation;
    			long lfWeight;
    			byte lfItalic;
    			byte lfUnderline;
    			byte lfStrikeOut;
    			byte lfCharSet;
    			byte lfOutPrecision;
    			byte lfClipPrecision;
    			byte lfQuality;
    			byte lfPitchAndFamily;
    			long plfFacename;
    		};
    
    		struct DRAWTEXTPARAMS {
    			long cbSize;
    			long iTabLength;
    			long iLeftMargin;
    			long iRightMargin;
    			long uiLengthDrawn;
    		};
    
    		struct NUMBERFMT {
    			long NumDigits;
    			long LeadingZero;
    			long Grouping;
    			long lpDecimalSep;
    			long lpThousandSep;
    			long NegativeOrder;
    		};
    
    		struct CURRENCYFMT {
    			long NumDigits;
    			long LeadingZero;
    			long Grouping;
    			long lpDecimalSep;
    			long lpThousandSep;
    			long NegativeOrder;
    			long PositiveOrder;
    			long lpCurrencySymbol;
    		};
    
    		struct SYSTEMTIME {
    			short wYear;
    			short wMonth;
    			short wDayOfWeek;
    			short wDay;
    			short wHour;
    			short wMinute;
    			short wSecond;
    			short wMilliseconds;
    		};
    	[
    		dllname("kernel32.dll"),
    		helpstring ("Kernel32 DLL Binding")
    	]
    	module Win32_Kernel32 {
    
    		[
    			entry ("RtlMoveMemory"),
    			helpstring ("The ubiquitous CopyMemory")
    		]
    		void _stdcall CopyMemory ([in] void* Destination, [in] void* Source, [in] int Length);
    
    		[
    			entry ("RtlZeroMemory"),
    			helpstring ("Fills a block of memory with zeros")
    		]
    		void _stdcall ZeroMemory ([in] void* Destination, [in] int Length);
    
    		[
    			entry("GetComputerNameW"),
    			helpstring("Retrieves the NetBIOS name of the local computer")
    		]
    		VARIANT_BOOL _stdcall GetComputerName ([in] long lpBuffer, [in,out,ref] long* lpnSize);
    
    		[
    			entry("HeapUnlock"),
    			helpstring("Releases ownership of the critical section object, or lock, that is associated with a specified heap")
    		]
    		long _stdcall HeapUnlock ([in] long hHeap);
    
    		[
    			entry("HeapLock"),
    			helpstring ("Attempts to acquire the critical section object, or lock, that is associated with a specified heap")
    		]
    		long _stdcall HeapLock ([in] long hHeap);
    
    		[
    			entry("HeapFree"),
    			helpstring ("Frees a memory block allocated from a heap by the HeapAlloc or HeapReAlloc function")
    		]
    		long _stdcall HeapFree ([in] long hHeap, [in] long dwFlags, [in,out] void* lpMem);
    
    		[
    			entry("HeapAlloc"),
    			helpstring ("Allocates a block of memory from a heap. The allocated memory is not movable")
    		]
    		long _stdcall HeapAlloc ([in] long hHeap, [in] long dwFlags, [in] long dwBytes);
    
    		[
    			entry("HeapCreate"),
    			helpstring ("Creates a private heap object that can be used by the calling process. The function reserves space in the virtual address space of the process and allocates physical storage for a specified initial portion of this block")
    		]
    		long _stdcall HeapCreate ([in] long flOptions, [in] long dwInitialSize, [in] long dwMaximumSize);
    
    		[
    			entry("HeapDestroy"),
    			helpstring("Destroys the specified heap object. It decommits and releases all the pages of a private heap object, and it invalidates the handle to the heap")
    		]
    		long _stdcall HeapDestroy ([in] long hHeap);
    
    		[
    			entry("HeapReAlloc"),
    			helpstring("Reallocates a block of memory from a heap. This function enables you to resize a memory block and change other memory block properties. The allocated memory is not movable")
    		]
    		long _stdcall HeapReAlloc ([in] long hHeap, [in] long dwFlags, [in] long lpMem, [in] long dwBytes);
    
    		[
    			entry("MulDiv"),
    			helpstring("Multiplies two 32-bit values and then divides the 64-bit result by a third 32-bit value")
    		]
    		long _stdcall MulDiv ([in] long nNumber, [in] long nNumerator, [in] long nDenominator);
    
    		[
    			entry("GetLocaleInfoW"),
    			helpstring("Retrieves information about a locale specified by identifier")
    		]
    		short _stdcall GetLocaleInfo ([in] long LCId, [in] long LCType, [in] long lpData, [in] short cchData);
    
    		[
    			entry("GetNumberFormatW"),
    			helpstring ("Formats a number string as a number string customized for a specified locale")
    		]
    		long _stdcall GetNumberFormat ([in] long Locale, [in] long dwFlags, [in] long lpValue, [in] struct NUMBERFMT lpFormat, [in] long lpNumberStr, [in] long cchNumber);
    
    		[
    			entry("IsValidLocale"),
    			helpstring ("Applies a validity test to a locale identifier")
    		]
    		VARIANT_BOOL _stdcall IsValidLocale ([in] long Locale, [in] long dwFlags);
    
    		[
    			entry("GetCurrencyFormatW"),
    			helpstring ("Formats a number string as a currency string for a locale specified by identifier")
    		]
    		long _stdcall GetCurrencyFormat ([in] long Locale, [in] long dwFlags, [in] long lpValue, [in] struct CURRENCYFMT lpFormat, [in] long lpCurrencyStr, [in] long cchCurrency);
    
    		[
    			entry("GetDateFormatW"),
    			helpstring ("Formats a number string as a date string for a locale specified by identifier")
    		]
    		long _stdcall GetDateFormat ([in] long Locale, [in] long dwFlags, [in] struct SYSTEMTIME lpDate, [in] long lpFormat, [in] long lpDateStr, [in] long cchDate);
    
    		[
    			entry("GetTimeFormatW"),
    			helpstring ("Formats a number string as a date string for a locale specified by identifier")
    		]
    		long _stdcall GetTimeFormat ([in] long Locale, [in] long dwFlags, [in] struct SYSTEMTIME lpTime, [in] long lpFormat, [in] long lpTimeStr, [in] long cchTime);
    
    	}
    
    
    	[
    		dllname("advapi32.dll"),
    		helpstring ("AdvAPI32 DLL Binding")
    	]
    	module Win32_AdvAPI32 {
    
    		[
    			entry("RegCreateKeyExW"),
    			helpstring("Creates the specified registry key")
    		]
    		long _stdcall RegCreateKeyEx ([in] long hKey, [in] long lpSubkey, [in] long Reserved, [in] long lpClass, [in] long dwOptions, [in] long samDesired, [in,out,ref] long* lpSecurityAttributes, [in,out,ref] long* phkResult, [in,out,ref] long* lpdwDisposition);
    
    		[
    			entry ("RegOpenKeyExW"),
    			helpstring ("Opens an existing registry key")
    		]
    		long _stdcall RegOpenKeyEx ([in] long hKey, [in] long pSubKey, [in] long ulOptions, [in] long samDesired, [out] long* phkResult);
    
    		[
    			entry ("RegCloseKey"),
    			helpstring ("Closes a key in the registry")
    		]
    		long _stdcall RegCloseKey ([in] long hKey);
    
    		[
    			entry ("RegQueryValueExW"),
    			helpstring ("Retrieves a value for a key") 
    		]
    		long _stdcall RegQueryValueEx ([in] long hKey, [in] long lpValueName, [in] long lpReserved, [in,out,ref] long* lpType, [in] long lpData, [in,out,ref] long* lpcbData);
    
    		[
    			entry("RegEnumKeyExW"),
    			helpstring("Enumerates subkeys for the given key")
    		]
    		long _stdcall RegEnumKeyEx ([in] long hKey, [in] long dwIndex, [in] long lpName, [in,out] long* lpcbName, [in] long lpReserved, [in] long lpClass, [in,out] long* lpcbClass, [in,out] struct FILETIME* lpftLastWriteTime);
    
    		[
    			entry("RegEnumValueW"),
    			helpstring("Enumerates the values for the specified key")
    		]
    		long _stdcall RegEnumValue ([in] long hKey, [in] long dwIndex, [in] long lpValueName, [in,out] long* lpcbValueName, [in] long lpReserved, [in,out] long* lpType, [in] long lpData, [in,out] long* lpcbData);
    
    		[
    			entry("GetUserNameW"),
    			helpstring ("Retrieves Login name of thread owner")
    		]
    		long _stdcall GetUsername([in] long lpBuffer, [in,out] long* lpcbBuffer);
    
    		[
    			entry("IsTextUnicode"),
    			helpstring("Determines if a buffer is likely to contain a form of Unicode text")
    		]
    		long _stdcall IsTextUnicode ([in] long lpBuffer, [in] long cb, [in] long lpi);
    
    		[
    			entry("RegisterEventSourceW"),
    			helpstring("Retrieves a registered handle to the specified event log")
    		]
    		long _stdcall RegisterEventSource ([in] long lpUNCServerName, [in] long lpSourceName);
    
    		[
    			entry("DeregisterEventSource"),
    			helpstring("Closes the specified event long")
    		]
    		long _stdcall DeregisterEventSource ([in] long hEventLog);
    
    		[
    			entry("ReportEventW"),
    			helpstring("Writes an entry at the end of the specified event log")
    		]
    		VARIANT_BOOL _stdcall ReportEvent([in] long hEventLog, [in] int wType, [in] int wCategory, [in] long dwEventId, [in] long lpUserSid, [in] int wNumStrings, [in] long dwDataSize, [in,out,ref] long* plpStrings, [in,out,ref] long* lpRawData);
    	};
    
    }
    I don't think there's an example, here, but if you want to pass an enum in IDL you need to say so, so perhaps use [in] enum BlockPropertyId BlockProperty
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    126

    Re: Variable uses an automation type not supported in Visual Basic

    Hello

    I have tried with different enum declaration , but nothing works.

    I do not believe that the problem is in the enum.
    I can get some values from the DLL and I can see
    the Enum (VB's IDE autocomplete)
    Code:
    SwitcherInput.GetString and SwitcherInput.GetInputId
    The problems is passing value to DLL
    Code:
    SwitcherInput.SetString,SwitcherInput.SetInt...
    Thanks for your ideas and help

    Regards

  12. #12
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Variable uses an automation type not supported in Visual Basic

    Without the DLL, a VB6 compiler, a MIDL compiler, I think it's the end of the road for me, then.

    If I may suggest, the IDL that you've shown is *so* geared towards C++, and it also seems to be missing import("stdole2.tlb") which VB requires for various reasons. On that basis, I would ditch the C++ version and start writing a VB one from scratch, testing each component as you go: don't forget to back up your registry otherwise the C++ one will cease to work the minute you reference your new VB version from VB6 - it auto-registers typelibs.

    A lot of work, yes, but I think that's the only way forward for you now.
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width