0

I have a class named NativeMethods.cs which contains all extern methods:

internal static class NativeMethods
{
    [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool wow64Process);

    [DllImport("advapi32.dll", CharSet = CharSet.Auto)]
    internal static extern int RegOpenKeyEx(
        IntPtr hKey,
        string subKey,
        int ulOptions,
        int samDesired,
        out int hkResult);
}

The assembly containing this class has a corresponding .Moles file. All other classes included in the assembly can be moled and stubbed properly, except this one.

There is no MNativeMethods that we can use for detouring. Is there a special case against the class name "NativeMethods" (Highly unlikely)? Or a special case against extern methods?

Ian
  • 5,625
  • 11
  • 57
  • 93

2 Answers2

0

Moles is capable of detouring calls to managed code. This class is clearly not dealing with managed code. Try creating a stub for this class, manually. This means crating an INativeMethods interface, have NativeMethods implement INativeMethods, and then use the interface as the stub, as usual. Moles will then generate stub type SINativeMethods from the interface, for use in test projects.

Mike Christian
  • 1,526
  • 1
  • 15
  • 27
0

"Thus, if a method has no body (such as an abstract method), we cannot detour it." - Moles Dev

Ian
  • 5,625
  • 11
  • 57
  • 93