Microsoft KB Archive/253863

= BUG: Sample Gateway (SGW) Returns Exception When it Is Run as a Console Application =

Article ID: 253863

Article Last Modified on 3/4/2004

-

APPLIES TO


 * Microsoft Exchange Development Kit 5.5
 * Microsoft Exchange Server 2003 Software Development Kit

-



This article was previously published under Q253863



SYMPTOMS
When you debug the Sample Gateway (SGW) as a console application, an unhandled exception may occur.



CAUSE
The definition of the HRESULT_FROM_WIN32 macro in the Winerror.h file is as follows: In this macro, x is evaluated twice. In our situation here, x is the RegCloseKey function. The first time that the RegCloseKey function is called, the registry key handle is closed. The second time that the RegCloseKey function is called, the handle is invalid, which causes an "Invalid handle" exception to be returned.
 * 1) define HRESULT_FROM_WIN32(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000)))



RESOLUTION
NOTE: The SGW will function correctly and ignore the exception, if you click OK, click Go on the toolbar, click Yes, and then click Go again.

To resolve this problem, modify line 389 in the Gwmain.c file. Replace the following line HR_LOG(HRESULT_FROM_WIN32(RegCloseKey(hkParameters))); with these two lines: DWORD err=RegCloseKey(hkParameters); HR_LOG(HRESULT_FROM_WIN32(err));



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Install the Sample Gateway.For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

200669 HOWTO: Install the Sample Gateway in Exchange Development Kit

 In Microsoft Visual C++, from the Tools menu, click Options, and then click Directories. Make sure that the Platform SDK Include files are listed before the Visual C++ Include files in the list. Open the ExchSDK.dsw project and rebuild the debug version of the Exchange Development Kit (EDK) library, ExchSDKd.lib. From the Project menu, click Setting, click Link, click General, and then click to clear the Incremental Link option. Rebuild the Gwsample.exe file.</li> Set a breakpoint on line 389 in the Gwmain.c file.</li> Run the sample as a console application under the debugger. If the service is registered under HKLM\SYSTEM\CurrentControlSet\Services\SGW, pass "notserv SGW" as parameters.</li></ol>

<div class="references_section">