admin管理员组文章数量:1314058
I can register a dll complied by .NET framework 4.8 to registry as COM and use it from Delphi code, but I cannot do the same thing in .NET 5+
Class :
[ComVisible(true)]
[Guid("21487353-6AE0-403B-AA8D-57AE9725C9DB")]
[ClassInterface(ClassInterfaceType.None)]
public class ClassA : IClassA
{
public string GetStr()
{
return "Message text";
}
}
IClass:
[ComVisible(true)]
[Guid("1A3C6B1D-9420-45A4-BCD4-E7E31762D035")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IClassA
{
string GetStr();
}
I build the project as x86 architecture (.NET framework 4.8.1) then run regasm project.dll /codebase
.
When I check the registry entries, I saw that ClassA was successfully registered and it has a ProgId (ClassLib.ClassA
).
And I called it from Delphi code:
program Project1;
uses
ComObj,
SysUtils,
ActiveX;
var
COMObject: OleVariant;
ReturnValue: string;
begin
try
CoInitialize(nil);
COMObject := CreateOleObject('ClassLib.ClassA');
ReturnValue := COMObject.GetStr;
WriteLn('COM method called successfully.->'+ ReturnValue);
except
on E: Exception do
WriteLn('Error: ' + E.Message);
end;
CoUninitialize;
end.
Here, I got the "message text" from dll. There is no problem but I want to do same thing with .NET 8 project dll.
So I created a new .NET 8 class library project with x86 build configuration and add these two properties to a PropertyGroup
in .csproj
and compiled
<EnableComHosting>true</EnableComHosting>
<ComVisible>true</ComVisible>
The regasm tool is not working with a dll compiled by .NET 8 and so tried regsvr32 tool as said here
Command :
regsvr32 .\ClassLibhost.dll
The operation completed successfully, but I get an error:
No such interface supported
when I call that code from Delphi.
本文标签: cHow to register a NET 5 dll to registery as COM correctly and use it from Delphi codeStack Overflow
版权声明:本文标题:c# - How to register a .NET 5+ dll to registery as COM correctly and use it from Delphi code? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741959558a2407193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论