|
In my code, I have instantiated a template class in the following manner:
CallbackWrapperSpecific<MainWindow, void (MainWindow::*)(int&), int>* cbwsPtr = new CallbackWrapperSpecific<MainWindow, void (MainWindow::*)(int&), int>(this, &MainWindow::DoWork, i);
The above object is a functor, which encapsulates a class member function pointer. In this case, I assume that the class member function pointer always has a pointer to this (meaning that the class does not go out of scope while the functor exists), but I would not like to make the assumption that the functor pointer will not go out of scope, because it may very well do so until the time that the function pointer actually gets called. If it goes out of scope before that, then I will lose the pointer to that object and run into a memory leak. The difficulty here is not in capturing that pointer and deleting it later, but rather, in capturing that pointer, and making sure to delete it as a class of the type that I have listed above. Manually recasting to such a long-winded (and infinitely varying) type is not a good solution.
Because new and delete check the sizes of the objects (I think), would it be a good idea in this case to call malloc(), store both the pointer and the size of the pointer initially, and then call free() on the pointer, while specifying a size?
|
|
|
|
|
Dear all
build any one cube with VC++.who have such snippet? please send me, thanks a lot.
Regards
Li Zhiyuan
6/15/2007
|
|
|
|
|
you definately do need help.
Please read the guidelines for posting questions (at the top of the forum), then maybe modify your post to reflect those guidelines.
Then maybe you might get a better response
|
|
|
|
|
I think you can find a cube on the examples of MSDN did you see it?
|
|
|
|
|
I would like to intercept outgoing port 80 connections, redirect the http request, and inject the response back into the stream as if it had never been redirected.
Each time a user desires a web page, he transmits a request to a web server, and the web server transmits a response back to the user. Let us assume that user A is only able to access the IP address of user B, but user B is able to access the IP addresses of everybody. If user A desires a web page from someone other than user B, he will be unable to. The solution is as follows.
When user A requests a web page, instead of sending the request directly to the web server, the request is sent to user B. User B then requests the same request from the web server, and receives the corresponding response. That response is then sent back to user A.
To user A, it appears as if the request and response were completed with out having to send packets to user B. This is because all of the tunneling work goes on in the background. User A does not need to configure his web browser to connect to a certain proxy. Instead, when user A requests a certain page from a web server, a program running on user A's computer intercepts that request, does the necessary tunneling to user B, and finally injects the response back into user A's tcp stack, as if user A had himself contacted the web server.
I do not want to use a normal proxy. This all needs to occur in the background. The problem is implementing the previous paragraph. How do I tap into the windows tcp stack like that? I know that Google Desktop does it to modify search results, so it is definitely possible.
How do I do this? Sample code anyone? Sample projects? Any articles that have been written on this? Any help is welcomed.
Jason Donenfeld
ZX2C4 Software
|
|
|
|
|
Given the following two classes:
class A
{
public:
A() {}
A( const A &si )
{
m_strName = si.m_strName;
m_strStatus = si.m_strStatus;
}
A( const A *si )
{
m_strName = si->m_strName;
m_strStatus = si->m_strStatus;
}
A( LPCTSTR lpszName, LPCTSTR lpszStatus )
: m_strName(lpszName), m_strStatus(lpszStatus)
{
}
virtual ~A() {}
private:
CString m_strName;
CString m_strStatus;
};
typedef CArray<A*, A*> arr;
class B
{
public:
B() {}
B( const B &mi )
{
m_arrServices.Append(mi.m_arrServices);
}
virtual ~B() {}
arr GetServices( void ) const
{
return m_arrServices;
}
private:
arr m_arrServices;
}; I can't seem to figure out exactly what the compiler is complaining about (other than the obvious). I've changed the typedef statement to store actual objects, and references to an A object, all to no avail. I've had different types of constructors for A , but none of them seem to make a difference. The B::GetServices() method is supposed to return a copy of the m_arrServices array. I don't want to return a reference or a pointer to that array because I don't want it changed.
Both classes have several private members that I'm trying to provide getter and setter methods for. Any ideas?
Thanks,
DC
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: changed the typedef statement to store actual objects
My first thought as well. I suspect the 'problem' for the compiler is with the CArray class. It must be attempting to call some form of copy constructor which doesn't exist. I'd investigate the implementation of CArray with a view to determining which one.
Of course it is just possbile that the definition of CArray doesn't exist at this point in the compilation, if it was forward declared, and the compiler can't determine whether there is a copy constructor or not. It's cautious like that
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
CArray doesn't have a copy ctor. It doesn't matter what you use as the template params, there's no copy ctor to copy any CArray object. I'd suggest this:
const arr& GetServices() const { return m_arrServices; } Or if you absolutely can't return m_arrServices (the caller could cast away the const and muck with it) make the caller pass in a CArray that you fill in:
void GetServices(arr& a) const { a.Copy(m_arrServices); }
|
|
|
|
|
I think the copy constructor on CArray is declared as explict and therefore its not allowed to create a copy.
Sameer.
|
|
|
|
|
In an SDI application i am using one dialog box and i am using many number of radio buttons. When i close this dialog box and open it once again is there any way that i can get the same dialog box i.e which buttons which i selected earlier(before closing the dialog box).
Please reply.
|
|
|
|
|
l_d wrote: ...is there any way that i can get the same dialog box i.e which buttons which i selected earlier...
Yes, just save the state of the buttons in a configuration file or the registry.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
If you are closing the dailog and open it again without closing the main SDI application then u just have to make the dialog class object a member variable or a gloabal variable ( not recomended ). Now I suppose u r doing it as a local variable.
Regards
Anil
|
|
|
|
|
If u really dont want to close the dialog, just hide it instead of closing.
akt
|
|
|
|
|
|
See here and here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
This is the user who normally types a bunch of gibberish.
______________________
stuff + cats = awesome
|
|
|
|
|
Do you want to start it or you want to know what is it if you want to know about it so David's answer is good(his answers are good ) but if you want to leran it if you buy a book is better.;)
|
|
|
|
|
Hi,
I have a simple question concerning the best way to send data over a network. Imagine, you should write a program, e.g. like RADIUS. I actually don`t really know if Radius is a very complicated protocol, but that doesn`t matter.
In a way, it will look like the following example.
- The first byte is contains the id
- The next two byte contains the length of the package
- ...
Now my question is how would you program that in C. Because I think there exist two possibilities:
(a) you create a unsigned char array and save the data into it according to the specifications of the protocol
(b) you create a struct with the elements you need and send this over the network. But is it right that the data, stored in the structure need not be arranged in the memory as I defined it in the struct (from the compilers point of view)?
I`m very glad about any advice.
|
|
|
|
|
You could do it either way. If you know the structure of the data then a struct can be easier.
For example, following your proposed "packet header" which has an id and a length, you could make
a struct like this:
#pragma pack( push, PACKETHEADERpack, 1 )
struct PACKETHEADER
{
unsigned char Id;;
unsigned short Length; <code>
};
#pragma pack( pop, PACKETHEADERpack)
Note that the structure packing is set to 1 so no padding is added to the structure or its
members.
You can then receive a header on a socket something like:
PACKETHEADER PacketHdr;
recv(socket, (char *)&PacketHdr, sizeof(PACKETHEADER), 0);
You also may need to consider byte ordering in multi-byte numeric variables. If you will be
communicating between different platforms then you may need to convert them to network byte
order, send them, then convert them to the native format on the receiving end.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi Mark
thank you for your help. It was very useful
|
|
|
|
|
I have a DLL which is being developed in VC6.
This DLL uses internal resources such as a look-up table which i access using
AfxGetInstanceHandle() , FindResource and LoadResource API's
This works as expected.
However I have a project configuration that also creates a static library for the same , in which case the above mentioned API's will not be able to access the internal resource.AfxGetInstanceHandle will provide the handle to the application that uses this static library. With this condition , it seems that the internal resource needs to move to the application that uses the static library. For security reasons I dont want to expose this resource to external applications . Is it possible by some means to access the resource from the static library without having to move the internal resource to the application ?
Any ideas or suggestions are desperately needed .
Thanks
|
|
|
|
|
act_x wrote: Is it possible by some means to access the resource from the static library without having to move the internal resource to the application ?
Try this at the beginning of the function that accesses the resource:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
New to VC++, working with 6.0
Trying to read a text file one character at a time. If program finds a comma in text file, it stops and creates a string out of all the preceding characters. No problem reading the file or recognizing the comma. The program won't concatenate the chars into one string.
Here's the code:
char buffer[1];
char cur_char = NULL;
CString cur_data;
UINT bytesread;
do
{
cur_data += cur_char;
bytesread=radardata.Read(buffer,1);
cur_char=buffer[0];
}
while (cur_char != ',');
Every time I run it, cur_data ends up NULL. Here's what else I've tried with the same result:
cur_data = cur_data + CString(cur_char);
cur_data = CString(cur_data) + CString(cur_char)
Thanks in advance!
|
|
|
|
|
cur_data should end-up with NULL as you are adding NULL to it from the beginning.
The following will work;
char buffer[1];
char cur_char;
CString cur_data;
UINT bytesread = 0;
do
{
bytesread += radardata.Read(buffer,1);
cur_char=buffer[0];
cur_data += cur_char;
}
while (cur_char != ',');
--
=====
Arman
|
|
|
|
|