从C调用来自dll文件(在VB中为wirtten)的COM组件

时间:2015-08-09 11:59:33

标签: c vb.net

我的dll在VB中编码,我想从普通COM components调用C。以下是dll的几行代码。假设我想从普通Initialize()调用方法CCoCreateInstance中方法C的参数应该是什么。

我成功地从dll调用此C++的所有方法,但我想从C拨打电话。你可以帮我解决这个问题。

Namespace Thermodynamics

<System.Serializable()> <ComClass(Calculator.ClassId, Calculator.InterfaceId, Calculator.EventsId)>
Public Class Calculator

    Public Const ClassId As String = "5F2B671E-FA61-401e-8D14-71FB5B328F9B"
    Public Const InterfaceId As String = "0EA44EDE-AD65-435c-B8CC-0D1146BD182B"
    Public Const EventsId As String = "0817BD3F-5278-4e49-A7FB-92416A8A7E4E"

    Private _availablecomps As Dictionary(Of String, ConstantProperties)

    Sub New()

    End Sub

    ''' <summary>
    ''' Initializes the calculator and loads the compound databases into memory.
    ''' </summary>
    ''' <remarks></remarks>
    <System.Runtime.InteropServices.DispId(1)> Sub Initialize()

        'load databases
        _availablecomps = New Dictionary(Of String, ConstantProperties)

        'ChemSep
        Me.LoadCSDB()

        'load DWSIM XML database
        Me.LoadDWSIMDB()

    End Sub

1 个答案:

答案 0 :(得分:-1)

这是用于调用Initialize()方法的完整C ++代码。

#include "tchar.h"
#include<iostream>
#include<Windows.h>
#include <comutil.h>
#include <string>
#include <xstring>


#import "C:/DTLSource/DTLSource/DTL-master/DWSIM/bin/Debug/DTL.tlb"  raw_interfaces_only
using namespace DTL;


int main(int argc, _TCHAR* argv[])
{
     // Initialize COM.
 HRESULT hr = CoInitialize(NULL);

    _CalculatorPtr ptrinterface(_uuidof(Calculator));
 ptrinterface->Initialize();

    CoUninitialize();
return 0;
}