Trying to use IActiveScriptProfilerControl::StartProfiling
from my C# code, I've created this interface definition:
[ComImport]
[Guid(@"784b5ff0-69b0-47d1-a7dc-2518f4230e90")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptProfilerControl
{
void StartProfiling(
ref Guid clsidProfilerObject,
ProfilerEventMask eventMask,
uint dwContext);
// ...
}
Which I believe is correctly translated to .NET.
The original first parameter is defined as
[in] REFCLSID clsidProfilerObject
With these definitions:
typedef GUID CLSID;
typedef CLSID *REFCLSID;
I'm also able to create an instance of Microsofts JQueryScriptEngine
object and query for the IActiveScriptProfilerControl
.
What I'm currently failing at is how to tell the StartProfiling
function to use my IActiveScriptProfilerCallback
-derived object.
My question:
How to connect my own profiler callback class with the active script profiler control interface through a call to IActiveScriptProfilerControl::StartProfiling
?
Ideally, I would love to do this without the need to RegAsm my class.
Update 1:
I've changed the first parameter of interface definition to:
[ComImport]
[Guid(@"784b5ff0-69b0-47d1-a7dc-2518f4230e90")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IActiveScriptProfilerControl
{
void StartProfiling(
IActiveScriptProfilerCallback clsidProfilerObject, // <-- changed.
ProfilerEventMask eventMask,
uint dwContext);
// ...
}
and tried to call this function by passing an instance of my IActiveScriptProfilerCallback
-derived class.
Still, I get the error:
Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
(Update from my future self that came here while searching for a similar error)
I've managed to solve this by monitoring the registry, both when doing a Regasm.exe call on my assembly, as well as when monitoring what keys the profiler requests when valling
StartProfiling
.These keys were required for
HKEY_CLASSES_ROOT
:Another suggestion for JScript is to also add:
Since I wanted my program to run without administrative privileges, I've create a class to create the above keys unter
HKEY_CURRENT_USER
, wich also works.Following is the full class file for reference purposes:
Update July 2018
I've once again got the initial error on my development machine when running directly from within Visual Studio 2017:
After some try and error, I figured out that this was due to the fact, that I configured my Visual Studio to always run as an administrator.
When starting from within this context, somehow something seems to go wrong. I still don't know what exactly.
Solution for this was to simply start my executable directly from Windows File Explorer and not from within Visual Studio.
Another possible solution (which I didn't try) should be to not run Visual Studio as an administrator.