代码之家  ›  专栏  ›  技术社区  ›  Mike Webb

如何从VB6调用C++ DLL而不必通过COM?

  •  1
  • Mike Webb  · 技术社区  · 16 年前

    好的,所以我有一个C++项目编译成一个DLL文件。我可以在c_中引用这个文件,并查看/使用dll文件中的所有对象和函数。我需要做的是通过vb6引用这些对象和函数。

    C++代码中没有任何东西看起来像是在创建一个DLL。没有''.xDeScript(dL导出)'修饰符,只是C++代码。

    有这样的对象:

    String ^
    Array^
    

    我不完全确定它们是什么。我对C++的了解不是很广泛,我只在C++中对Linux系统进行了编码,尽管从用法上看,它们看起来像指针。这些对象与C++中的DLL有什么关系吗?

    无论如何,我可以添加我需要的任何包装器,或者添加一个定义文件(.def),尽管我不知道要使用什么包装器,也不知道定义文件是如何工作的,也不知道如何构造它。

    感谢您的帮助和/或建议。如果你能给我一些好的信息,那将是有帮助的。我做的所有搜索都没有帮助。

    请记住,我需要从VB6中访问这个C++ DLL中的所有函数和对象。

    谢谢。

    编辑:向问题添加了.h文件和assemblyinfo.cpp规范

    我在这些文件中更改了一些名称,但结构是相同的。注意,这引用了其他文件,但是我假设如果一个文件可以工作,那么其他文件可以使用相同的过程。我能看到每一个物体,而不是方法:

    //myDBObject.h
    #pragma once
    using namespace System;
    namespace myDBNamespace {
    
    #include "ProblemSolution.h"
    
    public ref class MyDataBaseAccessor
    {
    public:
        MyDataBaseAccessor();
    
        static  String ^    GetServiceVersion() { return sDLLVersion;};
        int                   GetServiceStatus() { return myiDBStatus;};
        String ^                GetMyVersion();
        String ^                GetDBVersion();
        String ^                GetDLLVersion();
        String ^                GetExpireDate();
    
        MyOtherObject ^         GetMyOtherObject();
    
        int             ProcessProblem(ProblemSolution ^ dsps);
    
    private:
        static  MyDataBaseController ^  myDataBase;
        static  MyOtherObject ^         myObjs;
        static  MyDataset ^     myDS;
        static  String ^                myDBPath;
    
        static  String ^                sDLLVersion = "0.01";
        static  String ^                sReqDBVer = "0.01";
        static  int                     myiDBStatus;
        static  bool                    myBoolean, myOtherBoolean, mybNoChain;
    
    };
    }
    

    以下是assemblyinfo.cpp文件:

    #include "stdafx.h"
    
    using namespace System;
    using namespace System::Reflection;
    using namespace System::Runtime::CompilerServices;
    using namespace System::Runtime::InteropServices;
    using namespace System::Security::Permissions;
    
    //
    // General Information about an assembly is controlled through the following
    // set of attributes. Change these attribute values to modify the information
    // associated with an assembly.
    //
    [assembly:AssemblyTitleAttribute("My Product Title")];
    [assembly:AssemblyDescriptionAttribute("")];
    [assembly:AssemblyConfigurationAttribute("")];
    [assembly:AssemblyCompanyAttribute("My Company")];
    [assembly:AssemblyProductAttribute("My Product Name")];
    [assembly:AssemblyCopyrightAttribute("My Copyright")];
    [assembly:AssemblyTrademarkAttribute("My Program")];
    [assembly:AssemblyCultureAttribute("")];
    
    //
    // Version information for an assembly consists of the following four values:
    //
    //      Major Version
    //      Minor Version
    //      Build Number
    //      Revision
    //
    // You can specify all the value or you can default the Revision and Build Numbers
    // by using the '*' as shown below:
    
    [assembly:AssemblyVersionAttribute("1.0.*")];
    
    [assembly:ComVisible(true)]; //Here is the ComVisible tag. It was false and I set it to true
    
    [assembly:CLSCompliantAttribute(true)];
    
    [assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = false)];
    
    2 回复  |  直到 16 年前
        1
  •  1
  •   Steve Townsend    15 年前

    regasm

    Dim net As Object
    
    Set obj = CreateObject("NETProject.Foo")
    obj.Move
    

    Dim net As Foo
    
    Set obj = New NETProject.Foo
    obj.Move
    

    [ComVisible(true)]
    public ref class MyDataBaseAccessor