By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,686 Members | 1,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,686 IT Pros & Developers. It's quick & easy.

Registering a COM Server using C#

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.