Registering a COM Server using C#

  • Thread starter Thread starter VivekR
  • Start date Start date
V

VivekR

Hi All,

I was using VC++ earlier to register COM Server programmatically. What
i do is I use LoadLibrary(Desired COM DLL), then
GetProcAddress("DllRegisterServer"), and then call that function using
the function pointer that GetProcAddress returns. How do i do that in
C#, I tried using the DllImport attribute for calling LoadLibrary and
GetProcAddress, it works but at last GetProcAddress returns a fucntion
pointer ie a FARPROC or barely long, and i don't know how to use it as
a function pointer in C#.

Please help in this regard

Thanks in advance,
Vivek Ragunathan
 
Hi,

If the COM DLL is known at compile time, try to use DllImport directly with
the DllRegisterServer function of your COM DLL and call it.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Vivek,

You won't be able to do this dynamically in .NET 1.1 or before.
However, in .NET 2.0, you can create a delegate with the appropriate
signature, like so:

// The delegate for DllRegisterServer.
[return:MarshalAs(UnmanagedType.Error)]
private delegate int DllRegisterServerFunction();

Once you have that, you can pass the IntPtr representing the value that
GetProcAddress returns to the static GetDelegateForFunctionPointer method on
the Marshal class, and it will return a delegate that you can call to invoke
the method in the DLL.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top