473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Registering components(dll, ocx, etc) via API

Hi, I wrote this little function to register ocxs or dlls.. When it's
all right this function works properly, but justly, for example, if the
application runs with a user that hasn't administrator rights the
registration does not work. The problem is that it seems that the
called function 'dllregisterserver' does not return failure values.
Doesn't the function 'WaitForSingleObject' should return a non-zero
value if some fails? I'd really need that if the function that
registers the component fails for some reason I would be able to trap
the error someway. Here follows the code I use. I don't write here APIs
declaration too.
Some suggest to know if the registration works fine or not using this
method?

Thank you very much...

PS: Comments are in italian as I'm italian :-))

Public Function RegisterCmp(cmpPath As String) As Boolean
On Error GoTo err_RegisterCmp

Dim hLib As Long
Dim pAddress As Long
Dim hThread As Long
Dim dwThreadId As Long, dwRC As Long
Dim response As Long

RegisterCmp = False

hLib = 0
pAddress = 0
hThread = 0
dwThreadId = 0
dwRC = 0

hLib = LoadLibrary(cmpPath)

' controllo che hLib sia valido come valore (<>0)
If hLib Then
'Ottengo l'indirizzo della funzione DllRegisterServer
pAddress = GetProcAddress(hLib, "DllRegisterServer")
Else
oLog.Scrivi "ClsMgmFls_RegisterCmp(): Error loading library " &
cmpPath & _
".", Error
'Esco dalla function
Exit Function
End If

'Controllo pAddress che sia valido (<>0)
If pAddress Then
'Creo un thread che esegue la funzione presente all'indirizzo
retReg
'(DllRegisterServer). CreateThread restituisce un handle a tale
thread
hThread = CreateThread(0&, 0, pAddress, 0&, 0, _
dwThreadId)
Else
oLog.Scrivi "ClsMgmFls_RegisterCmp(): Error locating function "
& _
"''DllRegisterServer''.", Error
'Pulisco l'handle della library caricata in memoria
FreeLibrary hLib
Exit Function
End If

'Controllo che hThread sia valido (<>0). Se valido sta girando il
thread
If hThread Then
'Se dwRC prende un valore<>0 significa che sta ancora girando.
'Viene restituito un valore da WaitForSingleObject() ogni 100ms
dwRC = WaitForSingleObject(hThread, 100)
Else
oLog.Scrivi "ClsMgmFls_RegisterCmp(): Could not create the
thread " & _
"''DllRegisterServer''.", Error
'Pulisco l'handle della library caricata in memoria
FreeLibrary hLib
'Esco dalla funzione
Exit Function
End If

'Finchè dwRC non assume il valore 0 gli viene riassegnato il
valore di
'WaitForSingleObject ogni 100ms. Se ottiene 0 il thread è stato
eseguito
'con successo. Ovviamente se è già a 0 dopo la precedente
chiamata di
'WaitForSingleObject il ciclo non viene nemmeno eseguito.
Do While dwRC <> WAIT_OBJECT_0
dwRC = WaitForSingleObject(hThread, 100)
Loop

RegisterCmp = True

'Pulisco gli handles del thread creato e della library caricata
CloseHandle hThread
FreeLibrary hLib

Exit Function

err_RegisterCmp:
oLog.Scrivi "ClsMgmFls_RegisterCmp(): " & Err.Number & " - " &
Err.Description, Error
'Se esiste o l'handle della library o l'handle thread eseguo
pulizia
If hThread Then CloseHandle hThread
If hLib Then FreeLibrary hLib
End Function

Nov 21 '05 #1
3 2092
The problem is that it seems that the
called function 'dllregisterserver' does not return failure values.
It should, but different implementations may behave in different ways.

I don't write here APIs declaration too.
That's a shame, because I suspect they are incorrect based on your use
of Longs.

Some suggest to know if the registration works fine or not using this
method?


Well first of all I suggest you get rid of the CreateThread hack and
call the function with the proper signature. Here's an example

http://www.msjogren.net/dotnet/eng/s...dynpinvoke.asp

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
Ok Mattias I post here API decalrations too that I use in the module
where I define my function..

Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule
As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias
"LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule
As Long, ByVal lpProcName As String) As Long
Private Declare Function CreateThread Lib "kernel32" _
(ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal
lpStartAddress As _
Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId
As Long) _
As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal
hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Const WAIT_OBJECT_0 = &H0&

I repeat that the registration works very well.. The problem is that
the function WaitForSingleObject always returns the value '0'
(WAIT_OBJECT_O), that is, the value returned in case of success of the
function (DllRegisterServer in my case) even if, insted, the
registration fails. I wonder the reason of it, I am driving crazy for
it!! :-)

Nov 21 '05 #3
Thank you all equally (is it right?? :-) )
I''ve found my misterious key to resolve my problem.. I use the API
function GetExitCodeThread() that as out parameters gives the
dwExitCode that is a pointer to a variable which contains the return
code of the function that has run into the thread. In fact if I make
run the app with non admin privileges the dwExitCode contains
-2147467259 that is E_FAIL ;-)) Good!!

Bye bye!

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Prashanti | last post by:
Hi , I have built a windows application in c sharp which using the methods of COM Object. The application is working fine. Now need to make this application a package to deploy at client...
6
by: ian | last post by:
Hi All I have a DLL (nahd.dll) that has been supplied to me will a PBX phone system. According to the documentation it is to allow developers to write there own applications to monitor the...
7
by: anon | last post by:
Hi, How do i register a DLL(like OWC) on the server...will just running regsvr32 work....any syntax issues...?? Thanks. *** Sent via Developersdex http://www.developersdex.com *** Don't...
3
by: Arvind P Rangan | last post by:
hi, I have compiled a .dll. steps followed is try to upload the dll to global assembly method 1: al /i:temp.dll but this gives an error method 2: gacutil /i temp.dll - this uploads dll to global...
1
by: Brian Mitchell | last post by:
Please forgive the newbie question, but I created a Windows Control Library project and I am wondering how I go about registering the .dll so I can reference it in my other applications? (So it...
12
by: cfps.Christian | last post by:
I've got a nice little deadline here and have to deal with the dumbest things possible to get it done. I had to create an application that is spliced into another application via an event handler...
0
by: Grumpy Aero Guy | last post by:
I have an app that utilizes a DLL provided by a 3rd party. This DLL requires registration via "regsvr32" before adding it successfully as a reference in Visual Studio during development. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.