winzip icon

Win CE Device Connection Detect II

Email
Submitted on: 2/6/2015 8:01:00 PM
By: Kwyshell (from psc cd)  
Level: Advanced
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 1768
 
     The code is based on my article "Win CE Device Connection Detect". But someone may find it will be crashed for new version of ActiveSync. Thank Alber to remind me of this problem.

After a simple test of my code, I have found why the code does not work. Once again VB's old problem, crash for multi-thread issue. As what we knew, VB is not a thread safety language. In this case, ActiveSync in process-server change the calling context to different context from original. It caused VB's runtime library crashed. Why does VB always crash for multi-thread? You can compile your VB code and generate a PDB for your debugger like VS or VS.Net.Use debugger to trap the error and you will understand why crash crash everywhere. VB's runtime always assumes we just live in single thread.

Another solution for this case is creating a COM server and passes the object reference to ActiveSync's COM Interface. VB supports STA thread model and all of object calls will be protected by STA. But this is not what a good solution for this case "A simple implementation".

My solution here is more complex but you don't have to create a COM server for your code. Since VB's code isn't thread-safety, we have to find it out and modify it. After observing the PDB behavior, we found following calls are not safe for MT. It's 'Any Win32 API code' and 'Most COM related VB-call'. Win32 API of VB's not safe. The problem is not caused by API but caused by VB's compiler adding some extra code (prolog/epilog) after each API calls (it's _VBASetSystemError and it's not safe).

We use ReplaceVTableEntry technique to do a wrapper by VB's Module. Because function of a module in VB is not belongs to any object and it will be called safely. After our wrap functions are called, we need to do something like synchronization and force original thread to deal our request here. What can we do any synchronization stuff without Win32 API functions and most object calls? Here I design a simple mechanism for VB's user. I just pass all of parameters to a buffer and deal this buffer by a continual time-loop. You can see the code and know what it's. The problem is that we just deal the parameters asynchronous and never cares about something like thread-safety for parameters processing.

But who cares!

http://home.kimo.com.tw/kwyshell/
http://kwyshekk.myweb.hinet.net/


 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.