如何消除VC+中使用C#DLL的错误+;
这是我的接口和名为DataAccess.cs的类如何消除VC+中使用C#DLL的错误+;,c#,visual-studio-2010,visual-c++,dll,dllimport,C#,Visual Studio 2010,Visual C++,Dll,Dllimport,这是我的接口和名为DataAccess.cs的类 using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Data.Common; using System.Linq; using Microsoft.Practices.Enterp
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.Common;
using System.Linq;
using Microsoft.Practices.EnterpriseLibrary.Data;
using IISWebFrameworkDAAB.BusinessLayer;
using IISWebFrameworkDAAB.DataAccessLayer;
using Framework.Data;
using System.Text;
namespace IISWebFrameworkDAAB.DataAccessLayer
{
[Guid("76f20d76-b030-4487-a315-2d727dedd4ec")]
public interface DataAccessInterface
{
#region "Methods"
void InsertSampleTable(Byte varTinyInt, Int32 varInt, String varText, String varVarchar, Boolean varBit, DateTime varDateTime, Decimal varDecimal);
};
[Guid("c686d756-98a7-4048-b79c-b1ff9889730c")]
public class DataAccess : DataAccessInterface
{
public void InsertSampleTable(Byte varTinyInt, Int32 varInt, String varText, String varVarchar, Boolean varBit, DateTime varDateTime, Decimal varDecimal)
{
m_procName = "Insert_SampleTable";
m_dbCommand = m_db.GetStoredProcCommand(m_procName);
m_db.AddInParameter(m_dbCommand, "_varTinyInt", DbType.Byte, varTinyInt);
m_db.AddInParameter(m_dbCommand, "_varInt", DbType.Int32, varInt);
m_db.AddInParameter(m_dbCommand, "_varText", DbType.String, varText);
m_db.AddInParameter(m_dbCommand, "_varVarchar", DbType.String, varVarchar);
m_db.AddInParameter(m_dbCommand, "_varBit", DbType.Boolean, varBit);
m_db.AddInParameter(m_dbCommand, "_varDateTime", DbType.DateTime, varDateTime);
m_db.AddInParameter(m_dbCommand, "_varDecimal", DbType.Decimal, varDecimal);
m_db.ExecuteNonQuery(m_dbCommand);
}
};
}
这是我的AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 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("IISWebFrameworkDAAB")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IISWebFrameworkDAAB")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[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(false)]
[assembly: ComVisible(true)]
[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("..\\..\\MyKeyFile.SNK")]
// The following GUID is for the ID of the typelib if this project is exposed to COM
//[程序集:Guid(“76f20d76-b030-4487-a315-2d727dedd4ec”)]
这是我的客户:-
#include <windows.h>
#include <stdio.h>
#pragma warning (disable: 4278)
// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import <mscorlib.tlb> //raw_interfaces_only
#import "C:\Documents and Settings\Administrator\Desktop\new\NiproDAAB\IISWebFrameworkDAAB\bin\Debug\IISWebFrameworkDAAB.tlb"
using namespace IISWebFrameworkDAAB;
int main(int argc, char* argv[])
{
DataAccessInterface *cpi = NULL;
int retval = 1;
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_DataAccess,
NULL, CLSCTX_INPROC_SERVER,
IID_DataAccessInterface, reinterpret_cast<void**>(&cpi));
if (FAILED(hr))
{
printf("Couldn't create the instance!... 0x%x\n", hr);
}
}
我按照下面链接中给出的那样做了尝试将“命名的guid”添加到导入中,例如
'#import named_guids'
此步骤在您引用的示例中的COMClient.cpp源代码中进行了说明,如下所示:
..
#import "CSharpServer.tlb" no_namespace named_guids
..
我得到一个错误,“entlibcontrib.data.mysql”没有强名称
'#import named_guids'
..
#import "CSharpServer.tlb" no_namespace named_guids
..