|
I define a winapp life m_font, a public data member of my derived CWinApp class,
But in the method
void CMyDialog::OnSelFontButton()
{
CFontDialog dlg;
if (dlg.DoModal() == IDOK)
{
CString strFace = dlg.GetFaceName();
int iFontSize = dlg.GetFontSize();
LOGFONT lf = {0};
lf.lfWeight = iFontSize;
_tcscpy(lf.lfFaceName, strFace);
<FAILED> theApp.m_font.CreateIndirectFont(&lf);
m_MYEDITCTL.SetFont(&theApp.m_font);
}
}
when I choose the font in the second time, I face a ASSERTION failure in the place <FAILED>. And I also tried a global definition, it failed in the same place too. Someone tell me why?
|
|
|
|
|
fantasy1215 wrote: when I choose the font in the second time, I face a ASSERTION failure in the place <failed>.
What line of what file is asserting?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Does this line has error? theApp.m_font.CreateIndirectFont(&lf); ?
|
|
|
|
|
This line doesn't have compile error.
But when running the exe, it faces the ASSERTION.
When I debug to trace, find the ASSERTION failed line is in that place.
|
|
|
|
|
Well I am running your code and its working (I checked bor button) but I have two questions:
(1)did you check return value of CreateFontIndirect what was it?
(2)You said SetFont doesnt work it has two arguments second parameter is for redraw did you use of default(true)
|
|
|
|
|
Sorry if this is the wrong place to post this...
I am writing a mini-filter which needs to open files before they are
deleted. I am filtering on _MJ_CLOSE and then checking the
DeletePending flag on the associated FILE_OBJECT. I need to open the
file for write access to wipe the contents, but no matter what I have
tried I always get a status STATUS_DELETE_PENDING from the Open
function. I have tried FltCreateFile, ZwCreateFile & IoCreateFile.
Can anyone shed some light on how this might be accomplished?
Thanks very much!
John
|
|
|
|
|
What is the accepted way to stop a thread from waiting on the ConnectNamedPipe() function?
I have tried terminating the thread with TerminateThread, and I have tried sending the pipe a special "terminate" message so that the thread can exit by itself.
But what is the accepted method?
|
|
|
|
|
Closing the handle may do it.
I personally like using overlapped I/O with events.
There's an example here: one Use for Overlapped I/O[^]
(see the section "Overlapped I/O Usage")
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks again, Mark. I see I'm not the first who ran up against this dilemma.
The overlapped method is brilliant in its simplicity. There is no need to call GetOverlappedResult() because we only need to know that the event has occurred!
|
|
|
|
|
Independent123 wrote: The overlapped method is brilliant in its simplicity. There is no need to call GetOverlappedResult() because we only need to know that the event has occurred!
Yeah, I like that I don't like any blocking functions - I want total control!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It was already answered, but don't try TerminateThread.. causes leaks most of the time. Properly signal the thread and close it from the inside to properly release your resources.
|
|
|
|
|
I'm trying to pass a pointer to a function as an argument to another function, but I am getting compile errors.
class CModule : public CDialog
{
public:
CModule (CWnd* pParent = NULL);
...
private:
unsigned char FunctTask1(unsigned char, unsigned char);
unsigned char FunctTask2(unsigned char, unsigned char);
unsigned char FunctTask3(unsigned char, unsigned char);
void ManageTasks(unsigned char, unsigned char, unsigned char (*)(unsigned char, unsigned char));
};
unsigned char CModule ::FunctTask1(unsigned char Param1, unsigned char Param2)
{
...
}
unsigned char CModule ::FunctTask1(unsigned char Param1, unsigned char Param2)
{
...
}
unsigned char CModule ::FunctTask1(unsigned char Param1, unsigned char Param2)
{
...
}
void CModule ::ManageTasks(unsigned char Param1, unsigned char Param2, unsigned char (*ptrFunct)(unsigned char, unsigned char)
{
...
switch (ptrFunction(1,1))
{
case 0:
case 1:
}
...
}
now based on a combobox selection, I will call a different function
void CModule::OnSelchangeCombobox()
{
switch(m_Combobox->GetCurSel())
{
case 0: ManageTask(1,1,FunctTask1); break;
case 1: ManageTask(1,1,FunctTask2); break;
case 2: ManageTask(1,1,FunctTask3); break;
}
}
but i get this error on compile
'ManageTasks' : cannot convert parameter 3 from 'unsigned char (unsigned char,unsigned char)' to 'unsigned char (__cdec<br />
l *)(unsigned char,unsigned char)'
What am I doing wrong? FYI I'm using VC++ 6.0.
|
|
|
|
|
acerunner316 wrote: What am I doing wrong?
From a quick glance at your code: you are trying to pass a pointer to a member-function where a pointer to a function is expected
|
|
|
|
|
so i have to specify in the argument list of 'ManageTasks' to expect a member function and not a regular function?
How do I do that?
|
|
|
|
|
The methods FunctTask1() , FunctTask2() , FunctTask3() either need to be static or not a member of CModule .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
In that case, I can't use it the way I had intended. I need FunctTask1,2,&3 to be able to access other member variables and functions that aren't static, so making it static wont work.
Time to rethink. Thanks for the help.
|
|
|
|
|
acerunner316 wrote: I need FunctTask1,2,&3 to be able to access other member variables and functions that aren't static, so making it static wont work.
You're not out of luck just yet. Two plausible solutions still exist. One is to change the third parameter of ManageTasks() to include CModule . I don't have the syntax readily available, but it's not uncommon and can easily be searched.
The other would be to create two versions of FunctTask1() , FunctTask2() , and FunctTask3() . One would be static and the other would not. That would look something like:
BYTE CModule::FunctTask1(BYTE Param1, BYTE Param2)
{
}
static BYTE CModule::FunctTask1(BYTE Param1, BYTE Param2, CModule *pThis )
{
return pThis->FunctTask1(Param1, Param2);
}
void CModule::ManageTasks(BYTE Param1, BYTE Param2, BYTE (*ptrFunct)(BYTE, BYTE), CModule *pThis )
{
...
switch (ptrFunction(1, 1, pThis))
{
case 0:
case 1:
}
...
}
void CModule::OnSelchangeCombobox()
{
switch(m_Combobox->GetCurSel())
{
case 0: ManageTask(1, 1, FunctTask1, this); break;
case 1: ManageTask(1, 1, FunctTask2, this); break;
case 2: ManageTask(1, 1, FunctTask3, this); break;
}
}
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: You're not out of luck just yet. Two plausible solutions still exist. One is to change the third parameter of ManageTasks() to include CModule. I don't have the syntax readily available, but it's not uncommon and can easily be searched.
Tried that, see by reply to Randor below.
I will try the overloaded function way. However, one of the reason I wrote my code the way it is was so that I can easily add more functions later (ie FunctTask4,5,6 etc) without having to change much code. Just add a new case in the OnSelchangeCombobox function. I can still call ManageTask to do the same things. Having to overload every single one seems inefficient to me.
|
|
|
|
|
acerunner316 wrote: Having to overload every single one seems inefficient to me.
Indeed, I was just offering all the possibilities I could think of, and let you figure out which one would be best for your situation.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
In addition to DavidCrow's reply....
You can pass pointers to member functions but to
use them you have to have an object of the class
they are a member of, just like any class method call.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
typedef unsigned char (CModule::*FUNCPTR)(unsigned char,unsigned char);
ManageTask(1,1,&CModule::FunctTask1);
|
|
|
|
|
tried that, but when I call ptrFunct(0,0); from inside ManageTask, I get an error saying "term does not evaluate to a function".
Edit: nevermind. just realized i have to call it like this:
(this->*ptrFunct)(0,0);<br />
-- modified at 18:42 Thursday 1st November, 2007
|
|
|
|
|
Modify the class as follows:
CModule : public CDialog
{
public:
CModule (CWnd* pParent = NULL);
...
private:
unsigned char FunctTask1(unsigned char, unsigned char);
unsigned char FunctTask2(unsigned char, unsigned char);
unsigned char FunctTask3(unsigned char, unsigned char);
typedef unsigned char (CModule::*PFunctTask_t)(unsigned char, unsigned char);
void ManageTasks(unsigned char, unsigned char, PFunctTask_t);
};
void CModule ::ManageTasks(unsigned char Param1, unsigned char Param2, unsigned char (*ptrFunct)(unsigned char, unsigned char)
{
...
switch ((this->*ptrFunction)(1,1))
{
case 0:
case 1:
}
...
}
And modify the calls like this:
void CModule::OnSelchangeCombobox()
{
switch(m_Combobox->GetCurSel())
{
case 0: ManageTask(1, 1, &CModule::FunctTask1); break;
case 1: ManageTask(1, 1, &CModule::FunctTask2); break;
case 2: ManageTask(1, 1, &CModule::FunctTask3); break;
}
}
-- modified at 20:49 Thursday 1st November, 2007
Steve
|
|
|
|
|
Hi all. Im trying to make a simple FTP client that uploads files. Again im trying to make a client that uploads files and not downloads. I specified that so that we could get an understanding of what im trying to do here. Anyway i was refered to a site that deals with programming for FTP Servers. Heres the url: http://www.stanford.edu/class/ee284/pa.html
he instructions were written for a UNIX programming but WinSock supports all the functions it calls for. The functions are the following:
socket()
bind()
listen()
getsockname()
accept()
Mind everyone finding a simple way to use these functions is NOT a simple task. But after spending countless hours using google/yahoo i came up with the following code:
<br />
#include <iostream><br />
#include <winsock.h><br />
using namespace std;<br />
<br />
<br />
#define port 21<br />
bool ftpmsg(const char *message);<br />
SOCKET dataSock;<br />
SOCKET socketbuffer;<br />
<br />
int main(){<br />
const int SIZE=100;<br />
char msg[SIZE];<br />
char server[SIZE];<br />
char recvbuffer[900];<br />
WORD wVersionRequested;<br />
SOCKADDR_IN addr;<br />
WSADATA wsa;<br />
struct sockaddr_in structSock;<br />
struct hostent *ftpserveraddy;<br />
wVersionRequested=MAKEWORD(2, 0);<br />
WSAStartup(wVersionRequested, &wsa);<br />
dataSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);<br />
<br />
printf("Please enter the Host name to connect to:");<br />
cin.getline(server, SIZE);<br />
printf("Connecting to FTP Server: '%s'\n",server);<br />
if((ftpserveraddy = gethostbyname(server)) == NULL){<br />
printf("DNS Lookup of '%s' failed!\n",msg);<br />
}<br />
structSock.sin_family = AF_INET; <br />
structSock.sin_port = htons(port);<br />
structSock.sin_addr.s_addr = *((unsigned long*)ftpserveraddy->h_addr_list[0]);<br />
memset(structSock.sin_zero, 0, 8);<br />
if(connect(dataSock, (sockaddr*)&structSock, sizeof(sockaddr)) == SOCKET_ERROR){<br />
cout << "Error " << endl;<br />
}<br />
recv(dataSock, recvbuffer, 512, 0);<br />
cout << recvbuffer << endl;<br />
<br />
while(1){<br />
socketbuffer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);<br />
getsockname(socketbuffer, (LPSOCKADDR)&addr, NULL);<br />
bind(socketbuffer, reinterpret_cast<SOCKADDR*>(&addr), sizeof(SOCKADDR_IN));<br />
listen(socketbuffer, 10);<br />
accept(socketbuffer, NULL,NULL);<br />
<br />
Sleep(1000);<br />
ftpmsg("USER user\r\n");<br />
Sleep(1000);<br />
ftpmsg("PASS password\r\n");<br />
Sleep(1000);<br />
ftpmsg("PORT\r\n");<br />
Sleep(1000);<br />
ftpmsg("STOR file.txt\r\n");<br />
Sleep(9000);<br />
ftpmsg("QUIT\r\n");<br />
}<br />
WSACleanup();<br />
return 0;<br />
}<br />
<br />
<br />
bool ftpmsg(const char *message)<br />
{ <br />
if(send(dataSock, message, strlen(message), 0) == SOCKET_ERROR){<br />
exit(1);<br />
return false;<br />
}<br />
else{<br />
return true;<br />
}<br />
}<br />
Notice how i try to open a new socket in the while loop because you have to open a new socket so that the data can be transfered there. I understand that much. However im getting my binding or listen wrong. I've been told that i should thread the connection but i dont see why considering its meant to do one thing. If anyone has any suggestion please let me know. I've been up and down the FTP RFC and i pretty much understand how it works. Now i just need to get the coding part right. Thanx in advance!
|
|
|
|
|
I'm not familiar with the FTP protocol so I can't address that portion of your code. However, I see some problems inside the while loop.
1) You don't check the status of any of your calls to socket, bind, listen or accept - you need to do so. I bet one of them is failing, and checking the error code returned by WSAGetLastError will help you determine what is wrong.
2) Assuming you do successfully create the new socket, you never destroy it at the bottom of the loop.
3) There is no way out of your while loop.
Judy
|
|
|
|
|