Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Subclassing crashing VB, as always.
  
User name:
Password:
Reply:
 

UserPost
HyperLamer
Posts: 1563/8210
I've never really seen anything like that. I think DirectX has a function you could do that with, but I dunno how to use it and Google is no help. I managed to make it play a WAV, and there's a frequency adjust function (raise or lower the pitch), so I tried making a WAV of a constant 8000hz tone, since the default frequency was 8000 it makes the math pretty damn easy. But when I did that the default frequency changed to like 22000. Plus, I'd prefer not using a WAV at all.
As for lag or excessive CPU usage, it's not a big deal, I'm only trying to play a tone for like half a second. (Making a phone dialer program. )
Cellar Dweller
Posts: 140/269
Originally posted by HyperHacker
BTW, if anyone knows how to play tones out of the sound card (given a specific frequency and length, being able to play multiple tones at once, and not pausing the program until it's done), I need to know.


I think that the Windows sound API offers some way to play a sound data buffer in the background and call back to the application when the sound data is about to run out. I could be wrong about this. I have not even looked at the Windows sound API in many years.

If that is the case, then I think that the best thing to do is create two or three sound buffers and synthesize the waveforms to a buffer that is not currently being played. Store the phase of the waveforms in the list of active tones so that there will be no click when a buffer starts playing.

Be sure not to write sound synthesis code in a language that does array bounds checking, automatic array resizing, or dynamic typing. Also, avoid floating point math if possible. Heed these warnings lest your program lag behind the sound card or excessively consume CPU cycles.
HyperLamer
Posts: 1555/8210
Hmm... I think that (while testing some multithreading experiments) I've discovered one of the most important rules of multithreading in VB: No two threads can reference the same function at any time. (Subclassing counts as multithreading, because a different thread calls the function.) For example, if your new thread calls a function, and at any time after that the original thread calls it, the program will crash. I'm not sure why this is (and it certainly limits functionality), but it seems to hold true throughout my experiments. Declare a function in a module somewhere and create a new thread. Have the new thread call this function, it should work fine. Now have the original thread call this function later, VB crashes. This doesn't seem to apply to variables (I managed to make one thread change the BG colour while the other changed the title, both in endless loops). The biggest problem I've found is that VB seems to crash whenever the second thread is terminated. (That, and the farking Data View window just popped up out of nowhere and appears every time I start VB now. )

BTW, if anyone knows how to play tones out of the sound card (given a specific frequency and length, being able to play multiple tones at once, and not pausing the program until it's done), I need to know.
Kyoufu Kawa
Posts: 677/2481
I prefer to use VBAccellerator's Subclassing and Timer Assistant for this shit. Subclassing without the crashes.

I use it in RS-Ball to prevent horizontal resizing.
HyperLamer
Posts: 1543/8210
Yeah, I tried that. I personally think it's a threading issue, or some such thing, but then I'd have to wonder how subclassing could even work without crashing.
neotransotaku
Posts: 1339/4016
the API isn't doing error checking and VB can't do much in terms of error checking for C code because the best it can do is to make sure your parameters pass the type checking for the function call. Whether the values are valid values to use in the API call is a different story.

So, why don't you call MouseMove with values you know should work in that if expression. If that works, then you know the values you are passing it that are bad, not the API function itself.
HyperLamer
Posts: 1541/8210
The point of your 1337 post being...?
neotransotaku
Posts: 1337/4016
you are working with the WindowsAPI and that is written in what language? C? with C, if it looks like data, it will use it. I'm in a project that uses a C++ DLL from a VB DLL. I can define the available C++ functions anyway I want in C++ and it will run. Whether it runs correctly is a different story.

In short, when it comes to running C stuff from other language, if it is in memory and in a valid area, anything goes.
HyperLamer
Posts: 1534/8210
If it were an invalid parameter, it would show an error message wouldn't it? Trying to use F8 didn't work; VB wouldn't respond to keypresses when it broke.
neotransotaku
Posts: 1329/4016
have you taken a look at what MouseMove accepts and doesn't accept? as a programmer, you have to assume that when you use API, the API is correct. Not unless you are 100% sure what you are giving it is valid. If that is the case, then this is where bug reports are welcomed by people who program the API.
Squash Monster
Posts: 384/677
Why would you uncomment them one at a time instead of using the step command (F8)?

And nope, I have no clue what's wrong with it.
HyperLamer
Posts: 1524/8210
Originally posted by neotransotaku
is there a better way to monitor how VB travels through that if expression? like...what VB statement in that if expression causes VB to crash?

Yes, I uncommented them one at a time, it's when it calls MouseMove that causes the crash.
dan
Posts: 165/782
Google it. There's a million half decent tutorials on the subject Ok, maybe a million is an exaggeration.
neotransotaku
Posts: 1328/4016
is there a better way to monitor how VB travels through that if expression? like...what VB statement in that if expression causes VB to crash?
HyperLamer
Posts: 1518/8210
I swear, Windoze's API was programmed by a team of retarded monkeys on crack. No, wait, that's an insult to crack-addicted retarded monkeys.

After subclassing the window procedure to trap 4th and 5th mouse buttons because VB doesn't for some dumb reason, I have this code:

If iMsg = &H200& Then
Form1.Form_MouseMove wParam, -1, lParam And 65535, lParam \ 65536
Else
Debug.Print Hex$(hWnd), Hex$(iMsg), Hex$(wParam), Hex$(lParam)
WindowProc = CallWindowProc(ProcOld, hWnd, iMsg, wParam, lParam)
End If


The code fires the MouseMove event when it gets a mouse message, otherwise it lets Windoze handle it. As soon as it tries to execute the MouseMove event, VB crashes without any sort of error message. Why is it doing this?
Acmlm's Board - I2 Archive - Programming - Subclassing crashing VB, as always.


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.011 seconds.