Solved

windows program

Posted on 2004-04-28
15
248 Views
Last Modified: 2010-04-01
Hi all,
I got this program from expert Mokule.
how do i run this? I am new to c++\
I mean is it
File->new workspace->win32 application-> empty project
file -> new->c++ file

See, i need a simple program for my Single board computer on a communication box
the box , has several ports, one connected to a security camera
there is an Mpeg frame grabber harwdware within the box
another to microphon etc
I need t a simple program tht tells me. yes, the microphone is connected or not
                                                         yes, the camera is connected or not.
the device driver of the frame grabber does have some inheretnt detection, like it does tell me when a video signal is lost
i want to do a small implementation just to see if the ports are conneected or not


the program beloe does seem to have a purpose like tht...
could u tell me how to go abt running  this






Program
#include <windows.h>
#include <assert.h>

HANDLE hCom;
OVERLAPPED o;
BOOL fSuccess;
DWORD dwEvtMask;

hCom = CreateFile( "COM1",
    GENERIC_READ | GENERIC_WRITE,
    0,    // exclusive access
    NULL, // default security attributes
    OPEN_EXISTING,
    FILE_FLAG_OVERLAPPED,
    NULL
    );

if (hCom == INVALID_HANDLE_VALUE)
{
    // Handle the error.
    return;
}

// Set the event mask.

fSuccess = SetCommMask(hCom, EV_CTS | EV_DSR | EV_BREAK);


if (!fSuccess)
{
    // Handle the error.
    return;
}

// Create an event object for use in WaitCommEvent.

o.hEvent = CreateEvent(
    NULL,   // default security attributes
    FALSE,  // auto reset event
    FALSE,  // not signaled
    NULL    // no name
    );

assert(o.hEvent);

if (WaitCommEvent(hCom, &dwEvtMask, &o))
{
    if (dwEvtMask & EV_DSR)
    {
         // To do.
    }

    if (dwEvtMask & EV_CTS)
    {
         // To do.
    }

    if (dwEvtMask & EV_BREAK)
    {
         // To do.
    }
}
0
Comment
Question by:vikasgkutty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
15 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10938554
Copy the code above, create a new project using File - New - Win32 Console Application, choose a new name, and select Empty Project.

If you got it, open a new text file, past your code to it, select all, use <TAB> to indent all code, add

   void main()
   {

below the #include statements

and

  }

to the end.

Store the file to the new project directory using .cpp extension, e. g. <project_name>.cpp .

Right-click on the file and choose Insert.. to <project_name>.

Build project.

That it is.

Regards, Alex


0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10938667
A Win32 Application will work also, but you have  WinMain(...) function and not main().

If you want to have some output you need to create windows or write to output window of Visual Studio using OutputDebugString() function.

With a console application you may use cout and cin to get a simple input/output in the console window.

#include <iostream>

void main()
{
    cout << "Hello World" <<  endl << endl;

    cout << "Type any key to quit ==>" <<  endl;

    char c;
    cin >> c;
}

Regards, Alex
0
 

Author Comment

by:vikasgkutty
ID: 10938791
ok, than q....let me just try it out and hgte back to u
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vikasgkutty
ID: 10938846
why does it give me an error for endl, cout etc
i did inlcue iostream
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 10938873
Add line line...

    using namespace std;

... after the includes.
0
 

Author Comment

by:vikasgkutty
ID: 10938918
cool,
whats tht supposed to do
0
 

Author Comment

by:vikasgkutty
ID: 10938923
it worked
0
 

Author Comment

by:vikasgkutty
ID: 10938925
it worked
0
 

Author Comment

by:vikasgkutty
ID: 10938956
Ok,...
This program here seems to be doing some port detection
its checks DSR , CTS lines
i guess.. do u think this can be used to acheive what i need
i.e
IS the port disconnected or connected?
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10939088
Set a break-point  (hand-symbol) to line containing 'return' and start prog by F5 key.

    if (!fSuccess)
    {
        // Handle the error.
        return;  // SET HERE THE BREAK POINT
    }


If it stops at that point it didn't connect and you may post us the contents of variable fSuccess.

If it didn't stop, it connects and you may set break points below to see what happens.

Regards, Alex

0
 

Author Comment

by:vikasgkutty
ID: 10939231
was doing tht,
it tells me tht breakpoint is not positioned on correctlines, and it shifts the break point outside tht
 if (!fSuccess)
    {
        // Handle the error.
        return;  // SET HERE THE BREAK POINT
    }
o.hEvent = CreateEvent(
                  NULL,   // default security attributes
                  FALSE,  // auto reset event
                  FALSE,  // not signaled
                  NULL    // no name
                  );//SHIFTS it here

Vikas


0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 125 total points
ID: 10943377
That's an error of the Debugger. I suppose it's because of big macros in some windows header files what causes an error in counting header lines.

Simply try to position the break point some lines above or use the Debug Menu - it comes up when the Debugger is started -  to manually update the breakpoint's line number. You may also try to set the break point once the Debugger is running. I suppose that line numbers get correctly evaluated then.

Regards, Alex
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question