?
Solved

windows program

Posted on 2004-04-28
15
Medium Priority
?
249 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
Industry Leaders: 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 375 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

765 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