473,394 Members | 1,800 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,394 software developers and data experts.

ExitThread API fails

Here is the code.

Dim process, regLib, succeed As Integer
Dim xc, h1, id As Integer
Dim p As String

Select Case func
Case regxEnum.REGISTER
p = "DllRegisterServer"
Case regxEnum.UNREGISTER
p = "DllUnregisterServer"
Case Else
Return resultEnum.INVALID
End Select

regLib = LoadLibraryRegister(Path)

If regLib = 0 Then
Return resultEnum.NOTFOUND
End If

'get the address for either the Register or Unregister
process = GetProcAddressRegister(regLib, p)

If process = 0 Then
FreeLibraryRegister(regLib)
Return resultEnum.NOTACTX
Else
h1 = CreateThreadForRegister(0, 0, process, 0, 0, id)

'unable to create a thread for register or unregister
If h1 = 0 Then
FreeLibraryRegister(regLib)
Return resultEnum.NOTHREAD
Else
succeed = (WaitForSingleObject(h1, 2000) = 0)

If succeed Then
CloseHandle(h1)
FreeLibraryRegister(regLib)
Return resultEnum.SUCCESS
Else

GetExitCodeThread(h1, xc)
ExitThread(xc)

FreeLibraryRegister(regLib)

Return resultEnum.FAILURE
End If
End If
End If

Here is the problem:

I have a program running this code segment on lots of different
machines. However, on only 3 machines this code segment fails. I
have been able to track it down to when ExitThread(xc) is called, it
never returns. The value of xc when this API is called is 259. I am
a very green newbie with threading and am thoroughly confused by this.
I thought, since xc = 259, that means the thread is still running.
Shouldn't ExitThread just kill the thread? Am I missing something
important here? I would love to have some help in understanging this.

As always, thank you very much for your help.
Kalvin
Nov 20 '05 #1
4 1555
You might want to check the documentation for ExitThread. Any call to
ExitThread never returns since the thread making the call exits.
"Kalvin" <kt***@streck.com> wrote in message
news:87**************************@posting.google.c om...
Here is the code.

Dim process, regLib, succeed As Integer
Dim xc, h1, id As Integer
Dim p As String

Select Case func
Case regxEnum.REGISTER
p = "DllRegisterServer"
Case regxEnum.UNREGISTER
p = "DllUnregisterServer"
Case Else
Return resultEnum.INVALID
End Select

regLib = LoadLibraryRegister(Path)

If regLib = 0 Then
Return resultEnum.NOTFOUND
End If

'get the address for either the Register or Unregister
process = GetProcAddressRegister(regLib, p)

If process = 0 Then
FreeLibraryRegister(regLib)
Return resultEnum.NOTACTX
Else
h1 = CreateThreadForRegister(0, 0, process, 0, 0, id)

'unable to create a thread for register or unregister
If h1 = 0 Then
FreeLibraryRegister(regLib)
Return resultEnum.NOTHREAD
Else
succeed = (WaitForSingleObject(h1, 2000) = 0)

If succeed Then
CloseHandle(h1)
FreeLibraryRegister(regLib)
Return resultEnum.SUCCESS
Else

GetExitCodeThread(h1, xc)
ExitThread(xc)

FreeLibraryRegister(regLib)

Return resultEnum.FAILURE
End If
End If
End If

Here is the problem:

I have a program running this code segment on lots of different
machines. However, on only 3 machines this code segment fails. I
have been able to track it down to when ExitThread(xc) is called, it
never returns. The value of xc when this API is called is 259. I am
a very green newbie with threading and am thoroughly confused by this.
I thought, since xc = 259, that means the thread is still running.
Shouldn't ExitThread just kill the thread? Am I missing something
important here? I would love to have some help in understanging this.

As always, thank you very much for your help.
Kalvin

Nov 20 '05 #2

I suggest you forget about the threading APIs and do something like
this instead

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

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #3


Thank you very much for your reply. I like the methods but I still have
a problem.

A little more info, that I thought was not important, but maybe it is.
I have a COM component on lots of users machines. I have an .exe app
that checks the time stamp for the dll on the local machine against one
on the network, if the one on the network is newer, then the application
UnRegisters the local dll, copies the file from the network and
Registers it. When I use the method you suggest, after the dll is
Unregistered, and I attempt to copy the new file over the old file,
replacing it, I get an error that the file is in use. I have tried to
use a call:

Private Declare Function UnRegFile Lib "MyFile.dll" Alias _
"DllUnregisterServer" () As Long

to do unregister it, and a similar one to register it, but get the same
error.

Thank you again.
Kalvin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Kalvin,

Can't you run the app twice (perhaps from a batch file), once to
unregister and once to replace the file and re-register?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #5

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

Similar topics

1
by: Brendan Miller | last post by:
I am trying to close my application using Application.exit() in the frmMain_Closing event. When the form closes the process does not. My application only has one form (no other classes either). ...
4
by: Brian Keating EI9FXB | last post by:
Hello there, I've created a worker thread that will handle events. To give this worker thead a run loop i've called Application.Run(); What call should i make to cause this thread to leave its...
0
by: | last post by:
Hi there movers & shakers, The example below demonstrates a behaviour that is anoying the tits off of me! It doesn't happen whilst debugging from the IDE only when you run the compiled exe from...
6
by: kenneth fleckenstein nielsen | last post by:
Hi guru's It runs ok on my developmaschine, and on the test server that i've set up. but fails after installing on the customers server. I made a XML webservice that does these steps: a) access a...
7
by: SevDer | last post by:
Hi I have a class library that needs to download the HTML in a specific page of ours with provided querystring. When I open this URL with any browser, it loads fine. When I do WebRequest from Web...
1
by: comp.lang.php | last post by:
Consider my code: if ($this->isSuccessful && is_file($_FILES)) { // STEP 6: MOVE RESUME TO DIRECTORY $uuid = $this->sfug->getUUID(); if (!$uuid) $this->sfug->setUUID(); $uuid =...
2
by: Richard Hsu | last post by:
// code #include "stdio.h" int status(FILE * f) { printf("ftell:%d, feof:%s\n", ftell(f), feof(f) != 0 ? "true" : "false"); } int case1() { FILE * f = fopen("c:\\blah", "wb+"); int i = 5;
2
by: Anbu | last post by:
Sorry for cross posting the query. But I need a resolution as early as possible. I have developed an application to authenticate the user based on LDAP Search and authentication. The Windows...
12
by: Jim Rodgers | last post by:
I have a big asp file that has an error under certain conditions -- totally repeatable. However, it only fails when I set response.buffer = True at the top. WHen I set it False in order to debug...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.