|
How about the GetLength() method?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Do you want to get the file length or CFile object length?
If you want to get the length of special file, you can use GetLength() to obtain it.
But I recommend you to use CFindFile, the class can help you to get any file's length include locked/system/hidden/archive and so on.
Good luck.
Andy Xia
2004.5.4
|
|
|
|
|
the size of the object is easy... sizeof()
Don't try it, just do it!
|
|
|
|
|
I wanted the length of the acutal file, not the object.
In the end I did this.
DWORD dwFileSize = myFile.SeekToEnd( );
myFile.SeekToBegin( );
It works el perfecto (same as the old stdio method).
|
|
|
|
|
I have a grayscale image of 100x100px, where the top half is gray (pixel value=128) and the bottom half is black (value=0); however when i plot it to screen, it comes flipped. Why is that? Can anyone help? Here is the source; The result on screen is black followed by gray, which is not what i want. Why is it flipped?
void CPopUpDlg::OnButton1()
{
BITMAPINFO *m_pBmiImage;
CDC *pDC;
BYTE *m_pImg;
pDC =this->GetDC();
DWORD bitmapInfoSize;
int i;
int Width=100;
int Height=100;
//image of 8bit , 100x100pixels
int m_iSize = Width * Height;
m_pImg = new BYTE[m_iSize];
// Bitmap info structure for the image
bitmapInfoSize = sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD);
m_pBmiImage = (BITMAPINFO*)new BYTE[bitmapInfoSize];
m_pBmiImage->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pBmiImage->bmiHeader.biPlanes = 1;
m_pBmiImage->bmiHeader.biBitCount = 8;
m_pBmiImage->bmiHeader.biCompression = BI_RGB;
m_pBmiImage->bmiHeader.biSizeImage = 0;
m_pBmiImage->bmiHeader.biXPelsPerMeter = 0;
m_pBmiImage->bmiHeader.biYPelsPerMeter = 0;
m_pBmiImage->bmiHeader.biClrUsed = 0;
m_pBmiImage->bmiHeader.biClrImportant = 0;
m_pBmiImage->bmiHeader.biWidth = Width;
m_pBmiImage->bmiHeader.biHeight = Height;
//Set the color table as just grays.
for (i = 0 ; i < 256 ; i++) {
m_pBmiImage->bmiColors[i].rgbBlue = (BYTE)i;
m_pBmiImage->bmiColors[i].rgbGreen = (BYTE)i;
m_pBmiImage->bmiColors[i].rgbRed = (BYTE)i;
m_pBmiImage->bmiColors[i].rgbReserved = 0;
}
//first half of the image is gray
for(i=0;i<100*50;i++) m_pImg[i]=128;
//second half of the image is black
for(i=100*50;i<100*100;i++) m_pImg[i]=0;
//Plot to screen
SetDIBitsToDevice(pDC->m_hDC,
100,
100,
Width,
Height,
0,
0,
0,
Height,
m_pImg,
m_pBmiImage,
DIB_RGB_COLORS);
delete[] m_pImg;
delete m_pBmiImage;
}
|
|
|
|
|
its a complete guess, might not work but worth a try
m_pBmiImage->bmiHeader.biHeight = -Height;
specify negative height
i can't even remember what my point is now, but anyway, i'm correct
Barring unforeseen acts of God and Adminstrators, my server will be up tomorrow. I'm more worried about the Adminstrators.
|
|
|
|
|
Thanks, works just fine! Now the image plots correctly! Thanks a lot for the prompt reply!!
|
|
|
|
|
I downloaded the IPC Workshop project from 'The Code Project' but I get the following error:-
c:\IPC\IPCWorkshop\IPCWorkshopDlg.cpp(110): error C2440: 'static_cast' : cannot convert from 'void (__thiscall CIPCWorkshopDlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
.... when I try and build the project with Visual Studio .Net.
Does anyone know the compiler setting to get rid of the error?
|
|
|
|
|
MFC 7.0 has enhanced message map macros which catch errors in the return value; MFC 6.0 did not check you used the correct return type.
Change the declaration of whichever function is causing the problem (the source line will show an ON_MESSAGE macro) so that the return type is LRESULT rather than void .
On some systems, this could cause run-time errors.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
|
Hello, every one:
My program is a Compress/Decompress tool just like WinZip and WinRAR.
In my program, I will do:
1. Drag some items from my ListView control to Windows Explorer.
2. I should get the target path where I finished the dragging.
3. If it is a valid path, I will extract the selected files to the special path right now.
In my ListView class, I responsed LVN_BEGINDRAG message to begin a dropping action like follow codes:
// Begin dropping...
CMyZipBoxDataSource datasrc;
FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
datasrc.DelayRenderFileData(CF_HDROP, &etc);
DROPEFFECT dwEffect = datasrc.DoDragDrop ( DROPEFFECT_COPY );
... ...
// End dropping
the Class CMyZipBoxDataSource is inherited from COleDataSource, and I overrided the function:
BOOL CMyZipBoxDataSource::OnRenderFileData(LPFORMATETC lpFormatEtc,CFile* pFile)
I don't know:
1. what should I write down in this function to handle this process?
2. how to get the target path the file will be extracted?
3. WinRAR extract selected files to a temp path after mouse up when draged. when it finished, move the extracted files to target path. Can I extract them to the target path directly?
That's my question, Thanks for your attention again.
Andy Xia (andyxia@radinf.com)
2004.5.4
|
|
|
|
|
I have set WH_CBT in a dll,and this dll is called only for one application. I set a global variant:BOOL bFalg. its initial value is TRUE;and if I have set this varible in share segment,dll can not work and application is shut down
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode==HCBT_ACTIVATE)
{
if(bFlag) //Problem is here:these codes are executed again and again
{
CString temp;
CFile f;
bFlag=FALSE;
temp = "bFlag";
if(!f.Open("D:\\1.txt",CFile::modeWrite | CFile::shareDenyNone|
CFile::modeCreate | CFile::modeNoTruncate))
return CallNextHookEx(hkbGetMsg,nCode,wParam,lParam);
f.SeekToEnd();
f.Write(temp,temp.GetLength());
f.Write("\r\n",2);
f.Close();
return CallNextHookEx(hkbGetMsg,nCode,wParam,lParam);
}
}
}
|
|
|
|
|
probably as ur BOOL is global and ur hook dll is loaded in to every process space it, every time it is loaded its global variables are initialised.
you need to have a shared segment in ur DLL keep ur variables here.
hope it helps
i can't even remember what my point is now, but anyway, i'm correct
Barring unforeseen acts of God and Adminstrators, my server will be up tomorrow. I'm more worried about the Adminstrators.
|
|
|
|
|
I wrote a piece of code long time back and compiled it to obj file. Unexpectedly i lost the source code of that. Is there any way to convert the obj files back to source files. I used visual c++ 6.0 to compile the source.
Regards
Guru
|
|
|
|
|
normally, no chance... but if you compiled it in debug mode, i know borland add a tool to get back the source code. but in release mode, you can't because the code is optimised...
TOXCCT >>> GEII power
|
|
|
|
|
Can you tell me where i can get the borlan tool that you are mentioning about.
Regards
Guru
|
|
|
|
|
i don't think it will work with a Visual C++ compiled object file, but at www.Borland.com[^], looking for Builder
TOXCCT >>> GEII power
|
|
|
|
|
I have 2 classes, and both classes needs to know of each other. Here's the headers:
sprite.h
<br />
#ifndef SPRITE_H<br />
#define SPRITE_H<br />
#include "SDL.h"<br />
#include "SDLgraphics.h"<br />
<br />
class sprite<br />
{<br />
public:<br />
sprite( char * p_path, int p_noFrames );<br />
void Animate( SDLgraphics &p_g );<br />
SDL_Surface* GetSurface() { return m_image; }<br />
SDL_Rect* GetRect() { return &m_image->clip_rect; }<br />
protected:<br />
float m_x, m_y;<br />
int m_noFrames;<br />
int m_curFrame;<br />
SDL_Surface* m_image;<br />
<br />
};<br />
#endif<br />
SDLgraphics.h
<br />
#ifndef SDLgraphics_H<br />
#define SDLgraphics_H<br />
#include <cstdio><br />
#include <cstdlib><br />
#include "SDL.h"<br />
#include "sprite.h"<br />
<br />
class SDLgraphics<br />
{<br />
public:<br />
SDLgraphics(unsigned int p_flags);<br />
void Init(int p_width, int p_height);<br />
void Draw(sprite *p_sprite, SDL_Rect *p_area);<br />
inline void Draw(sprite *p_sprite);<br />
void Flip();<br />
protected:<br />
SDL_Surface *m_scene;<br />
<br />
};<br />
#endif<br />
When I try to compile it in Visual Studio 7.0 .NET I get error C2061: syntax error : identifier 'SDLgraphics', and another one relating to sprite.
Greatful for any help ;P
|
|
|
|
|
declare one class before defining the other :
sprite.h
<font style="color:blue;">#ifndef</font> SPRITE_H
<font style="color:blue;">#define</font> SPRITE_H
<font style="color:blue;">#include</font> "SDL.h"
<font style="color:blue;">#include</font> "SDLgraphics.h"
<font style="color:blue;">class </font>sprite {
<font style="color:blue;">public</font>:
sprite(<font style="color:blue;">char </font>* p_path, <font style="color:blue;">int </font>p_noFrames);
<font style="color:blue;">void </font>Animate(SDLgraphics &p_g);
SDL_Surface* GetSurface() { <font style="color:blue;">return </font>m_image; }
SDL_Rect* GetRect() { <font style="color:blue;">return </font>&m_image->clip_rect; }
<font style="color:blue;">protected</font>:
<font style="color:blue;">float </font>m_x, m_y;
<font style="color:blue;">int </font>m_noFrames;
<font style="color:blue;">int </font>m_curFrame;
SDL_Surface* m_image;
};
<font style="color:blue;">#endif</font>
SDLgraphics.h
<font style="color:blue;">#ifndef </font>SDLgraphics_H
<font style="color:blue;">#define</font> SDLgraphics_H
<font style="color:blue;">#include </font><unknown_file1.h> <font style="color:green;">
<font style="color:blue;">#include </font><unknown_file2.h> <font style="color:green;">
<font style="color:blue;">#include</font> "SDL.h"
<font style="color:blue;">#include </font>"sprite.h"
<font style="color:blue;">class </font>sprite; <font style="color:green;">
<font style="color:blue;">class </font>SDLgraphics {
<font style="color:blue;">public</font>:
SDLgraphics(<font style="color:blue;">unsigned int </font>p_flags);
<font style="color:blue;">void </font>Init(<font style="color:blue;">int </font>p_width, <font style="color:blue;">int </font>p_height);
<font style="color:blue;">void </font>Draw(sprite *p_sprite, SDL_Rect *p_area);
<font style="color:blue;">inline void </font>Draw(sprite *p_sprite);
<font style="color:blue;">void </font>Flip();
<font style="color:blue;">protected</font>:
SDL_Surface *m_scene;
};
<font style="color:blue;">#endif</font>
TOXCCT >>> GEII power
|
|
|
|
|
thx
|
|
|
|
|
Instead of including sprite.h in SDLGraphics.h try a forward declaration:
SDLgraphics.h
<br />
#ifndef SDLgraphics_H<br />
#define SDLgraphics_H<br />
#include <br />
#include <br />
#include "SDL.h"<br />
<br />
class sprite;<br />
<br />
class SDLgraphics<br />
{<br />
public<br />
...<br />
That should work in this case, because in SDLgraphics.h you only need sprite pointers.
Jens
|
|
|
|
|
Is it possible to monitor/hook a COM port that has been opened by another application?
|
|
|
|
|
I have installed Pladform SDK, but my code seems to refer to old .h files and not the new .h files. How do i make them link to my new .h files?
I have updated the environment variables as well.
Thanx.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
If you build your projects from DevStudio you also have to adjust your directory settings.
In VC 6 this is done in Tools->Options->Directories->Include Files
In VC 7+8 use Tools->Options->Projects->VC++ Directories
Jens
|
|
|
|
|
Tools->Options->Directories->Include Files
change the order using ALT+(UP/DOWN) ARROW and make ur platform sdk dir preferrably first one.
It's not a bug, it's an undocumented feature. suhredayan@omniquad.com
messenger :suhredayan@hotmail.com
|
|
|
|