gashtio 25 Light Poster

The User-agent field is mainly used for formatting the response accordingly (e.g. for mobile phones) and shouldn't result in an error code(4xx). The 405 you're getting means that the method used in the request (POST) is not allowed. If you examine the headers of the response from google.com you'll see "Allow: GET, HEAD" so you'll have to change the request method to either of those.

On a side note, if you're only going to be sending text and not binary data, you don't need the "multipart/form-data" content type.

gashtio 25 Light Poster

You can use BinaryFormatter 's Serialize and Deserialize methods instead of StreamWriter / StreamReader . Here's a little sample I wrote (with no error checking at all):

Receiver

static void Main(string[] args)
{
    TcpListener listener = new TcpListener(IPAddress.Any, 5005);
    listener.Start();
    Console.WriteLine("Server started.");

    Socket client = listener.AcceptSocket();
    Console.WriteLine("Accepted client {0}.\n", client.RemoteEndPoint);

    List<string> l = null;

    using (NetworkStream ns = new NetworkStream(client))
    {
        BinaryFormatter bf = new BinaryFormatter();
        l = (List<string>)bf.Deserialize(ns);
    }

    if (l != null)
        foreach (var item in l)
            Console.WriteLine(item);

    client.Close();
    listener.Stop();
}

Sender

static void Main(string[] args)
{
    TcpClient client = new TcpClient();
    client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5005));
    Console.WriteLine("Connected.");

    List<string> l = new List<string>() { "Lorem", "ipsum", "dolor", "sit", "amet" };

    BinaryFormatter bf = new BinaryFormatter();
    NetworkStream ns = client.GetStream();
    bf.Serialize(ns, l);
    Console.WriteLine("Data sent.");

    ns.Close();
    client.Close();
}
gashtio 25 Light Poster

I see... why do they provide these make_heap functions then?

Because you might have an existing collection that you want to turn into a heap in-place, instead of duplicating the elements using push es into a priority_queue .

