|
Can you post the code for your ProjectList Serialize() method?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I am looking for some comments / suggestions on the subjects of CALLBACKs and multithreading..
I have a MFC application that uses audio data as a document.
After studding several waveIn samples here I have some understanding how to accomplish this.
The key is that the MFC main thread creates a new thread for processing.
The CALLBACK waveInProc function passes control to this new thread that waits for data to arrive.
My question - is CALLBACK really a glorified hardware interrupt?
Is creation of the new thread just nice or actually needed because WaitForSingleObject stops the thread in some kind wait loop?
But my main problem is getting the audio data “back” to the MFC.
WM_ messages are useless - won't go “cross thread”.
It seems that the clean way to accomplish this is to go multithreading.
Since my application is not doing anything until the data arrives - maybe I can skip this new thread creation and just wait for data to arrive.
I have looked at using templates and found the method too convoluted.
(Processing structures?)
Do I have any other options?
PS I have posted here to read wider audience and some of the article studied are quite old anyway.
Thanks for reading.
Cheers Vaclav
|
|
|
|
|
Vaclav_Sal wrote: The key is that the MFC main thread creates a new thread for processing.
I'm not sure what you mean here. An MFC app (process) starts with one thread, wrapped by the
CWinApp class.
Vaclav_Sal wrote: The CALLBACK waveInProc function passes control to this new thread that waits for data to arrive.
No. The system is capturing waveform data on another thread. On that thread your callback
function is called.
Vaclav_Sal wrote: My question - is CALLBACK really a glorified hardware interrupt?
No. A CALLBACK is a function/method in your code that is called by the system. This could occur
on any thread, depending on what the callback is being used for (this is always documented).
Vaclav_Sal wrote: WM_ messages are useless - won't go “cross thread”.
Not true. WM_ messages can be sent/posted across threads. There is a difference between sending
and posting - study the docs for SendMessage/PostMessage. Messages to a window on another thread
go to the message queue associated with the thread that the window was created on.
Vaclav_Sal wrote: It seems that the clean way to accomplish this is to go multithreading
The multimedia system does the multithreading for you. All you need to do is put the data
somewhere when you receive notification in your callback. If you are doing something with that
data in another thread during the recording, then you need to synchronize access to the data -
usng thread synchronization objects works best.
Vaclav_Sal wrote: I have looked at using templates and found the method too convoluted.
Using templates for what?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark, thanks for your input.
I think I'll will try PostThreadMessage to notify the main thread.
|
|
|
|
|
That will work too. This is from your waveInProc callback function?
I'm curious why you need to notify another thread of something...
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark,
I am making slow progress. I used PostThreadMessage from the "helper thread" with "target" of my app thread.
I tried to intercept the message using ON_THREAD_MESSAGE macro in Main Frame and it did not work.
Using PreTranslateMessage method in Main Frame works. Now I need to notify the document/view to process the data and I am stuck. I tried posting same message in MainFrame (posting to current thread/ queue) and it did not work. (Maybe this all should be done in the app class?)
I know how to retrieve current document - maybe I'll take that route next.
The whole madness is in my need / want to let MFC do the processing and as you pointed out the waveInProc CALLBACK is a trigger for the new thread to do the wait for single object.
Maybe I am missing the main point here - the waveInProc CALLBACK "fires" with WIM_DATA and SetEvent is passed to the "helper " thread?
I managed to copy the data to global variable and now I need to do the processing - basically FFT and then some graphical and numerical displays and statistical analysis. Please correct me if I am wrong but if the helper is waiting for the object how can I do all this graphical stuff in same thread? Does it make sense to go back to main thread with all the view updating going on?
Thanks a lot for all your help.
Vaclav
|
|
|
|
|
Ok, before I attempt to steer you the wrong direction, what does your waveInOpen() call look
like? Specifically, what open flag(s) are you passing?
I've been thinking CALLBACK_FUNCTION, but you are mentioning threads and events, so I want to
make sure I'm following
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hello everyone,
Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when talking with another team -- codepage -- at the same time.
I am more confused when I saw sometimes we need codepage parameter for wide character conversion, and sometimes we do not need for conversion. Here are two examples,
code page is used in WideCharToMultiByte when dealing with unciode character
int WideCharToMultiByte (
UINT CodePage,
DWORD dwFlags,
LPCWSTR lpWideCharStr,
int cchWideChar,
LPSTR lpMultiByteStr,
int cbMultiByte,
LPCSTR lpDefaultChar,
LPBOOL lpUsedDefaultChar );
code page is not used in wcstombs when dealing with unciode character
size_t wcstombs (
char* mbstr,
const wchar_t* wcstr,
size_t count );
My question is, what is codepage (seems my current understanding is not correct)? Does codepage have anything to do with multi-byte character or only have relationship with wide character? Could anyone explain the meaning and relationship between codepage, wide character and multi-byte character?
thanks in advance,
George
|
|
|
|
|
Code pages map character codes to character glyphs ("The actual shape (bit pattern, outline, and
so forth) of a character image").
Some info: Locales and Code Pages[^]
wcstombs() uses WideCharToMultiByte internally. The codepage wcstombs() uses is based on the CRT
locale settings (see link) which is why you don't have to pass a codepage code.
Mark
-- modified at 13:41 Thursday 3rd May, 2007
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks Mark,
The page is very helpful.
Two more questions,
1. In the article, I think codepage has the same meaning of encoding -- mapping table between character and numbers. Is that correct?
2. Differences between multi-byte and wide character? I think they are both characters which are represented by more than one bytes. Why on Windows they are distinguished?
regards,
George
|
|
|
|
|
George_George wrote: 1. In the article, I think codepage has the same meaning of encoding -- mapping table between character and numbers. Is that correct?
If by character, you mean the character we see, and by numbers you mean the character codes, then
yes.
George_George wrote: 2. Differences between multi-byte and wide character? I think they are both characters which are represented by more than one bytes. Why on Windows they are distinguished?
To different ways to encode characters. With unicode, all character codes are 2 bytes (although
I think Unicode can support longer codes, I forget). With MBCS character codes can be one or
more bytes.
Either way, the codes need to be mapped to a character glyph to present the character to the
user. That mapping is done using the code page.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks Mark!
Previously, I think multibyte character is a specific encoding (codepage). But after discussion with you, I think I am wrong. Multibyte character on Windows is a general term which is used for representing character which could be stored in more than one byte. And several encoding (codepage), like UTF-8, ANSI, ... could be called as multibyte character. Is my understanding correct?
If my understanding is correct, I am wondering what about wide character? Seems wide character on Windows is the same as UTF-16? i.e. wide character == UTF-16 encoding (or UTF-16 codepage).
regards,
George
|
|
|
|
|
I think we're still mixing encoding and codepages
The "encoding" would be the value and format of the byte(s) used to store a character code.
The "code page" is the the mapping of encoded character values to a drawing of the character.
An example - if you have a bunch of Chinese Unicode-encoded characters in an array. If you try
to render those characters to the screen using the ANSI codepage, you'll get a bunch of boxes
drawn, indicating there was no character glyph in the codepage matching the character code.
If you use a codepage that does contain the Chinese character glyphs, then the characters will be
drawn.
UTF-16 is a Unicode encoding. I believe it allows for two-byte or 4-byte character codes but
I personally have never used larger than 2-byte (wide) characters.
UTF-16 is a more specific format than what we refer to in our C++ code. The different flavors
of UTF-16 have different byte ordering and/or bit positions. This strict definition provides
for cross-platform portablitity - the byte order and layout will be the same on all machines -
it's up to the users of the character codes to translate them to a suitable format for the
system they are used on.
If you search Google on "UTF8" or "UTF16" you'll find lots of information on the specifics of
those Unicode encodings.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thank you very much Mark! Great answer!!
Let us come back to the original question -- multibyte character and wide character.
Previously, I think multibyte character is a specific encoding (codepage). But after discussion with you, I think I am wrong. Multibyte character on Windows is a general term which is used for representing character which could be stored in more than one byte. And several encoding (codepage), like UTF-8, ANSI, ... could be called as multibyte character. Is my understanding correct?
If my understanding is correct, I am wondering the differences between multi-byte and wide character? I think they are both characters which are represented by more than one bytes. Why on Windows they are distinguished?
i.e. I think wide character is a subset of multibyte character. But seems on Windows they are two different types of character.
regards,
George
|
|
|
|
|
On some client's computer the (.NET) XmlDocument.Save() fails with some weird internal error such as:
============== (.NET stacktrace)
Exception : System.IO.IOException
Message : Unknown error "-1".
Source : mscorlib
Help :
Stack :
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Xml.XmlDocument.Save(String filename)
===============
I have reported such a problem to microsoft and they just told me they need more information such as a mini dump.
how do I do one?
|
|
|
|
|
Without writing new code, you can run DrWatson. When the program has a crash, DrWatson can write it to a minidump.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|
|
ha ok...
but it doesn't show when I run my .NET program. And if I don't catch the exception it shows a .NET exception box, not DrWatson.
Beside, from my remote memories of DrWatosn, I don't know how to tell it to save anything
Could you give some more detailed tip please?
|
|
|
|
|
|
This may be trivial for most of you. I have been programming for about 20 years, now, I have a Computer Science degree, and I have never had any one define, for me, what a wrapper is. I am sure I have probably made them and used them without knowing that is what they are called. To me a wrapper is that little bit of paper I have to go through to get to a piece of gum. Can someone tell me what is meant, in the programming world, by the term wrapper?
|
|
|
|
|
To me, from an object-oriented point of view - there's the concept of Encapsulation[^].
A wrapper provides the "capsule" for encapsulation.
For example, a wrapper class provides a public interface to a hidden/private implementation.
My 1 cent.
Mark
p.s. I don't know if the article I linked to is good - I just know it saved me some typing
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
MFC can be compared to a Wrapper AROUND Win32 calls; it makes creating and managing UI (mostly) easier for the programmers.
Wrapper functions or classes are created to make API simpler to use.
|
|
|
|
|
huehue wrote: To me a wrapper is that little bit of paper I have to go through to get to a piece of gum
I think you've found your way.
More specifically (but informally), we usually talk about Wrappers only in OOP. For instance MFC builds objects (wrappers) around plain C API. Wrapper is a broad concept of OOP, you can find specialized applications of this concept (for instance) in Proxy , Facade , Adapter design patterns.
hope that helps
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
A wrapper is some code or object which simplifies or adapts the use of some service by isolating the user from the complexities/specifics of its interface; often providing a simpler or more portable interface. Conceptually it "wraps" around the old interface.
Steve
|
|
|
|
|
This helps, thanks guys...
|
|
|
|
|
I’m working in a big MFC application. I now have Several Forms to add into this application. The original developer says there is no reason to stick with MFC. So I need to convert this MFC application. I’m looking for websites and/or books on converting. Both the old and new application will need to be written in C++.
Any advice would help.
Thanks
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|