应用程序定义的错误或用户定义的错误 - VB6

Application Defined Error Or User Defined Error - VB6

首先,我需要澄清这不是 VBA 相关的问题。此错误发生在与MS Office无关的Visual Basic 6.0发布程序上。


有问题的程序由一个名为 "Color_Picker.exe" 的可执行文件和一个名为 "ColorManagementControls.ocx" 的 ActiveX 控件组成。我正在尝试使用 Registration-Free Activation of COM

每当我尝试使用清单设置运行我的程序时

"Application-defined error or user-defined error."

弹出。从错误的标题 window,它始终是有问题的名称 class,我可以看出错误发生在 OCX 中。

问题是我知道 class 运行 没有错误。为了确保这不是与 Windows 10 不兼容的问题,因为程序是在 Windows XP 中编译的,所以我正确注册了我的 OCX,当我这样做时程序 运行s顺利。所以我猜测我的 OCX 清单设置不正确或需要额外的 add-ons 因为我严格按照 MSDN 教程进行操作。

编辑: 我忘了提到这在我用程序和 class 的未完成版本测试它之前是有效的。然后,我向 OCX 添加了一些属性并对 EXE 进行了一些 UI 改进。那是它停止工作的时候。

这是正在使用的 EXE 清单:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" 
  manifestVersion="1.0">
<assemblyIdentity
            type = "win32"
            name = "Color_Picker"
            version = "1.0.0.0" />
<dependency>
            <dependentAssembly>
                        <assemblyIdentity
                                    type="win32"
                                    name="ColorManagementControls.ocx"
                                    version="1.0.0.0" />
            </dependentAssembly>
</dependency>
</assembly>

这是正在使用的 OCX 清单:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" 
  manifestVersion="1.0">

<assemblyIdentity
   type="win32"
   name="ColorManagementControls.ocx"
   version="1.0.0.0" />

<file name = "ColorManagementControls.ocx">

<comClass
    clsid="{F25E6EEC-9586-4606-B0F3-D3601F59CD33}"
    threadingModel = "Apartment" />

<typelib tlbid="{F24DF9F0-C974-4307-A096-3A006918FB86}"
       version="1.0" helpdir=""/>

</file>

<comInterfaceExternalProxyStub 
    name="_udcColorScroll" 
    iid="{18EBDF4B-F66A-422F-99AF-C968FE10F494}"
    proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
    baseInterface="{00000000-0000-0000-C000-000000000046}"
    tlbid = "{F24DF9F0-C974-4307-A096-3A006918FB86}" />

</assembly>

这就是 OLE/COM 查看器显示的关于我的 OCX 的内容:

// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: ColorManagementControls.ocx

[
  uuid(F24DF9F0-C974-4307-A096-3A006918FB86),
  version(2.0),
  helpstring("vbpColorManageControls")
]
library vbpColorManageControls
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface _udcColorScroll;
    dispinterface __udcColorScroll;

    [
      odl,
      uuid(18EBDF4B-F66A-422F-99AF-C968FE10F494),
      version(1.0),
      hidden,
      dual,
      nonextensible,
      oleautomation
    ]
    interface _udcColorScroll : IDispatch {
        [id(0x40030000), propget]
        HRESULT HideCursor([out, retval] VARIANT_BOOL* HideCursor);
        [id(0x40030000), propput]
        HRESULT HideCursor([in] VARIANT_BOOL HideCursor);
        [id(0x40030001), propget]
        HRESULT ClipOnClick([out, retval] VARIANT_BOOL* ClipOnClick);
        [id(0x40030001), propput]
        HRESULT ClipOnClick([in] VARIANT_BOOL ClipOnClick);
        [id(0x68030005), propget]
        HRESULT ColorOut([out, retval] OLE_COLOR* );
        [id(0x68030004), propget]
        HRESULT Value([out, retval] single* );
        [id(0x68030004), propput]
        HRESULT Value([in] single );
        [id(0x68030003), propget]
        HRESULT StartColor([out, retval] OLE_COLOR* );
        [id(0x68030003), propput]
        HRESULT StartColor([in] OLE_COLOR );
        [id(0x68030002), propget]
        HRESULT EndColor([out, retval] OLE_COLOR* );
        [id(0x68030002), propput]
        HRESULT EndColor([in] OLE_COLOR );
        [id(0x68030001), propget]
        HRESULT Orientation([out, retval] eColPickOrientation* );
        [id(0x68030001), propput]
        HRESULT Orientation([in] eColPickOrientation );
        [id(0x68030000), propget]
        HRESULT BorderStyle([out, retval] eColPickBorderStyle* );
        [id(0x68030000), propput]
        HRESULT BorderStyle([in] eColPickBorderStyle );
    };

    [
      uuid(F25E6EEC-9586-4606-B0F3-D3601F59CD33),
      version(1.0),
      noncreatable,
      control
    ]
    coclass udcColorScroll {
        [default] interface _udcColorScroll;
        [default, source] dispinterface __udcColorScroll;
    };

    [
      uuid(CE70501E-3905-4718-A1A9-FF3C844A8286),
      version(1.0),
      hidden,
      nonextensible
    ]
    dispinterface __udcColorScroll {
        properties:
        methods:
            [id(0x00000001)]
            void Change([in, out] tColorScll* hoverInf);
            [id(0x00000002)]
            void Scroll([in, out] tColorScll* hoverInf);
    };

    typedef [uuid(66A38F2E-D6C2-49D3-BD5B-EF68DF34CECE), version(1.0)]
    enum {
        CPB_NONE = 0,
        CPB_SINGLE = 1,
        CPB_SINGLESHADED = 2,
        CPB_DOUBLE = 3,
        CPB_DOUBLESHADED = 4
    } eColPickBorderStyle;

    typedef [uuid(206F68AB-F66C-4BD9-AD43-82355A403A4E), version(1.0)]
    enum {
        CPO_HORIZONTAL = 0,
        CPO_VERTICAL = 1
    } eColPickOrientation;

    typedef [uuid(746EB8A7-B27D-44AF-B179-AE862424BC6E), version(1.0)]
    struct tagtColorScll {
        [helpstring("ColorScroll")        
]
        OLE_COLOR ColorScroll;
        [helpstring("LocScroll")        
]
        single LocScroll;
    } tColorScll;
};

根据您的评论

this had previously worked when I tested it with an unfinished version of both the program and class. I then added some properties to the OCX and made some UI improvements to the EXE. That is when it stopped working.

看来问题一定是由于编译后的 OCX 与一个或两个清单文件之间的某些不一致造成的。

从您发布的代码中,值得注意的是您的 OCX 清单具有:

<typelib tlbid="{F24DF9F0-C974-4307-A096-3A006918FB86}"
       version="1.0" helpdir=""/>
                ^^^

但 IDL 具有相同 GUID 的 version(2.0)。我会看看更改清单以使它们同步是否会解决此问题。