|
Cedric Moonen wrote: sz is local to your function and will be destroyed when the function terminates.
Thank you Cédric Moonen
So , if I want to use SendMessage(PostMessage) to send some more information than WPARAM and LPRAM, I should use new operator to allocate memory on the heap, and after GetMessage returned use delete to free memory?
|
|
|
|
|
Yes, in that case it is safe (even if it is not beautifull ).
|
|
|
|
|
not beautiful?
Is there some beautiful ways to send large objects between threads? How about Memory-mapped files? I think it is not beautiful too. Because after you copy some information in the memory-mapped file, you still need to tell the other thread to retrieve the information.
Thank you!
|
|
|
|
|
When I said not beautifull, it is mainly because in that case your second thread will need a message loop so it is not applicable in all cases. If you have already a message loop in your second thread then it is fine.
There are, I think, better solutions but it all depends of what you want to achieve. What I do in general is having a class ta wraps the threading functionality (have a member function that will be called from the thread) and then if I need to 'exchange' information, I'll do that through class members and I use events to notify the other thread and eventually critical sections to protect the access to the shared resources.
|
|
|
|
|
Cedric Moonen wrote: If you have already a message loop in your second thread then it is fine.
Yes ,one of the thread is a window thread, and the other is a worker thread, after the worker thread finishes it's working, it will Send(Post) a message with a large block of memory to the window thread.
Thank you Cédric Moonen
|
|
|
|
|
Roughly speaking, usually processes need some technique to exchange data, while threads, by nature, already share data. What I mean is that you just don't need to pass messages to you thread but a bit refactoring to your design.
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.
[my articles]
|
|
|
|
|
Thank you!
I'll think twice before coding.
A Chinese VC++ programmer
|
|
|
|
|
zengkun100 wrote: A Chinese VC++ programmer
Greetings to China.
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.
[my articles]
|
|
|
|
|
This isnt safe, a better word for it is dangerous. You better work with integer/enum values to singalize the state (for instance String IDs) or a global object which stores the information.
Greetings from Germany
|
|
|
|
|
To achieve 1 to 1 voice communication over LAN and record the voice for storing, i think of doing:
1) use winsock to establish client server connection
2) use DirectSound api:
-at client(A) side, capture sound in buffer
-modify the sound quality
-compress the sound to mp3 or wma file using ACM and store it
beside storing, after compression i send the buffer to server(B) side and playback it so that A talk to B and B can hear it.
-and B also going above procedure to A.
-Full-duplex used allow simultaneous capture and playback.-
Question:
1) I think of using DirectShow api also but how i know my pc hv it or not? I just see DirectSound.
2) Is my step stated will work to allow voice communication over LAN and store the voice? Please point out what i miss or how should it going.
3) I see the RTC(real-time communication) api also and seem like more good, should it be better choice? Is it support the recording also?
4) I should build it as win32 application?
If out there hv any source code sample with no additional feature just basic 1 to 1 voice communication over LAN and can record voice for storing pls post up here. I want it for understanding purpose. Thnks.
modified on Monday, January 14, 2008 12:55:16 AM
|
|
|
|
|
Member 4542272 wrote: 1) I think of using DirectShow api also but how i know my pc hv it or not? I just see DirectSound.
You shouldn't need DirectShow. DirectSound would be sufficient.
DirectSound (and DirectShow) are part of DirectX, which comes with
Windows XP+ and is installable on previous Windows versions.
Member 4542272 wrote: 2) Is my step stated will work to allow voice communication over LAN and store the voice? Please point out what i miss or how should it going.
Yes it will work. MP3 is not a good format for real-time voice
communication but using ACM there's a couple codecs included with
Windows that work fine.
Member 4542272 wrote: 3) I see the RTC(real-time communication) api also and seem like more good, should it be better choice? Is it support the recording also?
RTC is a protocol. It can be used for the networking portion but
you'll need to handle capturing, compressing, uncompressing, and
rendering the audio samples.
Member 4542272 wrote: 4) I should build it as win32 application?
If you want your app to run on Windows, then yes, that's a good choice.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
how can I Returns a pointer to the start of the given scanline in the bitmap’s data-bits in BYTE *
Trioum
|
|
|
|
|
Can you more specific?
Are you reading from file?
|
|
|
|
|
yes I am reading from the file filename.bmp
Trioum
|
|
|
|
|
So you can just move the file pointer to there.
The starting of image data is specified in the BITMAPFILEHEADER's bfOffBits member.
You can use Seek API if you are using CFile (MFC), or use SetFilePointer if you are using SDK.
|
|
|
|
|
I tried but failed
can you send me the pieace of code in sdk please please
Trioum
|
|
|
|
|
And what was your code?
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.
[my articles]
|
|
|
|
|
If you are using CBitmap to load your bitmap in MFC, you can get the whole bitmap pixel array using GetBitmapBits in to your own byte* buffer. To access any particular scanline, you can use the formula of X*B+Y*W*B, X is your x coordinate, Y is your Y coordinate, W is your image width (you can obtain this from CBitmap) and B is your bitdepth of the image in bytes.
|
|
|
|
|
I still could not solve th problem.I am not using MFC , only sdk.
what I am doing i am copying the "myfilename.bmp" image buffer
to some other buffer. i store a pointer to the starting address of the pixel bits in
BYTE * m_pImage;
Now I want to get scanline buffer up to the bitmap height-1.
so I still confused how to get scanline up to bitmap height-1.
Trioum
|
|
|
|
|
Hi All,,
I am making the Windows Service with the help VC++. I want to perform the some tasks like capture desktop screen from the service.For that I have writen below code which gives unwanted result.
<br />
<br />
void SendCapturedScreen()<br />
{<br />
FILE *f;<br />
f = fopen("E:\\CaptureLog.txt","w");<br />
char *str = (char *)malloc(2000);<br />
<br />
RECT rect;<br />
<br />
rect.left = GetSystemMetrics(SM_XVIRTUALSCREEN);<br />
rect.top = GetSystemMetrics(SM_YVIRTUALSCREEN);<br />
rect.right = rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN);<br />
rect.bottom = rect.top + GetSystemMetrics(SM_CYVIRTUALSCREEN);<br />
<br />
m_hrootdc = ::GetDC(NULL);<br />
m_hmemdc = CreateCompatibleDC(m_hrootdc);<br />
<br />
int iWidth = rect.right - rect.left;<br />
int iHeight = rect.bottom - rect.top;<br />
<br />
HBITMAP new_Bitmap = CreateCompatibleBitmap(m_hrootdc,iWidth,iHeight);<br />
HBITMAP temp_Bitmap = (HBITMAP)SelectObject(m_hmemdc,new_Bitmap);<br />
if(temp_Bitmap == NULL)<br />
{<br />
sprintf(str,("Failed to get HBITMAP from SelectObject"));<br />
fwrite(str,strlen(str),1,f);<br />
}<br />
<br />
BOOL blitok = BitBlt(<br />
m_hmemdc, <br />
0,<br />
0,<br />
rect.right - rect.left,<br />
rect.bottom - rect.top,<br />
m_hrootdc,<br />
rect.left, rect.top,<br />
SRCCOPY);<br />
<br />
int err = GetLastError();<br />
<br />
if(blitok)<br />
{<br />
sprintf(str,("\nBitBlt Successed\nError Code:%d"),err);<br />
fwrite(str,strlen(str),1,f);<br />
}<br />
else<br />
{<br />
sprintf(str,("\nBitBlt Failed\nError Code:%d"),err);<br />
fwrite(str,strlen(str),1,f);<br />
}<br />
<br />
Here what happens I dont get the BitBlt function's success. It fails and the GetLastError() function returns the code no 6 means invalid handle.So I want to ask you form the service I can not perform this operation. And I also check that both handles are not null.
Plz give any suggesion you have.
Thanks in Advance.
Ashish Bhatt,
System Developer,
Avinashi System Pvt. Ltd.
|
|
|
|
|
See does this code helpful
HDC m_hdcMem,hdc;
HBITMAP m_Bitmap,m_OldBitmap,hMainBmp;
hdc=GetDesktopWindow()->GetDC()->m_hDC;
m_Bitmap = CreateCompatibleBitmap(hdc,800,600);
m_OldBitmap=(HBITMAP) SelectObject(m_hdcMem, m_Bitmap);
BitBlt(m_hdcMem, 0,0,800,600, hdc,0,0,SRCCOPY);
hMainBmp =(HBITMAP) SelectObject(m_hdcMem, m_OldBitmap);
CImage m_Image;
m_Image.Attach(hMainBmp);
m_Image.Save("c:\\test.bmp");
m_Image.Destroy();
DeleteDC(m_hdcMem);
DeleteObject(hMainBmp );
DeleteObject(m_OldBitmap);
|
|
|
|
|
Thank You very much for reply.
First of all I can not execute below line of code in my application as shown ,it gives errors.
<br />
hdc=GetDesktopWindow()->GetDC()->m_hDC;<br />
And I also want to tell you that when I use m_hrootdc variable in the place of m_hmemdc in the function BitBlt() (Look into code which I posted before) then it does not show error but also it does not show bitmap on the screen.
Is these all about service which does not allow the UI interface or anything else.
Any more Ideas??
Thanks.
Ashish Bhatt,
System Developer,
Avinashi System Pvt. Ltd.
|
|
|
|
|
I have just tried your code in a normal application and it is working.
I am not familar with service.
But at the least can you find out which handle is invalid?
I think using BitBlt with
BOOL blitok = BitBlt( m_hmemdc, 0, 0, 100, 100, 0, 0, 0, WHITENESS ); // Check m_hmemdc
and
BOOL blitok = BitBlt( m_hrootdc, 0, 0, 100, 100, 0, 0, 0, WHITENESS ); // Check m_hrootdc
will helpful.
|
|
|
|
|
Thanks for Reply.
As you told to check both handles, I did the same and also got both handles right. In both cases it did not show invalid handle.
But I checked other thing that I tried to display some pixels using SetPixel() function but I did not get success.So ,finaly I conclude that service does not allow the interaction with desktop.
So I tried to make it able to interact with desktop from service property but itr still gives that error that handle is not valid. Do you know how can I interact with desktop through service?
Do you have any other suggetion??
Thanks.
Ashish Bhatt,
System Developer,
Avinashi System Pvt. Ltd.
|
|
|
|
|
ashishbhatt wrote: As you told to check both handles, I did the same and also got both handles right. In both cases it did not show invalid handle.
ashishbhatt wrote: But I checked other thing that I tried to display some pixels using SetPixel() function but I did not get success.
I got confused, because you can call BitBlt with WHITENESS with success.
|
|
|
|
|