cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ricklin
Level 3

IsConnected() problem

Hi,

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.


Rick
0 Kudos
(2) Replies
Sunny_s
Level 6

Here is the C++ code snippet:

...
HRESULT hr ;
VARIANT_BOOL b = VARIANT_FALSE;
CComPtr 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
...
0 Kudos
ricklin
Level 3

Thanks Sunny. Initializing the VARIANT_BOOL parameter correctly did the trick!
0 Kudos