|
VOID Sleep(
DWORD dwMilliseconds
);
Parameters
dwMilliseconds
[in] Specifies the time, in milliseconds, for which to suspend execution. A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. A value of INFINITE causes an infinite delay.
Return Values
This function does not return a value.
|
|
|
|
|
I've written a video capture application which also captures Frames. I use SampleGrabber filter and CaptureBuilder.
when i connect filters using CaptureBuilder, SampleGrabber fails.
alternatively, when i connect without using CaptureBuilder(using
graph->connect (pins)), SampleGrabber works but there's time-delay in stream rendering.
If any one have worked on this already, pls help me.
Thanx in advance for ur guidence
Ramesh.D
|
|
|
|
|
Hi,
I was working on this and i had a problem too with
ISampleGrabber, Actually my function GetMediaType
was returning an error.
Can you explain me how can i perform the following..
1. Open the Camera and just take a shot from it
2. close the device..
Sameer
|
|
|
|
|
I too face the same problem when i use the GraphBuilder.
Instead I instanciated the filters, added to the Graph, and the connected their pins(pGraph->Connect(inPin, outPin)
now Sample grabber works fine.
But there's time delay rendering the video input to the screen
Ramesh.D
|
|
|
|
|
Hello
I'm trying to print a bitmap from the resources. The bitmap has more than 256 colours. The idea is that i transfered my program from winnt 4.0 to windows xp. On the windows nt machine the program works. On the windows xp machine the app works only for the local printer; when it comes for the network printers i get an empty page. Why is that ? Somebody pls help me ... The prog is compiled with visual c++ 6.0. Here is the code in the OnDraw function - the only code i added :
int x=0, y=0;
CRect rcClient; GetClientRect(&rcClient);
if(pDC->IsPrinting()){
x = pDC->GetDeviceCaps(HORZRES);
y = pDC->GetDeviceCaps(VERTRES);
}
else {
x=rcClient.Width();
y=rcClient.Height();
}
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP8);
CDC memDC;
memDC.CreateCompatibleDC(NULL);
BITMAP bm;
bmp.GetObject( sizeof(BITMAP), &bm );
CBitmap* pOldBitmap = memDC.SelectObject(&bmp);
pDC->StretchBlt(0,0,x,y, &memDC, 0,0, bm.bmWidth,bm.bmHeight, SRCCOPY);
P.S. I would appreciate almost any good advice. This printing thing is something i wasn't able to find in any book (i mean printing a bitmap). This is sort of my only hope.
|
|
|
|
|
I have had the same problem trying to print CBitmap objects. DIBs work better for printing. Here is a code sniplet that I used to print a logo in the upper right corner of a printer page. It loads the resource into a CBitmapToDIB object. You will have to modify this for you application.
...
CBitmapToDIB dib;
if(dib.Create(IDB_LOGO1))
{
LPBITMAPINFOHEADER lpHdr;
CSize sizeDisplay;
CSize sizeLogo;
lpHdr = dib.GetBitmapHeader();
sizeLogo.cx = lpHdr->biWidth;
sizeLogo.cy = lpHdr->biHeight;
sizeDisplay.cx = sizeLogo.cx * 2;
sizeDisplay.cy = sizeLogo.cy * 2;
StretchDIBits(pDC->m_hDC, rcHeader.right - sizeDisplay.cx, rcHeader.top,
sizeDisplay.cx, sizeDisplay.cy,
0, 0, sizeLogo.cx, sizeLogo.cy,
dib.GetBitmapBits(), dib.GetBitmapData(),
DIB_RGB_COLORS, SRCCOPY);
}
... I have added the code for CBitmapToDIB below. I can't take credit for this code, I think I got it out of the MSDN years ago. There may be some newer or better code in the current MSDN or on Code Project.
But the code below works...
#if !defined(_BITMAPTODIB_H__INCLUDED_)
#define _BITMAPTODIB_H__INCLUDED_
class CBitmapToDIB
{
public:
CBitmapToDIB();
~CBitmapToDIB();
BOOL Create(CBitmap *hBitmap, CDC *pDC, CPalette *pPal = NULL, int nBitsPerPixel = -1);
BOOL Create(LPCSTR lpResourceString);
BOOL Create(WORD nResourceID);
void Destroy();
const LPVOID GetBitmapBits();
const LPBITMAPINFO GetBitmapData();
const LPBITMAPINFOHEADER GetBitmapHeader();
BOOL WriteDIBToFile(LPCTSTR lpszFileName, CProgressCtrl *pProgressCntrl = NULL);
BOOL WriteDIBToFile(CFile *pFile, CProgressCtrl *pProgressCntrl = NULL);
private:
void InitBitmapInfoHeader(LPBITMAPINFOHEADER pHdr, int nBitsPerPixel);
static WORD PaletteSize(LPBITMAPINFOHEADER pHdr);
static WORD DibNumColors(LPBITMAPINFOHEADER pHdr);
private:
HANDLE m_hDIB;
BITMAP m_Bitmap;
LPBITMAPINFO m_lpbmInfo;
LPBITMAPINFOHEADER m_lpbmInfoHdr;
LPBYTE m_lpBits;
DWORD m_dwDIBSize;
};
#endif //_BITMAPTODIB_H__INCLUDED_
#include "stdafx.h"
#include "BitmapToDIB.h"
#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
CBitmapToDIB::CBitmapToDIB()
{
m_hDIB = NULL;
Destroy();
}
CBitmapToDIB::~CBitmapToDIB()
{
Destroy();
}
void CBitmapToDIB::Destroy()
{
if(m_hDIB)
delete [] m_hDIB;
m_hDIB = NULL;
m_lpBits = NULL;
m_lpbmInfo = NULL;
m_lpbmInfoHdr = NULL;
m_dwDIBSize = 0;
}
void CBitmapToDIB::InitBitmapInfoHeader(LPBITMAPINFOHEADER pHdr, int nBitsPerPixel)
{
int nBPP;
memset(pHdr, 0, sizeof(BITMAPINFOHEADER));
pHdr->biSize = sizeof(BITMAPINFOHEADER);
pHdr->biWidth = m_Bitmap.bmWidth;
pHdr->biHeight = m_Bitmap.bmHeight;
pHdr->biPlanes = 1;
if ((nBitsPerPixel == 1) || (nBitsPerPixel == 4) ||
(nBitsPerPixel == 8) || (nBitsPerPixel == 24))
{
nBPP = nBitsPerPixel;
}
else
{
nBPP = m_Bitmap.bmPlanes * m_Bitmap.bmBitsPixel;
}
if(nBPP <= 1)
nBPP = 1;
else
if(nBPP <= 4)
nBPP = 4;
else
if(nBPP <= 8)
nBPP = 8;
else
nBPP = 24;
pHdr->biBitCount = (unsigned short)nBPP;
pHdr->biSizeImage = WIDTHBYTES(m_Bitmap.bmWidth * nBPP) *
m_Bitmap.bmHeight;
}
const LPVOID CBitmapToDIB::GetBitmapBits()
{
return LPVOID(m_lpBits);
}
const LPBITMAPINFO CBitmapToDIB::GetBitmapData()
{
return m_lpbmInfo;
}
const LPBITMAPINFOHEADER CBitmapToDIB::GetBitmapHeader()
{
return m_lpbmInfoHdr;
}
BOOL CBitmapToDIB::Create(CBitmap *hBitmap, CDC *pDC, CPalette *pPal, int nBitsPerPixel)
{
CDC dc;
BITMAPINFOHEADER tempHdr;
ASSERT(hBitmap);
if(!hBitmap)
return FALSE;
if(!hBitmap->GetBitmap(&m_Bitmap))
return FALSE;
Destroy();
InitBitmapInfoHeader(&tempHdr, nBitsPerPixel);
m_dwDIBSize = sizeof(BITMAPINFOHEADER) + PaletteSize(&tempHdr) + tempHdr.biSizeImage;
m_hDIB = (HANDLE)new char[m_dwDIBSize];
if(!m_hDIB)
return FALSE;
m_lpbmInfo = (LPBITMAPINFO)m_hDIB;
m_lpbmInfoHdr = &m_lpbmInfo->bmiHeader;
*m_lpbmInfoHdr = tempHdr;
m_lpBits = (LPBYTE)m_hDIB + (WORD)m_lpbmInfoHdr->biSize + PaletteSize(m_lpbmInfoHdr);
if(!dc.CreateCompatibleDC(pDC))
return FALSE;
if(pPal)
{
dc.SelectPalette(pPal, FALSE);
dc.RealizePalette();
}
if(!::GetDIBits(dc.m_hDC, HBITMAP(*hBitmap), 0, m_Bitmap.bmHeight, m_lpBits,
m_lpbmInfo, DIB_RGB_COLORS))
{
return FALSE;
}
return TRUE;
}
BOOL CBitmapToDIB::Create(WORD nResourceID)
{
return Create(MAKEINTRESOURCE(nResourceID));
}
BOOL CBitmapToDIB::Create(LPCSTR lpResourceString)
{
HRSRC hRsrc;
HGLOBAL hTemp;
LPSTR lpRes;
HINSTANCE hInstance = AfxGetInstanceHandle();
ASSERT(hInstance && lpResourceString);
if(!hInstance || !lpResourceString)
return FALSE;
hRsrc = FindResource(hInstance, lpResourceString, RT_BITMAP);
if(hRsrc)
{
Destroy();
hTemp = LoadResource(hInstance, hRsrc);
m_dwDIBSize = SizeofResource(hInstance, hRsrc);
lpRes = (LPSTR)LockResource(hTemp);
m_hDIB = (HANDLE)new char[m_dwDIBSize];
if(!m_hDIB)
return FALSE;
memcpy(m_hDIB, lpRes, m_dwDIBSize);
UnlockResource(hTemp);
FreeResource(hTemp);
m_lpbmInfo = (LPBITMAPINFO)m_hDIB;
m_lpbmInfoHdr = &m_lpbmInfo->bmiHeader;
m_lpBits = (LPBYTE)m_hDIB + (WORD)m_lpbmInfoHdr->biSize + PaletteSize(m_lpbmInfoHdr);
return TRUE;
}
return FALSE;
}
WORD CBitmapToDIB::PaletteSize(LPBITMAPINFOHEADER pHdr)
{
WORD NumColors;
NumColors = DibNumColors(pHdr);
if (pHdr->biSize == sizeof(BITMAPCOREHEADER))
return (WORD)(NumColors * sizeof(RGBTRIPLE));
else
return (WORD)(NumColors * sizeof(RGBQUAD));
}
WORD CBitmapToDIB::DibNumColors(LPBITMAPINFOHEADER pHdr)
{
int bits;
LPBITMAPINFOHEADER lpbi;
LPBITMAPCOREHEADER lpbc;
lpbi = (LPBITMAPINFOHEADER)pHdr;
lpbc = (LPBITMAPCOREHEADER)pHdr;
if(lpbi->biSize != sizeof(BITMAPCOREHEADER))
{
if(lpbi->biClrUsed != 0)
return (WORD)lpbi->biClrUsed;
bits = lpbi->biBitCount;
}
else
bits = lpbc->bcBitCount;
switch(bits)
{
case 1:
return 2;
case 4:
return 16;
case 8:
return 256;
default:
return 0;
}
}
BOOL CBitmapToDIB::WriteDIBToFile(LPCTSTR lpszFileName, CProgressCtrl *pProgressCntrl)
{
CString s;
if(!m_hDIB)
return FALSE;
try
{
CFileStatus rStatus;
if(CFile::GetStatus(lpszFileName, rStatus))
{
s.Format("File \"%s\" already exits. Overwrite?", lpszFileName);
if(AfxMessageBox(s, MB_OKCANCEL) == IDCANCEL)
return FALSE;
}
CFile file(lpszFileName, CFile::modeCreate | CFile::modeWrite);
return WriteDIBToFile(&file, pProgressCntrl);
}
catch(...)
{
s.Format("ERROR: Could not create BMP file \"%s\".", lpszFileName);
AfxMessageBox(s);
}
return FALSE;
}
BOOL CBitmapToDIB::WriteDIBToFile(CFile *pFile, CProgressCtrl *pProgressCntrl)
{
BITMAPFILEHEADER bfh;
DWORD dwFileSize;
ASSERT(m_hDIB && pFile);
if(!m_hDIB || !pFile)
return FALSE;
dwFileSize = sizeof(BITMAPFILEHEADER) + m_dwDIBSize;
bfh.bfType = 0x4d42;
bfh.bfSize = dwFileSize;
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = (m_lpBits - (LPBYTE)m_hDIB) + sizeof(BITMAPFILEHEADER);
try
{
if(pProgressCntrl)
pProgressCntrl->SetRange(0, 100);
pFile->Write(&bfh, sizeof(BITMAPFILEHEADER));
if(pProgressCntrl)
pProgressCntrl->SetPos(50);
pFile->Write(m_hDIB, m_dwDIBSize);
if(pProgressCntrl)
pProgressCntrl->SetPos(100);
return TRUE;
}
catch(...)
{
CString s;
s.Format("ERROR: Problem writing to BMP file \"%s\".", pFile->GetFilePath);
AfxMessageBox(s);
}
return FALSE;
} I hope this helps...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Hi,
I have an IP address in a CString (actually a char[])
how can i check whether the syntax is correct
Ne snipplets???
Thanx
Sameer
|
|
|
|
|
Sample function for verifing that the address has format like:
XXX.XXX.XXX.XXX
where XXX is a number between 0 and 255
bool CDummyDlg::checkIP(char *ip)
{char* tmpIP = ip;
char* tmpNR = new char[4];
bool OK = true;
memset(tmpNR,0,4);
int len = 0, groups = 0;
do
{if (*tmpIP >= '0' && *tmpIP <= '9')
if(len < 4)
tmpNR[len++] = *tmpIP;
else
OK = false;
else if('.' == *tmpIP || 0 == *tmpIP)
{if (atoi(tmpNR) > 255)
OK=false;
memset(tmpNR,0,4);
len = 0;
groups++;
}
else
OK = false;
}
while(*tmpIP++ && OK);
delete tmpNR;
return OK && (4 == groups);
}
I inserted a lot of comments, hoping it would be easier to read.
/moliate
Two o'clock and walking through familiar London - Or what was familiar London before the cursor deleted certain certainties -
I watch a suit and tie man giving suck to the Psion Organizer lodged in his breast pocket
its serial interface like a cool mouth hunting his chest for sustenance, familiar feeling, and I'm watching my breath steam in the air.
Neil Gaiman - Cold Colours
|
|
|
|
|
Hi,
I have an object of my class CSomeClass and this
object is global.
Now i have multiple threads running in my
application and they access this global object.
How do i make it thread safe.. like does it require
some critical section code or mutex etc..
Thanx in advance
Sameer
|
|
|
|
|
Add a CRITICAL_SECTION member variable to your object, initialize/release it at construction/destruction time and use it in every method of CSomeClass to serialize access to the objec from multile threads. This post of mine shows a convenient way to add CRITICAL_SECTION protection to a method with minimum effort.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I am not able to open yr post.. the page shows
no messages..
How do i see it???
Sameer
|
|
|
|
|
It's weird, I can see the page without problems... Try copying and pasting this URL to your browser:
http:
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanx..
but when do you call DeleteCriticalSection from yr
class.. isn't it necessary??
Sameer
|
|
|
|
|
Hi,
Can you show me a macro for this..
EnterCriticalSection(&cs);
myvariable->myfunc("kfsdjhkjsgdhkdg"); // string should be passed in macro
LeaveCriticalSection(&cs);
its like i want
LOG(X)
|
|
|
|
|
Can you show me a macro for this..
I could, but I'm afraid this would deprive you of the fun of figuring it out yourself.
Also, I don't think a macro is a good solution where alternatives (like an inline function) exist.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
If you want the class to be thread safe the critical section object should be a member of the class.
class CMySafeClass
{
...
CCriticalSection m_csObj;
...
} For methods that must be thread safe do this:
void CMySafeClass::Method1()
{
m_csObj.Lock();
m_csObj.Unlock();
} Hope this helps...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
i would like to know how to use this function
i tried to do simultaniasly read/write from COM but it didnt work
thanks.
|
|
|
|
|
Hi.
I am studying networking programming from Network Programming For Microsoft Windows, Second Edition by Anthony Jones and Jim Ohlund. I am just about ready to start on a new product that will be my first real Winsock program. I want to design and implement a simple message program (chat) that work over the IP protocol and TCP protocol.
I have the basic program core design in my mind. However, I am stuck with one problem and it is a problem that even Jones and Ohlund implied could be difficult to overcome for inexperience network programmers.
How do you predetermine the size of the data you receive?
Winsock has two basic functions for receiving data: revc (IPv4 or Winsock 1.1+) and WSARecv (IPv6 or Winsock 2). WSARecv is a powerful tool for *predetermined* data size. You can send multiple packages at one time, but the data size must be predetermined (i.e. 10k, 20k, and finally 30k). I will probably use revc since it is more flexible. Even with recv, however, you must give a specific size (byte) to read. Jones and Ohlund recommend sends the size of the data in the first four byte of the data stream. However, what if the user wants to send something that is larger than what a bour byte char variable can hold?
Please post any possible solutions.
Thanks,
Kuphryn
|
|
|
|
|
You can use as many bytes as you please to store the size. Consider using 8 bytes. If your platform doesn't support 8 byte integers, you can easily split it up in two parts where, say, the first four bytes tell how many full 4.2 GByte you have, and the second four bytes are the remainder. You could even send a custom header in all your transmissions to tell how many bytes hold up the size information. This way you will never run out of space. (Read, 640 kByte RAM is more than anyone will ever need )
|
|
|
|
|
Thanks.
Can you give me an example?
Let say I want to sent this message:
"Please give an example of how you would receive this message."
// send(socket, &message, sizeof(message), 0);
Kuphryn
|
|
|
|
|
... and to receive the message you do:
const int MAX_BUFF = 1024;
char buffer[MAX_BUFF];
recv(theSocket,&buffer, MAX_BUFF, MSG_OOB);
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Hi,
I think that highly depends on your protocol.
I was collecting some ideas about networking and Gnutella protocol (a P2P filesharing application). Gnutella is interesting here, because it uses line buffered data stream (e.g. HTTP handshaking) and also block buffered data (e.g. binary Gnutella protocol). The article can be found at: Programming a Gnutella Client, part II: network core
Let me know if it helps, I'm learning...
|
|
|
|
|
Well, I don't think it was the right answer
But, I just wanted to know how it worked... I'm still preparing how I will build my chat program!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Rickard Andersson wrote:
I'm still preparing how I will build my chat program
Have fun!
I'm on irc.p2pchat.org, if you wanna test my chat application.
|
|
|
|
|
Hi.
Okay. Basically, the program will be a client and a server. If it is connected to any other client/server, than the connect feature will be disabled.
As for the message, I plan to send and receive message and and forth. As for I/O mode and I/O model, I will use the simple WSAAsynSelect (non-blocking) model since it uses the Windows (MFC) messaging system.
Kuphryn
|
|
|
|
|