Communicating between processes with Pipe

Instead of using a complicated Sendmessge between processes, there is another convenient way to communicate between processes. Pipe!

There is a good tutorial and implementation demo with C#. link

I just used the server client in my program. But for the client, I used a simple C++ implementation.

HANDLE h=NULL;
void send_message(char *msg)
{
	if (!h)
		{
			h=CreateFile(L"\\\\.\\pipe\\MyNamedPip",
			      GENERIC_READ | GENERIC_WRITE,
                  0,
                  NULL,
                  OPEN_EXISTING,
                  FILE_FLAG_OVERLAPPED,
				  NULL);
		}

	DWORD BytesWritten;
	WriteFile(h,msg,strlen(msg),&BytesWritten,NULL);
	FlushFileBuffers(h);
}

Tags: , ,

Comments(0)

Declare an array of object references in VC++.net

上了贼船, 只能当贼.
Following the weird syntax of VC++.net, here is how to declare an array of a dotnet object references.

static array<System::Threading::Mutex^>^ trackers_mut = gcnew array<System::Threading::Mutex^>(10);

or

array <String^>^ filenames={"aa", "bb"};

有点抓狂. 但的确是这么写的. C及其衍生物总是那么变化无穷.

Tags:

Comments(0)

Using Windows Media Player Control in Visual Studio

In Old times, I still remember how cool it is to add a media player in my Delphi Form. Now I need to do the same to VC++.net, so I searched and got these links. Although they are not VC++.net solution, they still help a lot.

With some codec (here), this way can enable your application play video of most popular formats. So give up the other version of using Direct X to play only AVI format video in dotnet application.

Here are the links (still updating)

How to add Windows Media Player Control to Design ToolBox

How to use Windows Media Player in code (C# Version)

Tags: , ,

Comments(0)

Using OpenCV in VC++.Net

Continuous updating…
Current testing version: OpenCV 1.0 (I do not recommend the latest 1.1pre1. I got strange error using it in VC.net). VC++.net 2008.

Set up a project in Visual Studio

  • Choose VC++ -> Windows Forms Application (stand for dotnet framework)
  • Add opencv directory and dependent library from this post.
  • Add include <cv.h> to try out.
  • Compile, you might find an error saying ” cannot compile under /clr:safe or /clr:pure …”
  • Then goto Project setting: Configuration properties -> general -> Common Language Runtime Support -> change to  (/clr)
  • Compile again, it should work.
  • Convert IplImage to VC++.net Bitmap

    System::Drawing::Bitmap ^disp = gcnew System::Drawing::Bitmap(img->width, img->height, img->widthStep, PixelFormat::Format24bppRgb, System::IntPtr::IntPtr( img->imageData) );

    Tags: ,

    Comments(0)