|
Great! Thanks for sharing.
-Saurabh
|
|
|
|
|
the application i am using requires the uncompressed tiff file having bit depth 1 and resolution of 300dpi. it is built in dot net 2003. whenever i open the uncompressed tiff image having bit depth 1 and save the same tiff image using savefiledialog function of dot net2003, the uncompressed tiff file becomes compressed and the bit depth is increased to 32. i haven't use any compression function. the code of saving the file is given below
private: void saveImageFile()
{
saveImage->Filter= "Tiff files (*.tif)|*.tif" ;
saveImage->FilterIndex = 1 ;
saveImage->RestoreDirectory = true ;
System::Windows::Forms::DialogResult d = this->saveImage->ShowDialog();
if (d == System::Windows::Forms::DialogResult::OK)
{
// creating a bitmap
Bitmap* saveMyImage;
saveMyImage=new Bitmap(this->pictureBox1->Image);//,System::Drawing::Imaging::PixelFormat::Format1bppIndexed);
saveMyImage->SetResolution(300,300);
saveMyImage->PixelFormat::Format1bppIndexed;// this line doesnot work
saveMyImage->Save(saveImage->FileName,System::Drawing::Imaging::ImageFormat::Tiff);
}
}
|
|
|
|
|
I think you better ask the managed C++/CLI forum [^].
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
My lecturer require me to use char for string.
I include the string.h header file for my program.
I have a pointer variable by using the following code.
<br />
char *abc[10][10];<br />
char *def[10];<br />
After I initialize *def[], I enter the following code.
<br />
int n=0;<br />
strcpy(*abc[n],*def);<br />
After I enter the code above, my program crash. Why?
|
|
|
|
|
I really can't tell what you're trying to do with the above code - whether there's a single thing out of place, or if the whole thing is ass-about.
See, you've declared two arrays of pointers - you then start copying the strings pointed to by the pointers in the def array into the memory locations pointed to by the abc array, although you never actually allocate any memory for the string. - What does abc[0][0] point at? That's where you're trying to copy a string to. - Plainly put, you most likely don't own the memory that abc's elements are pointing at, hence the crash. - try removing the malloc statement then seeing what happens - seem familiar?
Here - some code that will hopefully do a better job of explaining this than I fear I am doing atm.
int main()
{
char *abc[10][10];
char *def[10];
int i = 0;
def[0] = "String 0";
def[1] = "String 1";
def[2] = "String 2";
def[3] = "String 3";
def[4] = "String 4";
def[5] = "String 5";
def[6] = "String 6";
def[7] = "String 7";
def[8] = "String 8";
def[9] = "String 9";
printf("Method 1 - copy strings themselves\n");
printf("----------------------------------\n");
for (i=0; i<10; i++)
{
abc[0][i] = malloc(strlen(def[i])+1);
strcpy(abc[0][i], def[i]);
}
for (i=0; i<10; i++)
{
printf("%s\n", abc[0][i]);
free(abc[0][i]);
abc[0][i] = NULL;
}
printf("\n\n");
printf("Method 2 - just copy pointers to the strings\n");
printf("--------------------------------------------\n");
for (i=0; i<10; i++)
{
abc[0][i] = def[i];
}
for (i=0; i<10; i++)
{
printf("%s\n", abc[0][i]);
}
}
|
|
|
|
|
cshong wrote: After I initialize *def[], I enter the following code.
Please post the initialization code.
BTW did you initialize abc as well?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hey all,
I got a big C++ interview coming up....and I am arrogant and think I am a C++ god...so see if you can stump my knowledge of the language. I solemnly swear I won't cheat and look up the answer, and you can feel free to rip me a new one in your responses. The only requirement is that you can't include anything about particular libraries or interfaces that aren't intrinsic to C++ (stl stuff is ok). The interview won't include things like that or other trivialities which can simply be referenced. They will be asking me things like "name the 3 ways you can blah blah" or "how could the following code be improved...what is the security or memory problem...what weaknesses does it have etc"
Show me what you got! Put me in my place and make me feel like I am going into this interview a lot dumber than I think!
Thanks to all who decide to participate...I owe you one.
|
|
|
|
|
andersod2 wrote: I solemnly swear I won't cheat and look up the answer
How can honesty be expected from such an arrogant and possibly egoistic person?
-Saurabh
|
|
|
|
|
takes one to know one brother...if you don't have the goods, save the philosophy lesson for somebody else.
|
|
|
|
|
Hey god, this forum is full of peaple asking help on C++ : try to answer their questions.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
how can a master of something be arrogant?
being humble is the first step to learn. if you think you're really good, you'll stop wanting to learn because you think you know it all...
i guess it's time to stop looking at the mirror and look at the world...
|
|
|
|
|
and btw, if you're a god, try to help me at my question about classes and events that i posted here on the forum... that would be of a great help to me
thank you
|
|
|
|
|
Nope, no god here - must have been another one of those cults.
|
|
|
|
|
This thread has been a sincere waste of time. I honestly expected more from a well-known on-line forum like CP. I was able to get a lot of lively responses and challenges on other forums with this exact same thread text.
Moderator, please use this thread as an example of what not to do. Having no responses at all would have been better.
Sincerely,
andersod2
|
|
|
|
|
I'm trying to get the time when a file was last
read. I'm using the following:
////////////////////////////////////////////////////////////
CTime ReadTime, CreatedTime;
CString sString;
CFileStatus status;
bool bTest = true;
while(bTest)
{
CFile::GetStatus( "c:\\flag.txt", status );
ReadTime = status.m_atime;
CreatedTime = status.m_ctime;
sString = ReadTime.Format("%H %M %S");
AfxMessageBox(sString);
sString = CreatedTime.Format("%H %M %S");
AfxMessageBox(sString);
}
///////////////////////////////////////////////////////////
The created time is okay. The read time is zero.
Any suggestions?
Thanks,
Roy
MODIFIED: The disk is fat32. I'm thinking this is the problem?
Perhaps I can only use this for NTFS.
modified on Saturday, July 5, 2008 1:59 PM
|
|
|
|
|
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);
}
}
|
|
|
|