奇怪的是,我无法在StackOverflow上找到答案,网上也没有太多,特别是对于Delphi.我发现了这里发布的示例解决方案.这是我最后得到的:
function ClrCreateManagedInstance(pTypeName: PWideChar; const riid: TIID;
out ppObject): HRESULT; stdcall; external 'mscoree.dll';
procedure TMyDotNetInterop.InitDotNetAssemblyLibrary;
var
MyIntf: IMyIntf;
hr: HRESULT;
NetClassName: WideString;
begin
//Partial assembly name works but full assembly name is preffered.
NetClassName := 'MyCompany.MyDLLName.MyClassThatImplementsIMyIntf,
MyCompany.MyDLLName';
hr := ClrCreateManagedInstance(PWideChar(NetClassName), IMyIntf, MyIntf);
//Check for error. Possible exception is EOleException with ErrorCode
//FUSION_E_INVALID_NAME = $80131047 2148732999 : The given assembly name
//or codebase was invalid.
//COR_E_TYPELOAD = $80131522 - "Could not find or load a specific type
//(class, enum, etc)"
//E_NOINTERFACE = $80004002 - "Interface not supported".
OleCheck(hr);
end;
Run Code Online (Sandbox Code Playgroud)
顺便说一句,根据具体情况,你可能想要动态加载mscoree.dll,因为它可能不存在于系统上(没有.Net Framework的XP)
编辑:不幸的是,我刚刚发现,这已被弃用并停止使用.Net4.这只留下两个选项 - CLR托管和非托管导出.此外,.Net4 COM代码的调试被破坏.
| 归档时间: |
|
| 查看次数: |
5658 次 |
| 最近记录: |