2015-08-09 6 views
-1

我有DLL編碼在VB,我想打電話給它的COM components從純C。以下是dll的幾行代碼。假設我想從普通的C調用方法Initialize(),那麼中方法CoCreateInstance的參數應該是什麼。從C DLL文件(VB中wirtten)調用COM組件從C

我成功地從C++調用此dll的所有方法,但我想從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 
+0

你是怎麼用C++做的? – GolezTrol

+0

首先,我使用regasm註冊了dll。這個過程生成了一個可直接在C++中使用的.tlb文件。以下是從C++調用它的代碼。 –

+0

#import「C:/ DTLSource/DTLSource/DTL master/DWSIM/bin/Debug/DTL.tlb」raw_interfaces_only –

回答

-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; 
}