|
You forgot to select the pen out of the device context before calling DeleteObject().
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hello,
Are you using the CPen class, or simply the Win32 GDI function CreatePen?
If you are using the CPen class, you get a LOGPEN like this:
<br />
CPen myPen;<br />
myPen.CreatePen(PS_SOLID, 1, RGB(255,0,0));<br />
<br />
LOGPEN myLogPen;<br />
myPen.GetLogPen(&myLogPen);<br />
If you then wanted to change the color of the pen, you could change the LOGPEN property, delete the CPen object and then use FromHandle or CreatePen, passing the LOGPEN back to the object.
If you are using the Win32 GDI function, I think it returns an HPEN, in which case I'm not very clear about what your question is.
I realize the stuff I said in here is pretty basic and that you probably have a more complicated question, so maybe I just misunderstood it. In any case, if you can explain a little more I'll see if I can help you.
Sincerely,
Alexander Wiseman
Est melior esse quam videri
It is better to be than to seem
|
|
|
|
|
template <class T> LPVOID GetPtrFromRVA( DWORD rva, T* pNTHeader, PBYTE imageBase )
{
PIMAGE_SECTION_HEADER pSectionHdr;
INT delta;
pSectionHdr = GetEnclosingSectionHeader( rva, pNTHeader );
if ( !pSectionHdr )
return 0;
delta = (INT)(pSectionHdr->VirtualAddress-pSectionHdr->PointerToRawData);
return (PVOID) ( imageBase + rva - delta );
}
These lines of code were taken from Matt Pietrek's PEDump (http://www.wheaty.net/[^]). This function takes an RVA and gives you an actual memory address where this RVA is located.
imageBase - is the image base where the PE file being viewed is mapped.
pSectionHdr - is a pointer to a section where the rva falls in.
Now I don't understand the last line of the function. Wouldn't imageBase + rva be enough? Why would we factor in this delta variable? On top of that, pSectionHdr->VirtualAddress and pSectionHdr->PointerToRawData point at the same information but in two different contexts. The VirtualAddress is the RVA of the section and PointerToRawData is the file offset of the section. Therefore, the load offset cannot always be the same as the file offset.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
|
Hi, i am developing a mini server using the CAsyncSocket class to allow communication between a Macromedia flash based front-end application and a VC++ back-end on the same PC.
I assumed the server should run on port 80, however i was not sure whether i should use 'localhost' for the server name or create a new one. I used the ffg code sequence to start the server however it fails on the specifed port.
// Create the server
m_csLocalServer = "";
m_nLocalPort = 80;
BServerStatus = GetPeerName(m_csLocalServer,m_nLocalPort);
m_BServerStatus = MainServer.Create(m_nLocalPort,SOCK_STREAM,FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE,m_csLocalServer);
if(m_BServerStatus != 0)
{
m_csServerResponse = "The server has been started";
}
I'll appreciate if anyone can tell me what im doing wrong
cheers,
femi.
|
|
|
|
|
So class MainServer is derived from CAsyncSocket?
Kuphryn
|
|
|
|
|
Hi!
I'm looking for a way to change a directory creation date.
I tried SetFileTime API function, it works well for files, but doesn't work for directories...
How to change the creation date of a directory?
Thks in advance!
Appstmd
http://www.atlence.com
|
|
|
|
|
HANDLE hDir = CreateFile(
".\\testFolder",
FILE_LIST_DIRECTORY|FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ|FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL
);
if( hDir == INVALID_HANDLE_VALUE )
{
printf( "Cannot open directory!\n" );
return 0;
}
FILETIME CreationTime;
if( !GetFileTime( hDir, &CreationTime, NULL, NULL ) )
{
printf( "Couldn't read file time\n");
return 0;
}
CreationTime.dwLowDateTime ^= 0x0101010101010101;
CreationTime.dwHighDateTime ^= 0x0101010101010101;
if( !SetFileTime( hDir, &CreationTime, NULL, NULL) )
{
printf( "Couldn't set file time\n");
return 0;
}
CloseHandle( hDir )
// These two lines are there just so that the time will change drastically
// and that the changes would be visible to your eye. So you need to remove
// them in your application
CreationTime.dwLowDateTime ^= 0x0101010101010101;
CreationTime.dwHighDateTime ^= 0x0101010101010101;
Instead of GetFileTime, you can use GetSystemTime or whatever you wish to do.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
|
Hi!
I have tested your code under Windows 98. It seems that the flag FILE_FLAG_BACKUP_SEMANTICS is not supported under this system.
Is there another way to change the date of a directory under Windows 95/98?
Thks in advance!
Appstmd
http://www.atlence.com
|
|
|
|
|
I am sorry Atlence. I haven't done any coding for months now. I have gotten rusty. I checked the SDK and this is what it states:
Directories
An application cannot create a directory with CreateFile; it must call CreateDirectory or CreateDirectoryEx to create a directory. Opening a directory with CreateFile requires the FILE_FLAG_BACKUP_SEMANTICS flag.
FILE_FLAG_BACKUP_SEMANTICS Indicates that the file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks, provided it has the SE_BACKUP_NAME and SE_RESTORE_NAME privileges. For more information, see Changing Privileges in a Token.
You can also set this flag to obtain a handle to a directory. Where indicated, a directory handle can be passed to some functions in place of a file handle.
Windows Me/98/95: This flag is not supported.
A few years back I could do it directly with assembly code but nowdays Windows XP won't allow direct access to anything anymore.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
Atlence,
It just hit me that a few years back when I was more involved with assembly I would use DOS interrupts to change the time of the files. You could use those techniques in Windows 98. I believe that Windows 98 allows you direct access to the hardware (I could be wrong on this). Run a search on DOS interrupts and functions.
If you want this to work on both XP and Windows 98 then make sure that you do something like this:
if( Windows XP )
use FILE_FLAG_BACKUP_SEMANTICS
if (Windows 98 )
use DOS interrupts
It might not be the best solution but it will work. Sorry for the late reply but as I said earlier I haven't done much programming late.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
My project consists of 3 dialogs outof which 2 have been
inserted using Insert->New Form method in VC++ 6.0
The problem is that i dont know how to initialise the new
dialogs and display them when the user clicks a button
Eg: Dlg = DialogBox, BT = Button
Dlg1 consists on 2 buttons BT1,BT2
If user clicks BT1 then Dlg2 should be shown
Elseif user clicks BT2 then Dlg3 should be shown
Can anyone please give the code required for the above procedure?
Thankyou for reading
$TELOPHASE$
|
|
|
|
|
Hello!
The general code for displaying a dialog is as follows: you need to declare a variable whose type is the dialog you want to display. You then need to call the DoModal() function of the dialog. This is assuming that when you clicked 'New Form' in VC++ 6.0 that you left the base class as 'CDialog'. To check your base class open up the .h file of your dialog box (e.g. Dlg2.h) and look at the declaration for the dialog. It should look something like this:
<br />
class CDlg2: public CDialog<br />
If you see 'CDialog' then your dialog's base class is 'CDialog' and you can follow my instructions above. Here is a code sample of what you wanted to do:
<br />
void CDlg1::OnBT1()
{<br />
CDlg2 myDialog;<br />
<br />
myDialog.DoModal();<br />
<br />
}<br />
<br />
void CDlg1::OnBT2()
{<br />
CDlg2 myDialog;<br />
<br />
myDialog.DoModal();<br />
<br />
}<br />
Hope that helps! If you don't know anything about message handlers or just want to know how to add one, please ask. In the meantime you could take a look at http://www.codeproject.com/dialog/#Beginners[^] for some great articles on getting started with Dialogs.
Sincerely,
Alexander Wiseman
Est melior esse quam videri
It is better to be than to seem
|
|
|
|
|
Thankyou very much! This has solved my problems!
I will also take a look at the link you provided!
Have a nice day!
$TELOPHASE$
|
|
|
|
|
Try reading about the subject!
This[^]article should give you an idea about what you want to accomplisch...
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
Hello,
My question today has to do with how you should implement DC s. I am having some debug assertions caused by an apparent DC misusage and would therefore like to know if there is anything wrong with my implementation.
Would you say it is alright to have a global pointer/object (in, say, a custom control's class) for a DC which is used by any painting (graphical output) functions. For example, consider the following:
class CustomControl : public ...
{
private:
CDC *pDC;
.
:
.
};
CustomControl::OutputLine(char *szStr)
{
BeginOutput();
.
:
.
EndOutput();
}
CustomControl::OnPaint(LPPAINTSTRUCT lpPaint)
{
BeginPaint(lpPaint);
BeginOutput(lpPaint->hdc);
.
:
.
EndOutput();
EndPaint(lpPaint);
}
CustomControl::BeginOutput(HDC hdc )
{
if(!DCHandle)
{
DCHandle = new CDC;
ASSERT(DCHandle != NULL);
if(!hdc)
DCHandle -> Attach(GetDC() -> GetSafeHdc());
else
DCHandle -> Attach(hdc);
.
:
.
}
CustomControl::EndOutput()
{
ASSERT(DCHandle != NULL);
ReleaseDC(DCHandle);
DCHandle->Detach();
delete DCHandle;
DCHandle = NULL;
}
Now imagine a worker thread running ,which invokes OutputLine , above defined, multiple times per second. The debug assertion happens everytime the control has to repaint (OnPaint invoked), whilst it is outputting.
Any ideas on what is happening here and on how to solve this?
Thank you very much.
David
[EDIT:] By the way, this particular problem is occurring inside a worker thread, which is not derived from CWinThread but interacts with several controls.
|
|
|
|
|
Which ASSERT is triggerd?
IIRC, DC's cannot be shared between threads. Have you tried the same code in a single threaded application?
--
Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr.
Welle: Erdball - F104-G Starfighter
|
|
|
|
|
Jörgen Sigvardsson wrote:
Have you tried the same code in a single threaded application?
Yeah, that is why I know this is a multithreading issue.
Jörgen Sigvardsson wrote:
Which ASSERT is triggerd?
Somewhere in one of MFC's sources (I believe WinGDI , among others)
Well, I have tried to correct this in the following way:
-- BeginOutput will not return until DCHandle has not been freed by EndOutput ;
CustomControl::BeginOutput(...)
{
while(DCHandle!=NULL);
.
:
.
}
-- this means that, not only the implementation has to be perfect (there has to be a correct initialisation/destruction of the DC handle), but also the thread will perform one graphical output operation at a time...
What do you think of this?
David
|
|
|
|
|
dNimrod#X wrote:
What do you think of this?
I think a critical section or mutex would be better. 1) it would be safe and not prone to race condition errors, 2) it would save a lot of CPU usage. How often do you paint and how often does the different threads fight for the DC? If the thread paint requests are done often but not often at the same time, a spin lock could be advantageous. A spin lock is basically a thread safe while(locked); synchronization feature. I believe there are a bunch of spinlock implementations on this site alone.
But anyway, I would proceed with a thread safe way. Problems will occur otherwise, it's just a matter of time and coincidence.
--
Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr.
Welle: Erdball - F104-G Starfighter
|
|
|
|
|
Anybody knows, where i can find a free data mining application, some kind of demo or free trial, or maybe coding of data mining algorithm. Thanks.
<italic>Work hard and a bit of luck is the key to success.
|
|
|
|
|
Hello,
I am having problems with ShellExecute,
and it is probably my misunderstanding
of how it works.
I have a batch file called rmdir.bat:
@echo off
rem - rmdir.bat
rmdir .tempdir
and if I use ShellExecute(NULL,"open","rmdir.bat",NULL,NULL,SW_HIDE),
the .tempdir is removed. But if I change my batch file to read,
@echo off
rem - rmdir.bat
rmdir < $1
and change ShellExecute to
ShellExecute(NULL,"open","rmdir.bat",".tempdir",NULL,SW_HIDE),
the .tempdir is not removed.
I thought that lpParameters (i.e., ".tempdir" in this example) would get passed
to rmdir.bat, but apparently it does not.
Anybody know what I am missing here?
Thanks,
Murrah Boswell
|
|
|
|
|
I think your batch file is wrong.
rem set to off when the program works.
@echo on
rem use %1 not < $1
rmdir %1
rem stop batch program to see results
pause
|
|
|
|
|
This is correct. There's nothing wrong with your ShellExecute call
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
That was it! Been a while since I had tro write a batch file!
Thanks for your help,
Murrah Boswell
|
|
|
|
|