471,344 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

Registering a COM Server using C#

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

Jul 21 '05 #1
2 4803
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

"VivekR" <Ke*****@gmail.com> escribió en el mensaje
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Jul 21 '05 #2
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"VivekR" <Ke*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stangonline.com | last post: by
2 posts views Thread by glenn | last post: by
1 post views Thread by =?Utf-8?B?UmljaA==?= | last post: by
1 post views Thread by shivkumar2004 | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.