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

DLLSelfRegister from VB.Net

P: n/a
I wrote a VB.NET desktop utility that uses "DLLSelfRegister" function from
the vb6stkit.dll
However,I have turned the
application into a service (customer's requirement) running in an
administrators account.
Now DLLSelfRegister fails to register the component, returning a value
of FAIL_OLE = 3 which means "unable to initialize OLE to register file"

I can shell to RegSvr32.exe from my service and that works ok,
but doesnt return a success or failure value.

Is there something about services that prevents this working?

Is there anyway to register an activex dll or ocx file from vb.net that
will work from in a service, or is there anything I can do to my service
to make vb6stkit.dll work?

The activeX dlls and ocxs are used by vb6 applications, so they do need to
be registered.

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Fri, 23 Sep 2005 03:18:01 -0700, "John Robinson" <so********@online.nospam> wrote:

I wrote a VB.NET desktop utility that uses "DLLSelfRegister" function from
the vb6stkit.dll

Please don't double post.
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #2

P: n/a
Hi

I think "DLLSelfRegister" is an undocument API, we do not recommend you use
it in your application directly.
Since regsvr32 works for you, but it never return, I think that is because
commonly Windows Service is not run in the currently logon windows desktop.
So when we run the regsvr32, commonly it will show a msgbox to tell us
success or not, because the regsvr32 runs in another windows desktop, so
the msgbox is shown but we did not see it.
It is similar with we show msgbox in ASP/ASP.NET code behind code(not the
client script), it will not be seen.

Here is KB about how regsvr32 works including the code.
207132 INFO: How Regsvr32.exe Registers and Unregisters COM DLLs
http://support.microsoft.com/?id=207132

I think you may try to change it to excluding the UI related code, e.g.
MessageBox.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #3

P: n/a
Thankyou Peter, the KB article was helpfull.

Now, how can I call the DLLSelfRegister function of the dll or ocx?

My code so far:

Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA"
(ByVal lpLibFileName As String) As Integer
Public Declare Function GetProcAddress Lib "kernel32" Alias
"GetProcAddress" (ByVal hModule As Integer, ByVal lpProcName As String) As
Integer
Public Declare Function FreeLibrary Lib "kernel32" Alias "FreeLibrary"
(ByVal hLibModule As Integer) As Integer
Public Declare Function OLEInitialize Lib "ole32" Alias "OleInitialize" ()
As Integer
Public Declare Function OleUninitialize Lib "ole32" Alias "OleUninitialize"
() As Integer
Dim pszDllEntryPoint As String = "DllRegisterServer"

Sub RegisterThis(ByVal sDllName As String)
OLEInitialize()
Dim hlib As Integer = LoadLibrary(sDllName)
Dim lpDllEntryPoint As Integer = GetProcAddress(hlib, pszDllEntryPoint)
{WHAT GOES HERE TO INVOKE THE FUNCTION INDICATED BY THE lpDllEntryPoint
POINTER?}
FreeLibrary(hlib)
OleUninitialize()
End Sub

I await your answer with grateful anticipation

""Peter Huang" [MSFT]" wrote:
Hi

I think "DLLSelfRegister" is an undocument API, we do not recommend you use
it in your application directly.
Since regsvr32 works for you, but it never return, I think that is because
commonly Windows Service is not run in the currently logon windows desktop.
So when we run the regsvr32, commonly it will show a msgbox to tell us
success or not, because the regsvr32 runs in another windows desktop, so
the msgbox is shown but we did not see it.
It is similar with we show msgbox in ASP/ASP.NET code behind code(not the
client script), it will not be seen.

Here is KB about how regsvr32 works including the code.
207132 INFO: How Regsvr32.exe Registers and Unregisters COM DLLs
http://support.microsoft.com/?id=207132

I think you may try to change it to excluding the UI related code, e.g.
MessageBox.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #4

P: n/a
This is .net why are you registering the dll anyway? there is no need for
it..
you can use reflection if you are tyring to reference a .dll at run time.

"John Robinson" <so********@online.nospam> wrote in message
news:2F**********************************@microsof t.com...
Thankyou Peter, the KB article was helpfull.

Now, how can I call the DLLSelfRegister function of the dll or ocx?

My code so far:

Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA"
(ByVal lpLibFileName As String) As Integer
Public Declare Function GetProcAddress Lib "kernel32" Alias
"GetProcAddress" (ByVal hModule As Integer, ByVal lpProcName As String) As
Integer
Public Declare Function FreeLibrary Lib "kernel32" Alias "FreeLibrary"
(ByVal hLibModule As Integer) As Integer
Public Declare Function OLEInitialize Lib "ole32" Alias "OleInitialize" ()
As Integer
Public Declare Function OleUninitialize Lib "ole32" Alias
"OleUninitialize"
() As Integer
Dim pszDllEntryPoint As String = "DllRegisterServer"

Sub RegisterThis(ByVal sDllName As String)
OLEInitialize()
Dim hlib As Integer = LoadLibrary(sDllName)
Dim lpDllEntryPoint As Integer = GetProcAddress(hlib, pszDllEntryPoint)
{WHAT GOES HERE TO INVOKE THE FUNCTION INDICATED BY THE lpDllEntryPoint
POINTER?}
FreeLibrary(hlib)
OleUninitialize()
End Sub

I await your answer with grateful anticipation

""Peter Huang" [MSFT]" wrote:
Hi

I think "DLLSelfRegister" is an undocument API, we do not recommend you
use
it in your application directly.
Since regsvr32 works for you, but it never return, I think that is
because
commonly Windows Service is not run in the currently logon windows
desktop.
So when we run the regsvr32, commonly it will show a msgbox to tell us
success or not, because the regsvr32 runs in another windows desktop, so
the msgbox is shown but we did not see it.
It is similar with we show msgbox in ASP/ASP.NET code behind code(not the
client script), it will not be seen.

Here is KB about how regsvr32 works including the code.
207132 INFO: How Regsvr32.exe Registers and Unregisters COM DLLs
http://support.microsoft.com/?id=207132

I think you may try to change it to excluding the UI related code, e.g.
MessageBox.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #5

P: n/a
Hi

So far .NET P/Invoke did not provide the approach call a function based on
a unmanaged function pointer which is returned from GetProcAddress, because
NET is all based on MSIL, the actually function call is handled by CLR via
JIT.

For you scenario, you may need to wrap the regsiter code in COM and
reference it from .NET.

Here is an article.
http://www.codeproject.com/csharp/dyninvok.asp

NOTE: Use the approach above will be at your own risk, and it is not a
supported behavior.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.