View Full Version : IsConnected() problem

05-07-2003, 04:47 PM

I have a question on using the IsConnected() feature using Visual C++ 7.0 (.NET). I am evaluating the Installshield hosted feature of UpdateService.

In the VB example, IsConnected() method is called without parameters. However, it looks like IsConnected() requires that you pass the parameter VARIANT_BOOL* pVal in order to call it in Visual C++. The UpdateService documentation shows this:

HRESULT IsConnected( VARIANT_BOOL* pVal );

If this the case? If so, what should the pVal be initialized to? If I don't initialize it, I get the:

Run-Time Check Failure #3 - The variable 'pVal' is being used without being defined.

error when I run it. If I go ahead and "Continue", the HRESULT returns false. If I call AppUpdate() instead, the internet connection is there because the Installshield update website pops up in a browser window.

Can anyone tell me how to correctly use IsConnected() ? Thanks.


05-07-2003, 05:29 PM
Here is the C++ code snippet:

CComPtr<IAgent3> spAgent;

hr = spAgent.CoCreateInstance(CLSID_Agent);

if (FAILED(hr))
throw hr;

hr = spAgent->IsConnected(&b);

In VB, runtime takes care of HRESULT so that VB programmer can work on better things. In other words, VB programmer does not have to worry about error checks after each line of code.
VB runtime raises the Error to the end-user. HRESULT is never directly exposed.

If you look closely the way IsConnected () is defined in type library of agent as:
HRESULT IsConnected([out, retval] VARIANT_BOOL* pVal);

pVal has a attribute of retval (return value).

Attribute [out, retval] tells VB runtime to pass temporary var as first argument to IsConnected() and show it as return value to the function IsConnected().

An VB example is as follows:
Dim pAgent as Object
Set pAgent = CreateObject( "DWUpdateService.Agent" )
If Not( pAgent.IsConnected( ) ) Then
MsgBox "You are not connected to the Internet."
End If

05-07-2003, 05:45 PM
Thanks Sunny. Initializing the VARIANT_BOOL parameter correctly did the trick!