I'm trying to build an ISAPI Filter to run in IIS. ISAPI filters, as far as
I've read, can only be written in C/C++. I don't feel comfortable writing
the majority of the processing for this filter in C++ and no one else on my
team knows C++ well enough to maintain such a project. Instead, I'd like to
create an easier-to-debug c++ ISAPI filter that calls to a COM Interop C#
library that we can lock down solid, then write the majority of the code in
.net.
So now just for that little detail of getting c++ to load a com dll from .net.
The problem is that while the .net dll compiles sucessfully, dependency
walker doesn't show that any methods are exposed, which I assume it would.
Also, after importing the tlb into a test console c++ app sucessfully, I
can't actually reference any of the functions for early binding without a
linker error about not being able to resolve the external symbol.
Also, since i don't actually know what the dll method names look like from
the tlb, I can't try late-binding either.
Am I right about dependency walker and that it ought to show the exports if
I've written it correctly? How do I make that happen?
Thanks,
Jason
(PS: Why does VS.NET crash every time I compile the ISAPIHandler dll? The
crash happens AFTER I get the notification from the OnRegistration() that the
object is registered. If I comment that function out, no crash)
(PPS: Are Strong Names necessary? What should the strong "name" field be?)
Here's the code:
=========== .Net DLL
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace NSISAPIHandler
{
[Guid("0F60BB8E-1524-4cbe-B90A-637402397973")]
public interface IISAPIHandler
{
[DispId(1)] int GetValue();
}
[Guid("BDE5939D-3592-4d52-88BF-B88A32158585")]
public class ISAPIHandler : IISAPIHandler
{
[DispId(1)] public int GetValue()
{
return 42;
}
/*
// Removed because it crashes VS.NET
[ComRegisterFunction()]
static void OnRegistration(Type t)
{
MessageBox.Show(t.FullName + " is being registered.", "Registration
Notification");
}*/
}
}
=========== .Net DLL AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
...
[assembly: Guid("26EDF85C-C5DB-4d2c-BA53-CADAFCF8CA70")]
[assembly: ComVisible(true)]
[assembly: ClassInterface(ClassInterfaceType.None)]
...
[assembly: AssemblyKeyFile(@"path/to/StrongName.snk")]
[assembly: AssemblyKeyName("Are these two lines even necessary?")]
===========
#include <stdio.h>
#import "ISAPIHandler.tlb"
int GetValue();
int main(int argc, char* argv[])
{
int x;
printf("%i", GetValue());
scanf("%i", &x);
return 0;
}
Markku Heikkil? - 20 Oct 2004 10:33 GMT
Windows depndency walker does not show .Net Dll fiunctions.
Take a look at
http://www.codeguru.com/Cpp/Cpp/cpp_managed/interop/article.php/c4845/
I have managed to call C# DLL from VC++60 executable by this way.
> I'm trying to build an ISAPI Filter to run in IIS. ISAPI filters, as far as
> I've read, can only be written in C/C++. I don't feel comfortable writing
[quoted text clipped - 96 lines]
> return 0;
> }