Or, if you want to guarantee a O(nlogn) bound of a sort, you can use make_heap alongside sort_heap to produce heap sort (although library implementations of std::sort usually have optimizations so it doesn't degenerate to O(n^2)).

gashtio 25 Light Poster

There's a newline between 1010101a and 1a, which has a different character code from 'a', so you get an additional true in your vector.

gashtio 25 Light Poster

Use _tprintf( TEXT("%s"), lpszDevName ); instead. You'll also have to #include <tchar.h> .

gashtio 25 Light Poster

The problem lies in the loop filling the bitmap data.

You can make a simple calculation of how many bytes you are writing - 3 each iteration, width*height/3 iterations - a total of width*height bytes, not pixels. Essentially, you're writing to every third pixel, hence the diagonal lines.

To correct the problem you should just replace the j+=3 in the loop with j++ .

hanvyj commented: Thanks for taking the time to spot my mistake! +1
gashtio 25 Light Poster

This code should only hang if you lift the key while the worker thread is executing this:

while(WaitForSingleObject(input->run, 0) != WAIT_OBJECT_0)
{
	SetWindowTextA(input->hWnd, "Hello");
	Sleep(500);
	SetWindowTextA(input->hWnd, "Goodbye");

but not this:

Sleep(500);
}

The problem is that SetWindowText actually sends WM_SETTEXT (sends, not posts) so it blocks until the main thread handles it. But after setting the event the main thread is stuck waiting on hThread and you get a deadlock.

To avoid that you should post the message instead of sending it (bear in mind that you can't post WM_SETTEXT, so you'll have to define your own message and handle it in the main thread procedure).

gashtio 25 Light Poster

You have to process the WM_CTLCOLORSTATIC message in the parent window (WM_CTLCOLOREDIT should you change the edit box style so it is neither disabled nor read-only). It is sent by the control to its parent before being drawn, passing its device context in the WPARAM, so you can change text/background color in the message handler.

The code would be something like this:

case WM_CTLCOLORSTATIC:
{
	HDC hEdit = (HDC)wParam;

	SetTextColor( hEdit, RGB(0, 0, 0) );
	SetBkColor  ( hEdit, RGB(255, 255, 255) );

	// Do not return a brush created by CreateSolidBrush(...) because you'll get a memory leak
	return (INT_PTR)GetStockObject( WHITE_BRUSH );
}

The return value is the brush used to paint the background. Also, the MSDN documentation is incorrect, the brush is not deleted by the system (at least not on Vista/7) so if you need a custom color brush, create it once and delete it when the window closes.

Bear in mind that the system overrides the text color of disabled controls, so you wouldn't be able to change it this way. Instead, you can specify ES_READONLY when creating the edit box (the text will be selectable, though).

Graphix commented: Thanks for the solution! +1
gashtio 25 Light Poster

You can call ISpVoice::Speak asynchronously and then use the ISpVoice::WaitUntilDone method, which does exactly what you want.

pVoice->Speak( szText, SPF_ASYNC, NULL );
pVoice->WaitUntilDone( 3000 ); // 3 seconds
donaldw commented: Awesome! Thanks so much! Exactly what I needed. +1
gashtio 25 Light Poster

The problem lies here HashTable = new (nothrow) ListSet [size]; .

Short explanation:

You are allocating an array of ListSet objects and handing the returned pointer to a Set * . This is not how inheritance works - you should allocate an array of Set pointers instead, and then allocate a ListSet object for each pointer. In code, that is:

int nSize = ...;
Base ** ppStuff = new Base * [nSize];
for( int i = 0; i < nSize; ++i )
	ppStuff[i] = new Derived();

...

for( int i = 0; i < nSize; ++i )
	delete ppStuff[i];
delete [] ppStuff;

Long explanation:

Every class that has virtual functions has a static virtual table - that's essentially an array of function pointers, one for each virtual function. Hidden from the programmer, the compiler adds a member variable - a pointer to that v-table. So your Set class actually looks something like this (in pseudocode):

class Set
{
public:
	typedef string T;
	virtual void Add(const T& key) = 0;
	virtual bool Contains(const T& key) = 0;
	virtual void Print() = 0;
	virtual void Remove(const T& key) = 0;

	function_ptr * __vfptr; // a pointer to a function pointer
	static function_ptr __vftable[] = { &Set::Add, &Set::Contains, &Set::Print, &Set::Remove };
	__vfptr = &Set::__vftable[0];
};

and the ListSet class:

class ListSet : public Set
{
	...

	static function_ptr __vftable[] = { &ListSet::Add, &ListSet::Contains, &ListSet::Print, &ListSet::Remove }; // this table is different from the Set one
	__vfptr = …
DarkT commented: solved my problem :) +0
gashtio 25 Light Poster

You can use one of the Marshal::StringToHGlobalAnsi/Auto/Uni methods to copy the string into unmanaged memory, and then clean up with Marshal::FreeHGlobal when you're done.

There's an example here that does exactly that.

inisca commented: Thank you +rep +0
gashtio 25 Light Poster

This happens because StreamReader::ReadLine returns nullptr when the end of stream is reached (which is the case when reading an empty file).

That means that on line 8 of your code line is now nullptr , and not the initial empty string. Since they do not compare equal to each other, the second if statement is entered, and because nullptr does not have a string representation, nothing is printed between the two 2's.

To observe the correct behavior, change the last part to:

if ( String::IsNullOrEmpty( line ) )
{
	MessageBox::Show("1" + line + "1");
}
else
{
	MessageBox::Show("2" + line + "2");
}
jonsca commented: Good +4
gashtio 25 Light Poster

There are quite a few things wrong :).

- All the "mdim_ = mdim_;" stuff is useless.

- In the Matrix(int cols) constructor, mdim_ remains uninitialized and you're getting a crash - you should set it to cols.

- The SetElement() function is incorrect, it should read:

void Matrix::SetElement(int m, int n, double d)
{
	data_[(m - 1) * ndim_ + n - 1] = d;
}

- In WriteToFile(), the correct formula is:

myfile << data_[i * ndim_ + j] << " ";

The idea is that you've processed i rows, each having ndim_ columns, plus j more columns from the current row.

Also, you need to open the file just once, not in each innermost iteration.

And you should probably do some error checking when adding (are the matrices the same size), setting element (is it within bounds), etc.

gashtio 25 Light Poster

What is the desired direction of the ray? If it is +Z, just specify (0,0,1) for rayDirection.

Currently you're generating something rather strange - a direction parallel to the line, defined by the points (0,0,0) and (shotOrigin._41, 0, shotOrigin._43) from line 4 of your code.

Otherwise, the conversion from world to model space is correct. And btw, the call to D3DXMatrixIdentity() is redundant.