Link to home
Start Free TrialLog in
Avatar of vikasgkutty
vikasgkutty

asked on

windows program

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.
    }
}
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

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


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
Avatar of vikasgkutty
vikasgkutty

ASKER

ok, than q....let me just try it out and hgte back to u
why does it give me an error for endl, cout etc
i did inlcue iostream
Add line line...

    using namespace std;

... after the includes.
cool,
whats tht supposed to do
it worked
it worked
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?
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

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


ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial