Some stuff with media in WM

25/10/2008

Trong namespace Microsoft.WindowsMobile.Forms có các lớp sau:

- CameraCaptureDialog

- SelectPictureDialog

- ChooseContactDialog

Vẫn đang tìm cách làm việc tương tự trong native code.

Update: Hình như WinCE có API SHCameraCapture, GetOpenFileNameEx… j j đó. Xong cái này!


Ensure reading data from socket in .NET

18/10/2008
private void ReadSockData(Socket sock, int len, byte[] dest)
{
  int iByteRead = 0;
  while (iByteRead < len)
  {
    iByteRead += sock.Receive(dest, iByteRead, len - iByteRead,
SocketFlags.None);
  }
}

Here’s Why It’s Windows 7

15/10/2008

Đọc cái này nghe nhảm ko chịu dc :) )

The mystery of Microsoft’s Windows version count has been solved. A day after announcing (in the Windows Vista blog) that the next release of Windows will be called Windows 7, Mike Nash (Microsoft Corporate VP, Windows Product Management) added a post laying out Microsoft’s Windows version numbers since Windows 3.x.

Basically, they go like this:

Version 4: Windows 95

Version 4 point releases: Windows 98, 98SE, and ME (4.0.1998, 4.10.2222 and 4.90.3000, respectively).

Version 5: Windows 2000

Version 5 point releases: Windows XP (5.1)

Version 6: Windows Vista

I was surprised to realize that Windows XP (in which Microsoft unified the code bases for Windows 9x and NT/2000) was only a point release. But at least we now know how they got to Windows 7.

Source: http://www.pcworld.com/article/152261/Windows_7_naming.html?tk=rss_news


Microsoft’s new ‘M’ programming language

14/10/2008

In a software-centric world where we already have many, many languages to program in, from scripting to bytecode compiled languages, to frameworks on top of languages and embedded languages, now Redmond wants to bring ANOTHER language to the table, titled ‘M’ (for Microsoft?).

Read the rest of this entry »


How to programmatically establish GPRS connection in .NET CF

08/10/2008

This is a simple way to establish GPRS connection in .NET CF using RAPI. Remember to check “Allow unsafe Code Blocks” option in project properties page!
Read the rest of this entry »


CG_Thuật toán Quay lơ (Weiler)

08/10/2008

Bài tập môn CG của tớ, 2 ngày code cái này thật là… !%^&$#@@#$%&

Những kinh nghiệm rút ra như sau:

1/ Trừ khi bị ép buộc, ko cài những thứ gì liên quan tới con trỏ bằng C++ nữa! Cái cảm giác 1 object nhưng có tới 3-4 con trỏ trong mấy cái list thật là… >”< Cuối cùng thì tớ cứ viết ẩu, new ào ào mà chả thèm delete…. hix… Cảm thấy có lỗi với thầy Phương, thầy Khiết, thầy Thư… nhiều wá… :”>

2/ Tớ đã ngồi cài lại cái hàng đợi bằng dslk đôi. Ngu thế là cùng!

3/ Post lên đây chơi ha!

http://cid-75f5081ae5375f06.skydrive.live.com/self.aspx/Shared%20source%20code/0612578|_Weiler.rar


Another trick with System.Net.Sockets.NetworkStream class

04/10/2008

Để hiểu dc cái trick này, người viết đã phải mất vài ngày… Hix…

Bình thường thì một ứng dụng mạng .NET sẽ có thread mạng được bọc trong vòng lặp như sau:

NetworkStream s = m_TcpClnt.GetStream();
while (s.DataAvailable)
{
//read mess
s.Read(aLen, 0, MSG_LEN);
// ……………
}

Ở đây ta dùng thuộc tính DataAvailable của lớp NetworkStream để xác định khi nào trong stream còn dữ liệu. Tuy nhiên vấn đề là nếu ta vừa đọc lên 1 lượng dữ liệu khá lớn (tầm 2KB) trong vòng while thì ngay sau đó, mặc dù phía server ko truyền gì nữa, nhưng DataAvaiible vẫn có giá trị TRUE, và vòng lặp tiếp tục, ta sẽ đọc được toàn là rác…

Để hạn chế điều này, ta có thể viết như sau:

while(true)

{

NetworkStream s = m_TcpClnt.GetStream();
if(s.Read(aLen, 0, MSG_LEN) > 0)
{
// ……………
}

}

Hàm Read() sẽ block đến khi nào có dữ liệu mới thoát, trả về số byte mà nó nhận được. Mặc dù không triệt tiêu 100% (nhất là khi truyền qua môi trường WiFi, GPRS v.v…) nhưng có lẽ đây cũng là cách hiệu quả.