Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

windows program

Posted on 2004-04-28
15
Medium Priority
?
251 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

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!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

636 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