DLLSelfRegister from VB.Net

G

Guest

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
 
P

Paul Clement

¤ 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)
 
P

Peter Huang [MSFT]

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.
 
G

Guest

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
 
C

Chris

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.
 
P

Peter Huang [MSFT]

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.
 

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

Top