|
How do i read JPEG ,GIF files to get the following info ...
1.Image Width
2.Image Height
3.Monochromw or color
4.Frame Rate ( for Gif)
Can some one give the code along with the Header structure of JPEG,GIFF
|
|
|
|
|
Take a look at CXImage - http://www.codeproject.com/bitmap/cximage.asp
Dave
|
|
|
|
|
Hi,
In a dialog-based application, i have a a worker
thread which read 256k data from Cdrom at one times (step).
But it failed with memory leak. Would you please
provide me a safe thread method to be used for my problem?
I see many example code of the "thread", but i don't know
which one is best for my problem.
Thanks in advance!
chen
|
|
|
|
|
If you're using AfxBeginThread then it's possible to have the returned CWinThread* as memory leak.
rechi
|
|
|
|
|
Thanks!
but how to solve this problem (i really used AfxBeginThread function)
and there is 256K data needed read from CD and save it to a file for
each iteration step.
chen
|
|
|
|
|
chen wrote:
there is 256K data needed read from CD and save it to a file
I don't know if this is the problem, it might work fine.
Save the CWinThread* returned by AfxBeginThread and delete it after the thread terminates.
rechi
|
|
|
|
|
The following is the part of the code, would you please try to
find where is my mistake?
class CEfmraDlg : public CResizableDialog
{
public:
CEfmraDlg(CWnd* pParent = NULL);
struct SToto
{
BOOL m_bToto;
};
static UINT StartThreadEfmRead (LPVOID param);
...........
bool m_bStop;
}
void CEfmraDlg::OnEfmRead()
{
m_bStop = FALSE;
SToto stToto;
stToto.m_bToto = TRUE;
AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this);
}
UINT CEfmraDlg::StartThreadEfmRead (LPVOID param)
{
char buff1[100];
CEfmraDlg* ts = (CEfmraDlg*)param;
if(ts->m_scsi.EFM_open(newSparam) == 0)
{
FILE *fp;
if( NULL == (fp = fopen("cd.txt", "wb"))){
ts->m_ListBox.AddString("Open cd.txt error");
}
ts->m_ListBox.AddString("Read CD begin ...");
int count = 0;
for(;
{
count++; //256k
if(ts->m_bStop)
{
ts->m_ListBox.AddString("Read EFM data aborted.");
ExitThread(0);
break;
}
if(ts->m_scsi.EFM_read(fp))
{
ts->m_ListBox.AddString("Read Error!");
ExitThread(0);
break;
}
memset(buff1, 0, 100);
sprintf(buff1,"CD Reading - Count: %d Bytes: %d", count, count*256*1024);
ts->m_diff = buff1;
ts->ShowText();
}
ts->m_scsi.EFM_close();
fclose(fp);
AfxEndThread (0);
return 0;
}
return 1;
}
chen
|
|
|
|
|
Replace ExitThread(0) with AfxEndThread(0) . Don't mix up these calls when you're using MFC.
When you're exiting the thread because of some read error or abort you have to call fclose(fp) . This could be your memory leak, with the greatest probability.
Use CWinThread *pThread = AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this) . If your program ends before the thread exits, then you must delete pThread.
rechi
|
|
|
|
|
I have tried using AfxEndThread(0), the result is same. In addition, when quit/abort from the thread the fclose(fp) really
called at the end of the UINT CEfmraDlg::StartThreadEfmRead (LPVOID param).
I will try to remove the
struct SToto
{
BOOL m_bToto;
};
and using CWinThread *pThread = AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this).
and delete the pThread try again.
chen
|
|
|
|
|
When i using using CWinThread *pThread = AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this).
How to delete the pThread and transfer the varibles?
chen
|
|
|
|
|
chen wrote:
In addition, when quit/abort from the thread the fclose(fp) really
called at the end of the UINT CEfmraDlg::StartThreadEfmRead (LPVOID param)
Be careful, when you call AfxEndThread(0) , the thread is killed on the spot! The call you are talking about will not be executed; put fclose(fp) before any AfxEndThread(0) call.
chen wrote:
How to delete the pThread and transfer the varibles?
You don't have to transfer any variable, judging by what i saw in your code. To delete pThread, try this:
try {
if (pThread->ExitInstance())
delete pThread;
}
catch(...)
{
TRACE("never mind\n");
}
Not the best option but it's easy to write
rechi
|
|
|
|
|
Would you like re-write above code onece again by using your
method?
chen
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) Gee, you really are persistent
Let's do it:
class CEfmraDlg : public CResizableDialog
{
CWinThread *pThread;
public:
CEfmraDlg(CWnd* pParent = NULL);
virtual ~CEfmraDlg()
{
try
{
if (pThread)
if (pThread->ExitInstance())
delete pThread;
}
catch(...)
{
TRACE("never mind\n");
}
}
struct SToto
{
BOOL m_bToto;
};
static UINT StartThreadEfmRead (LPVOID param);
bool m_bStop;
}
void CEfmraDlg::OnEfmRead()
{
m_bStop = FALSE;
SToto stToto;
stToto.m_bToto = TRUE;
pThread = AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this);
}
UINT CEfmraDlg::StartThreadEfmRead (LPVOID param)
{
char buff1[100];
CEfmraDlg* ts = (CEfmraDlg*)param;
if(ts->m_scsi.EFM_open(newSparam) == 0)
{
FILE *fp;
if( NULL == (fp = fopen("cd.txt", "wb")))
{
ts->m_ListBox.AddString("Open cd.txt error");
}
ts->m_ListBox.AddString("Read CD begin ...");
int count = 0;
for(; count<=256*1024; )
{
count++;
if(ts->m_bStop)
{
ts->m_ListBox.AddString("Read EFM data aborted.");
fclose(fp);
AfxEndThread(0);
}
if(ts->m_scsi.EFM_read(fp))
{
ts->m_ListBox.AddString("Read Error!");
fclose(fp);
AfxEndThread(0);
}
memset(buff1, 0, 100);
sprintf(buff1,"CD Reading - Count: %d Bytes: %d", count, count*256*1024);
ts->m_diff = buff1;
ts->ShowText();
}
ts->m_scsi.EFM_close();
fclose(fp);
AfxEndThread (0);
}
return 1;
}
rechi
|
|
|
|
|
could any one give me or tell me where I can download c library for soket.h and other internet library? thanks;P
|
|
|
|
|
Does anyone know of a way to detect if a volume is set up as a Dynamic Drive ? I know that the System ID field of the partition table will be set to 0x42 but cannot determine a way to access this information using the SDK.
|
|
|
|
|
Just a guess: Open drive, read sector 1, cylinder 0.....
|
|
|
|
|
Nope.
I found it late yesterday. In the hardware SDK using DeviceIoControl(), however at the moment I am getting access errors, but I am sure I will get around those. Thanks for your help.
|
|
|
|
|
hDevice = CreateFile(disks[DriveNum].name, /* Open the argument drive */
GENERIC_READ|GENERIC_WRITE, /* Read-only access required */
FILE_SHARE_READ|FILE_SHARE_WRITE, /* Shared read access */
NULL, /* Default security attributes */
OPEN_EXISTING, /* Disposition */
0, /* File attributes */
NULL); /* Don't copy any file's attributes */
if (hDevice == INVALID_HANDLE_VALUE)
memset(&scip, 0, sizeof(scip));
memset(IdOutCmd, 0, sizeof(IdOutCmd));
scip.cBufferSize = IDENTIFY_BUFFER_SIZE;
scip.irDriveRegs.bFeaturesReg = 0;
scip.irDriveRegs.bSectorCountReg = 1;
scip.irDriveRegs.bSectorNumberReg = 1;
scip.irDriveRegs.bCylLowReg = 0;
scip.irDriveRegs.bCylHighReg = 0;
//
// Compute the drive number.
//
scip.irDriveRegs.bDriveHeadReg = 0xA0;
//
// The command can either be IDE identify or ATAPI identify.
//
scip.irDriveRegs.bCommandReg =
(VersionParams.bIDEDeviceMap & 0x10) ? \
IDE_ATAPI_ID : IDE_ID_FUNCTION;
if( IDE_ATAPI_ID == scip.irDriveRegs.bCommandReg) {
LogMessage1("%s : ATAPI device",disks[DriveNum].name);
}
scip.bDriveNumber = 0;
scip.cBufferSize = IDENTIFY_BUFFER_SIZE;
if ( DeviceIoControl(hDevice, DFP_RECEIVE_DRIVE_DATA,
(LPVOID)&scip, sizeof(SENDCMDINPARAMS) - 1,
(LPVOID)&IdOutCmd, sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,
&cbBytesReturned, NULL) )
{
IDSECTOR *pids=(IDSECTOR *)((SENDCMDOUTPARAMS *)IdOutCmd)->bBuffer;
ChangeByteOrder(pids->sModelNumber, sizeof pids->sModelNumber);
memset(disks[DriveNum].model,0,sizeof(disks[DriveNum].model));
strncpy(disks[DriveNum].model,pids->sModelNumber,sizeof pids->sModelNumber);
/* Strip trailing whitespace from model number */
for(j=strlen(disks[DriveNum].model) ; (j>0) && isspace(disks[DriveNum].model[j-1]) ; j--);
disks[DriveNum].model[j]=0;
DriveSize=pids->ulTotalAddressableSectors;
}
|
|
|
|
|
where device
_snprintf(disks[DriveNum].name,sizeof(disks[DriveNum].name),"\\\\.\\PhysicalDrive%d",DriveNum);
|
|
|
|
|
It was the second parameter to CreateFile() that was giving the access problems, I have got it now, its easier to do this:
<snippet>
PARTITION_INFORMATION pti;
hDevice = CreateFile("\\\\.\\c:",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
bResult = DeviceIoControl(hDevice,
IOCTL_DISK_GET_PARTITION_INFO,
NULL, 0,
pti, sizeof(*pti),
&junk,
(LPOVERLAPPED) NULL);
if (bResult)
{
switch(pdi.PartitionType)
{
case PARTITION_LDM:
AfxMessageBox("Dynamic Drive Detected");
break;
case PARTITION_EXTENDED:
AfxMessageBox("Extended Partition Detected");
break;
case PARTITION_FAT32:
AfxMessageBox("FAT32 partiton Detected");
break;
case PARTITION_FAT_16:
AfxMessageBox("FAT16 partition Detected");
break;
default:
AfxMessageBox("None detected");
}
}
Just a note though. The doco says that PARTITION_INFORMATION and IOCTL_DISK_GET_PARTITION_INFO is obsolete, so you need to use the latest versions, however, this is fine for what we are doing.
|
|
|
|
|
Ok I wish to emulate the functionality that Windows Explorer uses when you select the Folders Explorer bar. I've used Spy++ and learned that the main Rebar sits ontop of a blank window (called BaseClass I think...?) within the rebar there are two other child windows: 1 to the ToolBar X button and the other is the Treeview window. Does anybody know how to achieve this?
Any help would be nice and appreciated. Thank you.
Ryan
|
|
|
|
|
|
#define INSTANCES 3 <br />
<br />
char FrameTitles[INSTANCES][]={"LineSync","DoorClosed","DoorLocked"};
I do this in Mainfrm.h . What is wrong here and why are these errors coming ?
<br />
:\Application_dev\SamplerApp\MainFrm.h(16) : error C2087: '<Unknown>' : missing subscript<br />
C:\Application_dev\SamplerApp\MainFrm.h(16) : error C2117: 'LineSync' : array bounds overflow<br />
C:\Application_dev\SamplerApp\MainFrm.h(16) : error C2117: 'DoorClosed' : array bounds overflow<br />
C:\Application_dev\SamplerApp\MainFrm.h(16) : error C2117: 'DoorLocked' : array bounds overflow<br />
SamplerApp.cpp<br />
C:\Application_dev\SamplerApp\MainFrm.h(16) : error C2087: '<Unknown>' : missing subscript<br />
C:\Application_dev\SamplerApp\MainFrm.h(16) : error C2117: 'LineSync' : array bounds overflow<br />
C:\Application_dev\SamplerApp\MainFrm.h(16) : error C2117: 'DoorClosed' : array bounds overflow<br />
C:\Application_dev\SamplerApp\MainFrm.h(16) : error C2117: 'DoorLocked' : array bounds overflow
|
|
|
|
|
You can't have jagged arrays in C. Try this:
char* FrameTitles[INSTANCES] = { "lineSync", "DoorClosed", "DoorLocked" }; And if you do that you can drop the INSTANCES constant as well.
--Mike--
PROCRASTINATION: Hard work often pays off after time, but laziness always pays off now.
BUY MY SOFTWARE!! (please?) RightClick-Encrypt | 1ClickPicGrabber
My IntarWeb Homepgae!!!11
|
|
|
|
|
I am trying to write a device install program to get around the problem of xp sp1 installing a driver that i do not wish to use. The ftdi usb-serial device has an approved driver in sp1 that is installed when the device is plugged in.
In order to install the device you must cancel the driver request from windows, go to device manager, and manually update the driver xp installed.
I have played with SetupCopyOEMInf(), UpdateDriverForPlugAndPlayDevices() and calling "rundll32 SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 c:\temp\drivers\ftd2xx.inf" with no real success.
Is there any way to automate the manual install process?
Cheers,
Dave
|
|
|
|