Program Stops Debugging

Hi Guys,

Really need some help here. I downloaded some code from a manufacturers website which they tell me works however when I debug the code, the terminal window appears for a spilt second and then stops (When it flashes it shows code line 150 only). I have looked through the code many times and cannot seem to find the problem. Please forgive me if I have missed something however I’m not an expert C/C++ programmer.

Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <comutil.h>				// for _bstr_t
#include <iostream>
#include <objbase.h>				// Necessary for COM
#include <stdio.h>
#include <tchar.h>

#include "FormattedOutput.h"
#include "Menu.h"
#include "VideohubAPI_h.h"


class MyVideohubCallback : public IVideohubCallback
{
	int					m_refCount;
	IVideohubState *	m_state;
	IVideohub *			m_hub;
	
public:
	
	MyVideohubCallback(IVideohub *hub) : m_hub(hub), m_refCount(0), m_state(NULL) {}
	~MyVideohubCallback() 
	{
		if (m_state!=NULL)
			m_state->Release();
	}
	
	HRESULT STDMETHODCALLTYPE StateChanged()
	{
		if (m_state == NULL)
		{
			// it is the first we are called, get the IvideohubAttributes interface
			// and print some details about the Videohub device
			printDeviceInfo();

			// we havent got an IVideohubState yet, get one
			if(m_hub->GetState(&m_state)==S_OK)
			{
				dumpState(m_state);
			}
		}
		else
		{
			// we already have an IVideohubState, update it
			// and get an iterator over the changes
			IVideohubStateChangeIterator *iter;
			
			if (m_state->UpdateState(&iter)==S_OK)
			{
				dumpChanges(m_state, iter);
				iter->Release();
			}
		}

		// re-print the user menu
		printMenu();

		return S_OK;
	}
	
	HRESULT STDMETHODCALLTYPE DeviceDisconnected()
	{
		printf_s("******\tVideohub DISCONNECTED\t******\n");
		return S_OK;
	}
	
	HRESULT STDMETHODCALLTYPE DeviceReconnected()
	{
		printf_s("******\tVideohub RECONNECTED\t******\n");
		return S_OK;
	}

	HRESULT STDMETHODCALLTYPE NewDeviceConnected()
	{
		return S_OK;
	}
	
	// IUnknown interface methods
	HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
	{
		HRESULT			result = E_NOINTERFACE;

		*ppv = NULL;

		if (iid == IID_IUnknown)
		{
			*ppv = this;
			AddRef();
			result = S_OK;
		}
		else if (iid == IID_IVideohubCallback)
		{
			*ppv = (IVideohubCallback*)this;
			AddRef();
			result = S_OK;
		}
		
		return result;
	}
	
	ULONG STDMETHODCALLTYPE AddRef(void)
	{
		m_hub->AddRef();
		return InterlockedIncrement((LONG*)&m_refCount);
	}
	
	ULONG STDMETHODCALLTYPE Release(void)
	{
		long		newRefValue;

		m_hub->Release();
		newRefValue = InterlockedDecrement((LONG*)&m_refCount);
		if (newRefValue == 0)
		{
			delete this;
		}
		
		return newRefValue;	
	}

	void printDeviceInfo()
	{
		IVideohubAttributes *attributes = NULL;
		
		if (m_hub->QueryInterface(IID_IVideohubAttributes, (void **) &attributes)==S_OK)
		{
			// print some info about the device
			dumpVideohubInfo(attributes);
			
			// release the interface
			attributes->Release();
		}
		else
		{
			printf("Error obtaining the Attributes interface\n");
		}
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	HRESULT					result;
	IVideohubDiscovery		*videoHubDiscovery = NULL;
	IVideohub				*videohub;
	MyVideohubCallback		*cb;


	// check the arguments
	if (argc!=2)
	{
		printf_s("usage: DeviceState <videohub device address>");
		return 1;
	}

	// initialise the device address
	_bstr_t deviceAddress(argv[1]);
	
	// Initialize COM on this thread
	result = CoInitialize(NULL);
	if (FAILED(result))
	{
		printf_s("Initialization of COM failed - result = %08x.\n", result);
		return 1;
	}

	// Create an IVideohubDiscovery object
	result = CoCreateInstance(CLSID_CVideohubDiscovery, NULL, CLSCTX_ALL, IID_IVideohubDiscovery, (void**)&videoHubDiscovery);
	if (FAILED(result))
	{
		printf_s("A Videohub Discovery object could not be created.\n");
		goto bail;
	}

	// get an IVideohub object for our device address
	if(videoHubDiscovery->ConnectTo(deviceAddress, 10000, &videohub) == S_OK)
	{
		// instantiate an IVideohubCallback object to receive state change notifications
		cb = new MyVideohubCallback(videohub);
		cb->AddRef();

		// register the callback object
		videohub->AddVideohubCallback(cb);

		// wait for user input
		// this function returns when the user selects the Quit option
		waitForUserInput(videohub);

		// remove the callback object
		videohub->RemoveVideohubCallback(cb);

		// release the callback object
		cb->Release();

		// release the IVideohub object
		videohub->Release();
	}
	else
	{
		printf_s("An IVideohub object could not be created for the given address\n");
	}

	// release the VideohubDiscovery object
	videoHubDiscovery->Release();

bail:
	// Uninitalize COM on this thread
	CoUninitialize();

	return 0;
}
Last edited on
Did you set any breakpoints? Debug will not pause until you tell it so. For now it looks like program finds that it wasn't passed exactly two arguments and finishes working.
All as it should be
Last edited on
Hi MiiNiPaa,

No breakpoints have been set. Is there a way I can find how many arguments have/are actually being passed?

Thanks for your help.
Don't you supply the arguments yourself? How are you running it?
Simply by debugging. I would expect the terminal window to stay and wait for my input(s). This is how I’ve been told this should work which is why I am so confused.

As things stand, how would I go about supplying the arguments myself?
Problem that this program is not getting any input aside from one command line argument.
As things stand, how would I go about supplying the arguments myself?


I'll ask again: How are you running it?
I am trying to run via CMD but simply dont know how to. How am i able to run?

All other development I have done has simply been windows form application.
In your IDE there should be "set program arguments" option somewhere.

EDIT: I assume you are running MSVS:
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/c655c026-e84d-4eab-b61f-a6f951643467/
In Project Properties, expand Configuration Properties, and then click Debugging.
In the pane on the right, in the textbox to the right of Command Arguments, type the arguments to main you want to use. For example, one two
Last edited on
Iv looked for this but am unable to to find. I am using Visual Studio 2012. I have seached the web but am unable to find anything.
http://stackoverflow.com/questions/298708/debugging-with-command-line-parameters-in-visual-studio
In VS 2008, 2010, or 2012, right-click the project, choose properties, go to the Debugging section -- there is a box for command line arguments.
Topic archived. No new replies allowed.