|
Alright, I think that I understand what you are saying (although I'm still confused as to why the designers of C decided to do this). The point of my post was to ensure that class Foo is correctly deallocating the member primes in it's destructor. If I understand you correctly, then all of the following should be equivalent statements, all of which result in no memory leaks:
virtual ~Foo() {
delete[] primes;
delete[] ℙ
delete[] &primes[0];
} Is it true that all of these correctly deallocate primes in the example? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
The best way of avoiding delete stress like this is to not bother with fiddling about with multi-dimensional arrays. Use a vector or vector of vectors and you don't have to worry about declaring it properly, sizing it or freeing it. The class does all that for you with very little overhead (bit of space, maybe some run-time cost if your optimiser isn't up to much).
Or another way is to handle the multidimensional bit yourself over a one dimensional array but that's a bit fiddlier and not the sort of thing you want to think about unless you're writing a collection class.
Cheers,
Ash
PS: All those will delete primes - just be careful of what they're pointing to. Arrays of pointers are a good way of going gaga and there's usually a better way of doing them.
PPS: The designers of C designed pointers and arrays to be very close to the hardware - which is why they're a bugger to use properly. Fortunately in C++ you don't need to use them that much, there's almost always a better alternative.
|
|
|
|
|
So, I'm fairly familiar with socket programming, but I have never before tried to send HTTP arguments to a web page before using WinSock.
I'm trying to duplicate the data in the following URL:
http://www.thewebsite.com/sub/database?action=authenticate&username=test&password=test
First, I am opening a socket to www.thewebsite.com on port 80. Then, I am sending the following:
<br />
std::string message = "POST /sub/database?action=authenticate&username=test&password=test";<br />
send(m_hConnection, message.c_str(), message.length(), 0);<br />
The problem is, I don't receive a response making me assume the format is incorrect since pasting the URL in a browser does return a response. Now, I'm kind of just guessing on the format to send the data in as I can't seem to find a good description online that doesn't involve a 3rd party library.
I have the following code in another thread in attempt to receive this data:
<br />
char recvbuf[MAX_BUFFER_LENGTH]; <br />
int result = recv(m_hConnection, recvbuf, MAX_BUFFER_LENGTH, 0)<br />
Any help is greatly appreciated.
Dustin
|
|
|
|
|
Found 2 of my problems.
First, it appears there is a problem receiving on the socket from a different thread that the one that created it. Can anyone confirm this and give me a possible solution?
Second, I added "HTTP/1.0\n" after POST in my message, I receive a response on a recv line directly after the send (not in the threaded method), but now I'm getting a response of:
HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Mon, 13 Sep 2010 21:35:24 GMT
Connection: close
Content-Length: 34
<h1>Bad Request (Invalid URL)</h1>
Any ideas?
|
|
|
|
|
Dustin Henry wrote: Any ideas?
Looks like a violation of the HTTP RFC, when client sends a HTTP 1.0 request the server must not answer with a HTTP 1.1 response as in your example. Well, try to send a HTTP 1.1 request as shown in my post below (including a Host header line), perhaps the server understand only HTTP 1.1. What kind of web server software are you using?
/M
|
|
|
|
|
Correct HTTP protocol[^] requires sending more than just the request line. If the service responds to pasting the URL to a browser, you must use the GET method instead of POST. The form data[^] is appended to the URL as name=value pairs separated by "& " characters.
|
|
|
|
|
Thanks for the reply, but linking to a 176 page document is not helpful in answering my simple question. Also, if you would look at the syntax I used I do understand the name=value pairs quite well. If you look at the reply I posted to my own post, I added the correct HTTP/1.0 header and now receive a response, but not a good one. Also, using GET instead of post does not seem to make a difference.
Thanks,
Dustin
|
|
|
|
|
Dustin Henry wrote: I'm trying to duplicate the data in the following URL:
http://www.thewebsite.com/sub/database?action=authenticate&username=test&password=test
This would be a GET request not a POST, translated into HTTP 1.1:
GET /sub/database?action=authenticate&username=test&password=test HTTP/1.1\r\n
Host: www.thewebsite.com\r\n\r\n
Does this help?
/M
|
|
|
|
|
Thank you, this helps a lot. Along with the GET, adding the correct formatting you've shown at the end of my request makes it work.
Thanks for the help
Dustin
|
|
|
|
|
Hello, I getting worried over this input validation as follows:
int age(0);
while (true)
{
cout << "\nEnter your age: ";
cin >> age;
if (cin.fail())
{
cin.clear();
cout << "Please enter a digit (number) only.\n";
continue;
}
cin.get();
break;
}
I don't get any problems when I enter a digit. In a way to validate input, I intentionally entered a letter. The test for cin.fail() is executed and the loop starts again. But when the loop restarts and gets to cin >> age, it does not wait for me to enter anything. It continues as if something has been entered, then the cin.fail() condition statements are executed again and again... I would like to know what I should do so that when the loop restarts and gets to where the application expects input, it waits for user input rather than continuing. Thanks.
|
|
|
|
|
|
You need to remove any guff that's currently gumming up the stream. Have a look here[^] for a canned solution.
The bit you're missing is at the end of the second if in the while loop.
Cheers,
Ash
|
|
|
|
|
hi,
i would like to write a control that works the same as the IE8 address bar with the auto complete option , and implement the delete that appear on each address.
in .NET i have the option of auto complete - is it also in MFC?
and regarding the delete i have no idea how to start....
thanks!!
|
|
|
|
|
should it be list box or combo box?
|
|
|
|
|
Hi I want to write a device driver and I need to include ntddk.h, ndis.h, ipFirewall.h and windows.h too (for calling some APIs for example MessageBox). When I compile the source file I get some errors like redefinition structures or constant values. Why?
And tel me how I can use APIs like GetDriveType, MessageBeep, etc in drivers.
Look at these:
1>d:\winddk\7600.16385.1\inc\api\ntdef.h(1418) : error C2027: use of undefined t
ype 'LIST_ENTRY64'
1>d:\winddk\7600.16385.1\inc\api\ntdef.h(1418) : error C2227: left of '->Blink'
must point to class/struct/union/generic type
1>d:\winddk\7600.16385.1\inc\ddk\mce.h(137) : error C2079: '_MCA_EXCEPTION::Time
Stamp' uses undefined union '_LARGE_INTEGER'
1>d:\winddk\7600.16385.1\inc\ddk\wdm.h(408) : error C2011: '_M128A' : 'struct' t
ype redefinition
1>d:\winddk\7600.16385.1\inc\ddk\wdm.h(417) : error C2011: '_XSAVE_FORMAT' : 'st
ruct' type redefinition
1>d:\winddk\7600.16385.1\inc\ddk\wdm.h(456) : error C2011: '_XSAVE_AREA_HEADER'
: 'struct' type redefinition
Thanks a lot
|
|
|
|
|
Reza Mirabdolhagh wrote: how I can use APIs like GetDriveType, MessageBeep, etc in drivers
short answer - you can't. It's a driver - it executes in kernel mode not user mode hence no user-mode APIs
Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
I've created a derived class of CMFCRibbonCombobox. How to set the RibbonComboBox to Drop List type by code? the default type is Dropdown.
Thanks!
|
|
|
|
|
Just set the second parameter to FALSE in its constructor
virtual void BeHappy() = 0;
|
|
|
|
|
I've tried this way. the second parameter is meaning of hasEditBox? not the droplist type.I followed the code and founded that there is a member(m_bDropDownListMode) in the CMFCPopupMenuBar class, and its default value is FALSE.How can I use it? when we use the toolbox in VS2010, we can modify the property to droplist type directly, How can I do it by code?
|
|
|
|
|
// not the droplist type.
Why not ?.. It would be a combobox with a choice list only...
What do you desire exactly for, please ?
virtual void BeHappy() = 0;
|
|
|
|
|
In CMFCToolBarMenuButton::OnCalculateSize Funcation:
...
if (pParentMenu->IsDropDownListMode())
{
CMFCDropDownListBox* pList = DYNAMIC_DOWNCAST(CMFCDropDownListBox, pParentMenu->GetParent());
if (pList != NULL)
{
return pList->OnGetItemSize(pDC, this, size);
}
}
...
so I desire to set RibbonCombobox dowmlistmode to respand the OnGetItemSize message, to execute the overload fun (OnGetDropListItemSize) which adjust the dropdownlist's width.
|
|
|
|
|
Try it :
class CMenuBarProxy : public CMFCPopupMenuBar
{
public:
void SetDropDown(BOOL bOnOff) { m_bDropDownListMode = bOnOff; };
};
void CYourComboBox::Redraw()
{
CMFCDropDownListBox* pcList = DYNAMIC_DOWNCAST(CMFCDropDownListBox, m_pPopupMenu);
if (pcList) {
CMenuBarProxy* pcBar = (CMenuBarProxy*) pcList->GetMenuBar();
if (pcBar && !pcBar->IsDropDownListMode()) {
pcBar->SetDropDown(TRUE);
}
}
CMFCRibbonComboBox::Redraw();
}
virtual void BeHappy() = 0;
|
|
|
|
|
make it! your code works well.. thanks!
|
|
|
|
|
Hi,
I have an application built on VS2005 which uses a static library built using VS6.0.
I have noticed an issue of incorrect function getting called from a static library linked at compiled time. Note that this static library was built using Visual Studio 6.0. Whereas my application which is using the static library for linking at compile time is built using VS2005.
At run time, I see that incorrect/different functions are getting called rather than the ones which are supposed to get called.
To solve this issue:
I rebuilt the static library (.lib) using VS2005. Then this newly built static library was used for compilation along with my application on VS2005. Then the functions are getting called correctly.
I have 2 questions here:
1) This means that if there is any static library built with older version of VS6.0, then it will not work correctly with an application built with VS2005. We need to rebuild it with the same compiler as the application is built with. Is this true? why this happens in case of static libraries?
2) If above point-1 is true, then isn't it necessary to rebuild DDLs also with VS2005? If no, then why it is ok that a DLL built with older version of compiler works fine with application built with newer compiler version?
|
|
|
|
|
Many things have undergone changes from older versions of the compiler.
It is not a matter of a static library or dynamic library.
If you're using any of the components that have undergone a change it would become incompatible.
For example, in ATL there have been many changes from ATL version 3.0 to 7.0.
Many classes have been split up into many different classes.
In MFC, the CString class has been changed to a template class.
These are a few changes that can make older libraries incompatible with newer compilers.
So when ever code for the library is available it is always better to compile them with the latest compilers.
You will also be able to catch many unknown bugs this way since newer compilers do much better than older ones.
|
|
|
|