开发者

Strange behavior in Library API call (NET and C++)

I have a thirt pary API. It simply stream media to given ip-port(read media from a capture device).

When I use that API in a Windows Form Application, it works. But when i call this API in a Console or Windows Service, it does not give any error but does not work[ does not stream ]: It seems that it does not take stream data from device.

The only difference betwween is that One Applications is Windows Form Applicati开发者_如何转开发on, the other is not.. There is really no difference other than this.

What kind of dependency may cause such a thing? Any idea ?

PS: The API is written in C++. I use that API in NET(C++/CLI)

For Example:

// Works in Windows Form Application

System::Void startButton_Click(System::Object^  sender, System::EventArgs^  e) 
{

    MyAPI->Start();
}
System::Void stopButton_Click(System::Object^  sender, System::EventArgs^  e) 
{
    MyAPI->Stop();
}

but ....

// Not Work In Console or Windows Service

 MyAPI->Start();

 Console::WriteLine("Streaming started.Press enter to exit");
 Console::Read();

 MyAPI->Stop();

Console::WriteLine("Streaming stopped");


The third party API probably depends internally on Windows event dispatching, which a console app will not do (by default, I believe you can set up event dispatching within a console app).


In case of a UI-application, there's always a message queue. In a console application, the is not. The 3rd party software might post messages to the message queue that is not there in the console-application. Doing so might cause unpredictable program behaviour. Try calling GetMessage() from the win api before the communication is started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