|
baloneyman wrote: The disk is fat32. I'm thinking this is the problem?
Yes.
Here's what the docs state:
"On the FAT file system, the specified date for both files and directories
is correct, but the time of day is always set to midnight."
|
|
|
|
|
Thanks for the quick response.
Guess I'll just have to think of something else for
non-ntfs drives.
Roy
|
|
|
|
|
Hi, I have such a problem that my toolbar isn't visible in IE7 by default. It seems to have some difference between IE < 7 and IE7, so my old code for IE6 doesn't work as expected in IE7 anymore. Please give me suitable code for IE7.
|
|
|
|
|
Hello.
I Know this isnt quite right forum to ask. The App is C#, however i am using Native WinAPI.
I am trying to list all process, and get full path. PROCESSENTRY32 in 95/98 used full path for exe. But not on newer system. MODULEENTRY32 Have szExePath. I wanted to use this to get full path.
I Used CreateToolhelp32Snapshot method to emurate process. (The only method that gave me good results). But to use Module32First() i need to open process, but i get error 87. On MSDN i found it is ERROR_INVALID_PARAMETER.
Is there a whay to fix this problem, or a diffrent method of getting full path. And no, no searching files through HDD.(I am intrested in the first solution)
Thanks in advance.
int hWnd = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe = new PROCESSENTRY32();
pe.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(PROCESSENTRY32));
int first = Process32First(hWnd, ref pe);
int error = GetLastError();
if (first == 0)
throw new ProcessListException("Can not get process list");
do
{
ProcessInfo pi = new ProcessInfo();
pi.iProcessID = (int)pe.th32ProcessID;
pi.sFileName = pe.szExeFile;
SetLastError(0);
int handle = OpenProcess(PROCESS_ALL_ACCESS, true, pi.iProcessID);
MODULEENTRY32 me = new MODULEENTRY32();
me.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(MODULEENTRY32));
bool t = Module32First(handle, ref me);
} while (Process32Next(hWnd, ref pe) != 0);
CloseHandle(hWnd);
Edit: Styling
|
|
|
|
|
Hi,
I'm no interopability expert, but error 87 means "INVALID_PARAMETER". I wonder if the C# Bool in
OpenProcess(PROCESS_ALL_ACCESS, true, pi.iProcessID);
translates to a Microsoft C TRUE which is a preprocessor define on 1. Maybe you should try this instead
OpenProcess(PROCESS_ALL_ACCESS, 1, pi.iProcessID);
So long,
Stefan
|
|
|
|
|
In addition to Stefan's reply...
First, you shouldn't be calling GetLastError() unless a return value indicates
an error actually occurred. If no error occurred, the return value of GetLastError()
is undefined in many cases. SetLastError() may have no effect if you're calling a Windows
API right after you use it. You have no idea how many times the error code for the thread may
change during that one API call.
Second, what do your marshaled structs look like? Are you marshaling them properly?
Third, you should be using IntPtr types for handles instead of int.
Mark
|
|
|
|
|
Mark Salsbery wrote: First, you shouldn't be calling GetLastError() unless a return value indicates
an error actually occurred. If no error occurred, the return value of GetLastError()
is undefined in many cases. SetLastError() may have no effect if you're calling a Windows
API right after you use it. You have no idea how many times the error code for the thread may
change during that one API call.
I Used SetlastError(0) to clear error from before. It was error 1008. And i called it after OpenProcess, i got error 87. Yust to make sure where it fails. And in a loop, the OpenProcess Failed all the time.
Mark Salsbery wrote: Second, what do your marshaled structs look like? Are you marshaling them properly?
I didnt use it properly.
Mark Salsbery wrote:
Third, you should be using IntPtr types for handles instead of int.
Changed it. And now it works. Thank you
|
|
|
|
|
I want to compress and decompress audio with g711.Well ,Done it,but there are lots of noise in it.
8000khz 2 channels 16 bits
CG711 g_711[2];
unsigned char g_getfrommicbuff[80000];//
int g_getfromsocketbuff[80000];//
CWaveFile* g_pWaveFile;
HRESULT CALLBACK GetData(unsigned char * pBuffer, int nBufferLen) //
{
static unsigned long pos=0;
unsigned long realread=0;
static long count=0;
if(pos<m_pWavFile->GetSize())
{
m_pWavFile->Read((unsigned char *)pBuffer,nBufferLen,&realread);
pos+=realread;
HRESULT hr;
unsigned int dwDataWrote=0;
//compress
int *pint=(int *)pBuffer;
for(int i=0;i<realread/4;i++)//
{
g_getfrommicbuff[i]=g_711[0].linear2alaw(*pint++);//
}
//decompress
for(int x=0;x<realread/4;x++)
{
g_getfromsocketbuff[x]=g_711[0].alaw2linear(g_getfrommicbuff[x]);
}
if( FAILED( hr = g_pWaveFile->Write( realread, (BYTE*)g_getfromsocketbuff, &dwDataWrote ) ) )
{
TRACE("error writing\n");
}
count++;
}
else//
{
memset(pBuffer,0,nBufferLen);
}
return 0;
}
class CG711
{
public :
CG711()
{
memcpy(seg_end,G_seg_end,sizeof(short)*sizeof(seg_end));
memcpy(_u2a ,G_u2a ,sizeof(unsigned char)*sizeof(G_u2a));
memcpy(_a2u ,G_a2u ,sizeof(unsigned char)*sizeof(G_a2u));
}
short seg_end[8];
unsigned char _a2u[128];
unsigned char _u2a[128];
int search(int val,short *table,int size)
{
int i;
for (i = 0; i < size; i++) {
if (val <= *table++)
return (i);
}
return (size);
}
unsigned char linear2alaw(int pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char aval;
if (pcm_val >= 0) {
mask = 0xD5; /* sign (7th) bit = 1 */
} else {
mask = 0x55; /* sign bit = 0 */
pcm_val = -pcm_val - 8;
}
/* Convert the scaled magnitude to segment number. */
seg = search(pcm_val, seg_end, 8);
/* Combine the sign, segment, and quantization bits. */
if (seg >= 8) /* out of range, return maximum value. */
return (0x7F ^ mask);
else {
aval = seg << SEG_SHIFT;
if (seg < 2)
aval |= (pcm_val >> 4) & QUANT_MASK;
else
aval |= (pcm_val >> (seg + 3)) & QUANT_MASK;
return (aval ^ mask);
}
}
int alaw2linear(unsigned char a_val)
{
int t;
int seg;
a_val ^= 0x55;
t = (a_val & QUANT_MASK) << 4;
seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
switch (seg) {
case 0:
t += 8;
break;
case 1:
t += 0x108;
break;
default:
t += 0x108;
t <<= seg - 1;
}
return ((a_val & SIGN_BIT) ? t : -t);
}
}
|
|
|
|
|
Why can't you leave it to windows ACM. Just an API acmStreamConvert will do the job for you.
|
|
|
|
|
Hello,
I'm attempting to integrate "The ultimate grid" - http://www.codeproject.com/KB/MFC/UltimateGrid.aspx[^] into my MFC application. I currently have my application working with a trivial grid, by using the sample "MyCug" class, per the ultimate grid beginner's guide: http://www.codeproject.com/KB/MFC/UltimateGrid_Start.aspx[^].
By editing MyCug's OnSetup(), I can cause the grid's initial content to change by calling various methods:
void MyCug::OnSetup()
{
...
cell.SetBackColor(grey);
cell.SetTextColor(black);
cell.SetText("One row");
SetCell(-1,0,&cell);
cell.SetText("Two row");
SetCell(-1,1,&cell);
cell.SetText("Three row");
SetCell(-1,2,&cell);
}
It is not obvious to me how I can change the content after the fact, without the unnecessary complexity of using a custom datasource - external calls to my object's SetCell() method from my CView don't have any apparent effect.
It would be acceptable to me to call MyCug's methods from my View, or to customise it and pass a container to it (something like an STL container) and have it do the work itself.
How can either of these things be done? What have I missed?
Regards,
Sternocera
|
|
|
|
|
I do this way:
1. prepare the data need to setup the grid
2. clear the grid
3. Setup the grid from gound up
BTW, I think the SetupGrid function should be at the place, where the knowledge to fill the grid is.
As my experiece, the author of UG will answer the question in no longer than 1 day.
|
|
|
|
|
followait,
The MyCug class has no SetupGrid() method.
So, I should have the grid update in the usual way, in OnSetup() , but after I've passed some container that contains the details?
>> 3. Setup the grid from gound up
How can I do that?
Thanks,
Sternocera
|
|
|
|
|
Maybe this way,
CMyData
{
public:
bool SetupGrid(CMyCug *pCug);
private:
}
bool CMyData::SetupGrid(MyCug *pCug)
{
pCug->Setup(this);
}
then in CMyCug
CMyCug::Setup(CMyData *pData)
{
...
}
It's really complex. You'd better ask the author.
system
|
|
|
|
|
The function you want to use is CUGCtrl::InsertRow(row) , which creates a new row at the specified location, or CUGCtrl::AppendRow , which adds a new row to the end. The row is empty so that you need to set the cell data afterwards
Graham
Librarians rule, Ook!
|
|
|
|
|
BOOL CMFCPropertyGridProperty::OnUpdateValue()
{
ASSERT_VALID(this);
ASSERT_VALID(m_pWndInPlace);
...
}
Now, trace it, when at bp2, press F10, it breaks at bp1, and the value of this changes.
|
|
|
|
|
It sounds like the .exe and the .pdb files do not match.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
m_pWndInPlace is invalid here.
PS: The problem is about anothing, change value via value list(a parent CMFCPropertyGridProperty),
the changes in subitems will not be informed. And when trying to add it manually, encounter this problem. I'll find another way before VS2008 SP1.
modified on Saturday, July 5, 2008 8:29 PM
|
|
|
|
|
Dear All
I'm having a spot of trouble - I'm hoping someone out there with a bigger brain than me might be able to help
I am trying to read a file and filter the contents into an output file. The input file is about 1.5Gb.
My code chugs away neatly doing it's job until it hits about 12% completion, then simply hangs or crashes! I have changed from the fstream.h to the windows.h to avoid the larger file issues associated there, but it still appears to give me problems. I was expecting problems over 4Gb, but the source text file is way smaller than that.
Anyway, here's the code for you - Again, any help is really apreciated.
#include <windows.h>
#include <iostream.h>
char * getEmail(char * str)
{
char * email;
int atpos = 0;
int spos = 0;
int epos = 0;
int length = strlen(str);
email = new char[length];
strcpy(email, "");
int x = 0;
while(x < length)
{
char ch = str[x];
if(ch == '@')
{
atpos = x;
}
x++;
}
if (atpos > 0)
{
bool found = false;
spos = 0;
x = atpos;
while(x > 0 && !found)
{
char ch = str[x];
if(ch == ',' || ch == '"')
{
spos = x;
found = true;
}
x--;
}
found = false;
epos = length;
x = atpos;
while(x < length && !found)
{
char ch = str[x];
if(ch == ',' || ch == '"')
{
epos = x;
found = true;
}
x++;
}
x = spos + 1;
int i = 0;
while(x < epos)
{
char ch = str[x];
email[i] = ch;
email[i + 1] = '\0';
x++;
i++;
}
}
return email;
}
int main(void){
HANDLE infileH;
HANDLE outfileH;
BOOL rsuccess;
BOOL wsuccess;
char s[10];
DWORD numRead;
DWORD numWriten;
char infile[MAX_PATH] = {"datafile.txt"};
char outfile[MAX_PATH] = {"output.txt"};
char * email;
char str[1024];
int x;
int i;
int atcount;
double goodemails = 0;
double bademails = 0;
DWORD pc = 0;
DWORD c = 0;
DWORD t = 0;
DWORD sizeLo, sizeHi;
cout << "Starting email extraction...\n\n";
infileH = CreateFile(infile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
if(infileH == INVALID_HANDLE_VALUE)
{
cout << "Error #" << GetLastError() << " occured on file open." << "\n";
}
sizeLo = GetFileSize(infileH, &sizeHi);
t = sizeLo;
outfileH = CreateFile(outfile, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
if(outfileH == INVALID_HANDLE_VALUE)
{
cout << "Error #" << GetLastError() << " occured on file open." << "\n";
}
x = 0;
do{
rsuccess = ReadFile(infileH, s, 1, &numRead, 0);
s[numRead] = 0;
str[x] = s[0];
str[x + 1] = '\0';
if(str[x] == '\n')
{
email = new char[1024];
email = getEmail((char*)str);
strcat(email, "\r\n");
i = 0;
atcount = 0;
while(i < (int)strlen(email))
{
if(email[i] == '@') atcount++;
i++;
}
if(atcount == 1)
{
wsuccess = WriteFile(outfileH, email, strlen(email), &numWriten, 0);
c = c + strlen(str);
pc = (DWORD)(((float)c / (float)t) * 100.0);
cout << pc << "% complete: " << email;
goodemails++;
}else{
c = c + strlen(str);
pc = (DWORD)(((float)c / (float)t) * 100.0);
cout << pc << "% complete: " << email;
bademails++;
}
x = 0;
}
x++;
}while(numRead > 0 && rsuccess && wsuccess);
CloseHandle(outfileH);
CloseHandle(infileH);
cout << "\n\n100% email extraction complete.\n\n";
cout << "Number of extracted emails: " << goodemails << "\n";
cout << "Number of bad emails removed: " << bademails << "\n";
return 0;
}
</iostream.h></windows.h>
|
|
|
|
|
You're going to need to do some more work at narrowing down the problem to just a small handful of lines if you want anyone to take you seriously. Use the debugger to help with this.
I see two instances of new , but no matching delete . Are you running low on memory?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
David is right; you allocate email, then clobber that pointer with an allocation within getEmail(); Neither make sense since you're using 1k.
I suspect, though, that the bigger problem is a buffer overrun. You do nothing to prevent more than 1k of data being put in str or email.
Another observation: you know how much data is being placed in the various strings, yet insist on calling strlen() and strcat() on them.
And what's with snippets like these?
char ch = str[x];
if(ch == ',' || ch == '"')
char ch = str[x];
email[i] = ch;
Why make goodemails a double. It can never be larger than a DWORD!
Why do you duplicate the code calculating the percent complete and why not define variable locally so it's more clear?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Thanks for the feedback. I worked with C++ back in the day and I guess I'm rather rusty. Trying to throw this together quickly and with zero sleep doesn't help.
Joe, you were spot on with the buffer overruns. More haste, less speed. All works a treat after some housekeeping.
Thanks again
|
|
|
|
|
Ubik K wrote: I worked with C++ back in the day and I guess I'm rather rusty.
Other than a few calls to cout , nothing that you have is C++.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm sure you're fun at parties. Ever heard of tact? Would it have been more accurate to say C with a smattering of Win32 system service calls?
|
|
|
|
|
The modeless dialog is created this way:
void CPropWnd::OnNavigator()
{
CNavDlg *pDlg = new CNavDlg(this, this);
pDlg->Create(IDD_NAVIGATOR, this);
CRect rc;
GetWindowRect(&rc);
pDlg->SetWindowPos(NULL,rc.left+rc.Width()+5,rc.top,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_SHOWWINDOW);
pDlg->UpdateWindow();
}
Why, and how?
|
|
|
|
|
I just wonder where you would destroy your dialog? If you create a dialog with "new" keyword you have to destroy it somewhere. Maybe this is the real source of your problem ...
So long,
Stefan
|
|
|
|
|