Solved

windows program

Posted on 2004-04-28
15
241 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
  • 7
  • 4
15 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
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
Comment Utility
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
Comment Utility
ok, than q....let me just try it out and hgte back to u
0
 

Author Comment

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

Expert Comment

by:rstaveley
Comment Utility
Add line line...

    using namespace std;

... after the includes.
0
 

Author Comment

by:vikasgkutty
Comment Utility
cool,
whats tht supposed to do
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:vikasgkutty
Comment Utility
it worked
0
 

Author Comment

by:vikasgkutty
Comment Utility
it worked
0
 

Author Comment

by:vikasgkutty
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now