Здравствуйте!
Передо мной стоит задача подключить сборку (Class Library) .NET (Написана на Шарпе) к BCB6 через COM.
У меня никак не получается создать экземпляр объекта... Причем функция возвращает непонятное значение, которое в MSDN почему-то не описано... Посмотрите, пожалуйста, что я делаю неправильно
Вот код, для обращения к сборке
//---------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <comdef.h>
#include <vcl.h>
#include <ComPlusServer_TLB.h>
#include <clx.h>
#import "../ComPlusServer/ComPlusServer/bin/Debug/ComPlusServer.tlb" raw_interfaces_only
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
void main(int argc, char* argv[])
{
puts("Running CoInitialize(NULL)...");
if(FAILED(CoInitialize(NULL)))
{
puts("CoInitialize error");
getchar();
return;
}
puts("Succesfully");
wchar_t *wcharCLSID = L"ComPlusServer.ServerTest";
CLSID clsidMyServer;
IServer *pMyServer;
puts("Running CLSIDFromProgID (bstrCLSID,&clsidOrbit)...");
if(FAILED(CLSIDFromProgID(wcharCLSID,&clsidMyServer)))
{
puts("Failed! Exiting...");
getchar();
return;
}
puts("Successfully");
puts("Running CoCreateInstance()...");
int resultConInit;
resultConInit = CoCreateInstance(clsidMyServer,0,CLSCTX_INPROC_SERVER,__uuidof(IServer),
(void**)&pMyServer);//ЗДЕСЬ НЕ РАБОТАЕТ!!!
if(resultConInit != S_OK)
{
switch(resultConInit)
{
case REGDB_E_CLASSNOTREG:
puts("A specified class is not registered in the registration database.\
Also can indicate that the type of server you requested in the\
CLSCTX enumeration is not registered or the values for the server\
types in the registry are corrupt.");
getchar();
return;
case CLASS_E_NOAGGREGATION:
puts("class cannot be created as part of an aggregate.");
getchar();
return;
case E_NOINTERFACE:
puts("The specified class does not implement the \
requested interface, or the controlling IUnknown does \
not expose the requested interface. ");
getchar();
return;
default://ПОСТОЯННО ПРИХОДИМ СЮДА
puts("Failed! Exiting...");
getchar();
return;
}
}
puts("Successfully");
getchar();
return;
}
//---------------------------------------------------------------------------
Код сборки (C#)
AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
// 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: AssemblyTitle("ComPlusServer")]
[assembly: AssemblyDescription("COM+ server test")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("BSTU")]
[assembly: AssemblyProduct("ComPlusServer")]
[assembly: AssemblyCopyright("Copyright © BSTU 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("eb4ecbc6-ed54-4459-a8b3-a854f23d4e13")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: ApplicationID("eb4ecbc6-ed54-4459-a8b3-a854f23d4e13")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: AssemblyDelaySign(false)]
IServer.cs
using System;
using System.Collections.Generic;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Reflection;
namespace ComPlusServer
{
[GuidAttribute("A615F03D-0F94-4b7b-8AAA-3FB7B5EE5494")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IServer
{
int ReturnInt(int i);
}
}
ServerTest.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
namespace ComPlusServer
{
[EventTrackingEnabledAttribute(true)]
[Guid("A05FDD0A-9F2B-414f-8896-12B645EC9F70")]
[ClassInterface(ClassInterfaceType.None)]
public class ServerTest : System.EnterpriseServices.ServicedComponent, IServer
{
#region Constructor
public ServerTest() { }
#endregion
#region IServer Members
int IServer.ReturnInt(int i)
{
return i;
}
#endregion
}
}
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>