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)

How to configue OpenCV in Visual Studio – Reprice

It has been quite a while since last time I post a howto of configuring OpenCV in Visual Studio. The post got a lot of attention and comments. As the the configuring has become simpler, the post becomes a bit bulky and out-of-date. So right now I am considering to rewrite the howto with a much simpler version.

  • Open Visual Studio, add following path to
    Tools–>Options–>Projects–>VC++ Directories–>Include files

    C:\Program Files\OpenCV\cv\include
    C:\Program Files\OpenCV\otherlibs\highgui
    C:\Program Files\OpenCV\cxcore\include
    C:\Program Files\OpenCV\otherlibs\cvcam\include
  • Add following path to Tools–>Options–>Projects–>VC++ Directories–>Library files
    C:\Program Files\OpenCV\lib
  • When create a new project,
    add following to “Project–>Properties–>Linker->Input–>Additonal dependencies

    cv.lib highgui.lib cvaux.lib cxcore.lib

    NOTE there is no difference between debug or release configurations

  • Tested on OpenCV 1.0 with Visual Studio 2008

    Links
    Original blogspot link1 link2.
    Li Hao’s post.

    Tags: ,

    * Comments(2)

    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)

    Handle file drop in QT

    File drop is an easy-to-use feature for users, as users can directly drag-and-drop a file from file browser onto your application. People may think it is difficult to implement. But actually, it is rather easy. Here is a fast way to start.

    The main idea is to handle these two events, QDropEvent and QDragEnterEvent. The following shows how to handle them in your app.

    First, add the following code to the class declaration in a header file,

    protected:
        void dropEvent(QDropEvent *event);
        void dragEnterEvent(QDragEnterEvent *event);
    

    Then add the implementation to the cpp file,

    void CLASS::dragEnterEvent(QDragEnterEvent *event)
    {
      if (event && event->mimeData()) {
        const QMimeData* md = event->mimeData();
        if (md->hasUrls())
            event->acceptProposedAction();
      }
    }
    

    and

    void CLASS::dropEvent(QDropEvent *event)
    {
        const QMimeData *data = event->mimeData();
        if(data->hasUrls())
          foreach(QUrl url, data->urls()) {
            QFileInfo info(url.toLocalFile());
                if(info.exists() && info.isFile())
              ///// do something with url.tolocalFile()
          }
    }
    

    One more thing, add the following code in the constructor of the class to enable the widget to accept the events.

    setAcceptDrops(true);
    

    That’s all!

    Tags:

    Comments(0)

    Open terminal in Nautilus/Explorer/Finder and vice versa

    Nautilus, Explorer and Finder are GUI file browsers of Ubuntu, Windows, and Mac OS respectively. No matter under which system, it would be extremely convenient if users can open a terminal with path being the same as location of the file browsers or vice versa. Here I show the ways of doing such under each system.

    Ubuntu
    Open terminal in Nautilus:
    just install nautilus-open-terminal with your Synaptic Package Manager, then you can find a “open in terminal” item in your context menu of your Nautilus.

    Open Nautilus in terminal

    nautilus . 

    Windows
    Open cmd line in Explorer
    install cmdhere tool in the collections of powertoys provided by Microsoft

    Open Explorer in terminal

    start .

    Mac OS
    Open terminal in Finder
    Download a simple cdto … app here and drag it onto your Finder toolbar. Clicking it will open a terminal with the current path in Finder.

    Open Finder in terminal

    open .

    Tags: , ,

    Comments(0)

    Create socks proxy with ssh under Linux

    If you have a server supporting ssh, you can easily create a socks proxy with ssh under linux, using the following commnd

    $ssh -D portnumber username@ip-address-of-ssh-server
    

    Then you got a socks proxy, localhost:portnumber. Just enjoy it in your browser or somewhere else.

    Keep the terminal alive until u don’t need the proxy anymore.

    Tags:

    Comments(0)

    how to use cout, cin, cerr in QT

    Include

    #include <QTextStream>
    #include <stdio.h>
    

    Create these instances globally

    QTextStream cin(stdin, QIODevice::ReadOnly);
    QTextStream cout(stdout, QIODevice::WriteOnly);
    QTextStream cerr(stderr, QIODevice::WriteOnly);
    

    Then you can use

    cout<<QString("bla bla")<<endl
    

    as you wish.

    refer: http://lists.trolltech.com/qt4-preview-feedback/2005-03/thread00012-0.html

    Tags:

    Comments(0)

    How to use OpenCV in QT under ubuntu

    Install OpenCV with Synaptic Package Manager
    Add one line in QT project file (*.pro)

    LIBS += -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux

    Then, include OpenCV header file in your source code.
    Do whatever you like in your source file.
    Compile.

    Note: This post is incomplete so far and subject to change.

    Tags: , ,

    Comments(0)