Я следовал этому учебнику, чтобы создать COM-DLL в Visual Basic.http://www.codeproject.com/KB/COM/Basics_of_Idl_file.aspx
Теперь я хочу использовать эту DLL в проекте C ++.Я использовал OLE / COM Viewer для создания файла .idl, как описано во второй половине этого урока.http://www.codeproject.com/KB/COM/vb_from_vc.aspx
Я скомпилировал .idl с помощью компилятора midl и включил файл .h, созданный в моем проекте c ++.
Вот мой код Visual Basic
<ComClass(MyComClass.ClassId, MyComClass.InterfaceId, MyComClass.EventsId)> _
Public Class MyComClass
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "46604f8a-85a2-4027-9728-0390534c9209"
Public Const InterfaceId As String = "30274029-711d-459a-9270-f9d73ad8737f"
Public Const EventsId As String = "5e234d69-5263-4001-86ff-c475b113a77d"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
Public Sub DisplayMessage()
MsgBox("Hello from MyComClass!")
End Sub
End Class
Вот мой код C ++
// Declare an HRESULT and a pointer to the clsVBTestClass interface
HRESULT hr;
_MyComClass *IVBTestClass = NULL;
// Now we will intilize COM
hr = CoInitialize(0);
// Use the SUCCEEDED macro and see if we can get a pointer
// to the interface
if(SUCCEEDED(hr))
{
hr = CoCreateInstance( CLSID_MyComClass,
NULL,
CLSCTX_INPROC_SERVER,
IID__MyComClass,
(void**) &IVBTestClass);
// If we succeeded then call the CountStringLength method,
// if it failed then display an appropriate message to the user.
if(SUCCEEDED(hr))
{
long ReturnValue;
_bstr_t bstrValue("Hello World");
// We can test this HR as well if we wanted to
hr = IVBTestClass->DisplayMessage();
hr = IVBTestClass->Release();
}
else
{
}
}
// Uninitialize COM
CoUninitialize();
При компиляции проекта C ++ я получаю следующие ошибки
Ошибка LNK2001: неразрешенный внешний символ _CLSID_MyComClass Ошибка LNK2001: неразрешенный внешний символ IID _MyComClass
Может ли кто-нибудь помочь мне понять, что я делаю неправильно?