COM interop, C #, Visual Studio 2010 & # 8594; built-in interaction types

My C # program accesses SAP through Nco3 (sapnco.dll). This program should also work with Delphi. Some of my methods return types from the sapnco.dll file:

public void IRfcTable table(...) { ... } 

in Delphi this method is displayed as

 function table(...): IUnknown { ... } 

I believe this IUnknown is that my TLB does not include the sapnco.dll file. I tried "Insert Interop Types = true" in Visual Studio, but then this error occurs:

Error Interoptypen aus Assembly "C: \ ..." kΓΆnnen nicht eingebettet werden, weil das ImportedFromTypeLibAttribute-Attribut oder das PrimaryInteropAssemblyAttribute-Attribut fehlt. with: ... \ sapnco.dll

(Interop types cannot be implemented because some attributes are missing).

Is it correct? If so, where to put these attributes?

+4
source share
1 answer

sapnco.dll is a .NET dll, so it is not exposed to COM, so you cannot directly use these types in a COM environment. The solution to your problem is to create a library to wrap sapnco.dll in classes open by COM:

As an example:

 [ComVisible(true)] public interface IComRfcTable { public void DoSomething(); } [ComVisible(true)] public class ComRfcTable { private _rfcTable; // object to wrap public ComRfcTable(IRfcTable rfcTable) { _rfcTable = rfcTable } public void DoSomething() { _rfcTable.DoSomething(); } } 

Then your method should be implemented as follows:

  public IComRfcTable table(...) { ... } 
+1
source

Source: https://habr.com/ru/post/1394983/


All Articles