Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help! Last resort! Please Read...

Status
Not open for further replies.

ghs215215

Programmer
Nov 6, 2003
2
US
I was asked to take on a project for a local foodbank. The foodbank has a giant/huge wooden turkey that they set up for donations. There is a 2'x 1' door on the turkey that the donator lifts up to place food inside.

My task was to (on short notice) make the turkey "gobble gobble" when the door was lifted up. So I wrote a program in Visual Basic 6, which I am familiar with. But to come and fnd out that it will never work because the ActiveX Control MSCOMM32.OCX which controls the Serial ports is not included in the "Working Model Edition". So I found the file and installed it. When I went to use it, it said it is not licensed and regestered. I cannot find any way around it except switching to Visual C++ 6.0, because i have the full blown version )standard with the librarys.

I have not used C++ for years and I need help converting VB6 to C++ (if possible). Any help will be greatly appreciated.

Here is the code that I had for VB6:

'Declare the API call
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

'Declare the constants that go along with the sndPlaySound function
Const SND_ASYNC = &H1 'ASYNC allows us to play waves with the ability to interrupt
Const SND_LOOP = &H8 'LOOP causes to sound to be continuously replayed
Const SND_NODEFAULT = &H2 'NODEFAULT causes no sound to be played if the wav can't be found
Const SND_SYNC = &H0 'SYNC plays a wave file without returning control to the calling program until it's finished
Const SND_NOSTOP = &H10 'NOSTOP ensures that we don't stop another wave from playing
Const SND_MEMORY = &H4 'MEMORY plays a wave file stored in memory
Private Sub Form1_Load()
MSComm1.CommPort = 1
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvRing Then sndPlaySound App.Path & "\sound.wav", SND_SYNC Or SND_NODEFAULT
End Sub
 
On the door, there is a momentary switch. when the door is closed the switch is open, visa-versa.
 
Well, to play a wav file, you can use Win32's playsound() function:

bool result = PlaySound("C:\\SomeDirectory\\sound.wav", NULL, SND_FILENAME);

Just add 'WinMM.Lib' as an additional dependency in your project settings.

I'm not sure about the rest...I haven't done any COM port communications yet. But it would make sense to put it in a 'while' loop and query the state of the momentary switch, introducing a delay after PlaySound().
 
Oh yeah, and
Code:
#include <mmsystem.h>
in your .h or .cpp file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top