Delphi : How to call the .Net 4.0 version of StrongNameSignatureVerificationEx

625 views Asked by At

I am trying to call StrongNameSignatureVerificationEx on IClrStrongName from Delphi (using Rad Studio Berlin)

My first attempt just used the definition

function StrongNameSignatureVerificationEx(
  wszFilePath : LPCWSTR;
  fForceVerification : boolean;
  var pfWasVerifided : boolean
): BOOL; stdcall; external 'mscoree.dll';

but this calls the .Net 2.0 version (which is not required for the target machines - gives a nice 'Please install .net framework 2.0/3.5 message')

There is a mechanism to create a CLR host and invoke the version of the routine from a specific runtime using TJclClrHost

var
  anHost : TJclClrHost;
  aClsId : TGUID;
  res : Boolean;
  obj : OleVariant;  // ? Not sure about this, copying from another example
begin

    anHost := TJclClrHost.Create('v4.0.30319');
    anHost. Start
    aClsId := StringToGuid('{9280188d-0e8e-4867-b30c-7fa83884e8de}'); 
    res := anHost.GetInterface(aClsId, obj);

    //...

However, I have no Delphi definition for IClrStrongName so once I get the object I don't see how to invoke any methods on it. Importing mscoree.tlb doesn't give one and a websearch revealed to me only a C++ definition from

  1. Is the code above correct (esp. the 'obj' parameter for GetInterface() )?
  2. Do I need an interface definition to invoke the method (is there a way to invoke by name)?
  3. Where can I obtain a Delphi definition for IClrStrongName?,
  4. How can I convert the C++ definition into Delphi?
1

There are 1 answers

12
David Heffernan On

The simplest way is to create a .net class library that exports the functionality that you need. Some ways to do that:

  1. Use a mixed mode C++/CLI class library. That allows you to create class unmanaged exports directly. These in turn can call into managed code.
  2. Create a C# class library and use Robert Giesecke's UnmanagedExports library to expose your functionality.

In both cases you end up with a .dll file whose functions you import into Delphi using the external directive.

There are plenty of examples of how to do both these things on the web, and here on Stack Overflow, so I won't attempt to create yet more identical examples.