|
Almost... std::vector::operator[] does not reallocate; calling it with an out-of-range index results in undefined behavior (std::vector::at(...) will throw an exception).
The OP should be using push_back to add to the vector . (Of course, they might want to preallocate some space for performance reasons...) The code then looks something like:
<br />
std::vector< int > my_array;
<br />
my_array.reserve( 32 );
for( ;; )<br />
{<br />
result = extern_function();<br />
if( result == 3 )<br />
break;<br />
my_array.push_back( extern_function_data() );<br />
}
Peace!
-=- James
Tip for SUV winter driving survival: "Professional Driver on Closed Course" does not mean "your Dumb Ass on a Public Road"! Articles -- Products: Delete FXP Files & Check Favorites
|
|
|
|
|
sure, i make a wrong.
if it's map it's right.
hi
|
|
|
|
|
I am writing a DDE server in VC++ to write data to Excel. I had seen some where the use of XlTable format. but that is not working well for me. Is there a better format than that i can use.
|
|
|
|
|
I have posted a couple of questions already on this subject and am understanding it now all the better. I have my code working but wonder what others would think of what I have.
It is the library object which contains a list of subjects. Each subject contains a list of books. I serialize the library to disk which works well. For an example when I store my library object I also write the number of subjects it contains. When I restore the library I then dynamically allocate new subjects the number of which I read from the data file. I can then add new subjects with a member function like this -
CLibrary::addSubject(const CSubject *subject)
{
CSubject *pSubject = new CSubject();
pSubject->name = subject->name;
}
I still wish to know though that what does CObject give me that I do not have to write myself anyway? I know it has other benefits like RTTI but what does it give for serilization? I just seem to have to write lots of code and CObject just is there doing nothing
|
|
|
|
|
CObject is the base class that has the virtual functions you are overriding.
It has the RTTI that the serialition subsystem uses to serialize and deserialze objects properly, especially ones it builds on the fly - meaning it has to create the objects that are serialized that your object contains.
If I don't plan to serialize or RTTI a class, then I uusally don't derive it from CObject myself.
|
|
|
|
|
Hai all,
I am doing a VC project invloving graphics.
While drawing a graphical object(say ellipse) on mousemove,
the whole screen is refreshed.
All the previously drawn objects are redrawn.
Consequently, the application slows down.
I am trying to refresh the particular region of the current object(ellipse) with InvalidateRect().
Please help me in solving this problem with InvalidateRect().
Or is there any other way to solve this problem?
With thanks,
Arun
|
|
|
|
|
|
I'm doing stuff like this in http://www.codeproject.com/miscctrl/diagrameditor.asp[^] where I find the performance quite ok. I'm updating all of the screen, but I do use double buffering. So, this might be a solution for you - create a memory CDC , draw all objects to it, and blit the whole mess to the screen in a single BitBlt .
|
|
|
|
|
OnEraseBkgnd():
return TRUE; // do all drawing in OnDraw()
OnLButtonDown():
pointAnchor = point;
rectCurrent.Set(point.x,point.y,point.x+1,point.y+1);
InvalidateRect(rectCurrent);
OnMouseMove():
rectNew.Set(pointAnchor.x,pointAnchor.y,point.x,poin.y);
rectNew.NormalizeRect();
rectNew.bottom++;
rectNew.right++;
rectCurrent.UnionRect(rectCurrent,rectNew);
InvalidateRect(rectCurrent);
rectCurrent = rectNew;
OnDraw():
Normaly in the above you would have been drawing to a bitmap via a memory DC.
BitBlt(...);
ExcludeClipRect(bitmapRect); // area where you blited the bitmap
CRect rcClip;
pDC->GetClipBox(&rcClip);
pDC->FillSolidRect( // fill in background
rcClip.left,rcClip.top,rcClip.Width(),rcClip.Height(),
::GetSysColor(COLOR_WINDOW));
With that said check out the article CExBitmap, it was designed to be used in a paint program.
Good luck!
INTP
|
|
|
|
|
I am trying to use named pipe to transfer data between two process. I have called the following code
<br />
HANDLE hPipe; <br />
LPTSTR lpszPipename = "\\\\.\\pipe\\DataTransferPipe"; <br />
<br />
hPipe = CreateNamedPipe( <br />
lpszPipename,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE |
PIPE_READMODE_MESSAGE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
1024,
1024,
18000,
NULL);
<br />
if (hPipe == INVALID_HANDLE_VALUE) <br />
{<br />
MessageBox("Error creating named pipe", "Named Pipe Error" , MB_OK);<br />
return;<br />
}<br />
<br />
bool bConnected = ConnectNamedPipe(hPipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); <br />
I want the system to be that if no client connect for say 3 sec the call ConnectNamedPipe should return false. Is this possible....how. In the above code it just locks on the ConnectNamedPipe call
|
|
|
|
|
BOOL SetNamedPipeHandleState(
HANDLE hNamedPipe,
LPDWORD lpMode,
LPDWORD lpMaxCollectionCount,
LPDWORD lpCollectDataTimeout
);
|
|
|
|
|
How can I remove non-client area of a window (border & title), which belongs to another process (separate application)? I have only HWND of that window, and cutting its DC using SetLayeredWindowAttributes() with LWA_COLORKEY, to get some specific shape, but all non-client area remains as an ugly frame. So I need to remove it somehow.
Note: the window is created by existing application, and I can’t change its code
|
|
|
|
|
You might want to try hooking the window and handling WM_NCPAINT .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
1) How to handle opening of a window, which belongs to another process (separate application)? The window has unique title, but not unique class. I need more intelligent way, than just calling FindWindow() from infinite loop
2) How can I monitor and handle closing/terminating of that window, after I found it?
|
|
|
|
|
Hook mechanism.
I don't know properly how to program to detect window open, but I know that is the most efficently way to detect.
Look in codeproject for hook. I think that you will have success ...
regards
Rodrigo Pinho Pereira de Souza
|
|
|
|
|
I have the following code:
typedef double* configPt;
configPt* configurations;
configurations = (configPt*)malloc(sizeof(configPt));
for(int i=0;i < max;i++)
{
configurations[i][0]=/*whatever*/
configurations[i][1]=/*whatever*/
}
/*Operations with the aid of configurations*/
free (configurations);
Well, when the program arrives to the free function, it crashes and i dont know why.
|
|
|
|
|
double** configurations;
configurations = (double**)malloc(sizeof(double*));
Here you are allocating a pointer to a pointer to double
for(int i=0;i < max;i++)
{
configurations[i][0]=/*whatever*/
configurations[i][1]=/*whatever*/
}
Here you are writing to a non allocated memory.
I would go for:
double **ppdDoubleMatrix = (double **) calloc(iRows, sizeof(double *));
if(ppdDoubleMatrix)
{
for (iRowsCounter = 0; iRowsCounter < iRows; iRowsCounter++)
{
ppdDoubleMatrix[iRowsCounter] = (double *) calloc(iColumns, sizeof(double));
}
}
Freeing it like so:
for (iRowsCounter = 0; iRowsCounter < pxThis->iRows; iRowsCounter++)
{
if (ppdDoubleMatrix[iRowsCounter])
{
free(ppdDoubleMatrix[iRowsCounter]);
ppdDoubleMatrix[iRowsCounter] = NULL;
}
}
// Free the pointer
free(ppdDoubleMatrix);
ppdDoubleMatrix = NULL;
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
for(int i=0;i < max;i++)
{
free(configurations[i][0]);
free(configurations[i][1]);
}
Enjoy it
Rodrigo Pinho Pereira de Souza
|
|
|
|
|
I'm trying to use a .dll and .lib that was created in VC++6 with a new VC.NET project. I add the .dll and .lib to the linker options and #include the cooresponding .h file to the project. I can't get the program to recongnize the function in the .dll and .lib correctly. It seems that .NET does not like the way the functions in the .h file are declared, or something?
Is there something new in VC.NET that I need to know with regards to using .lib and .dll?
Help! Thanks...
|
|
|
|
|
I have a dll port.dll .I don't know how to use them in VC++.
I use dumpbin tool but I can't use them. Help me doing this.
Please tell me in detail.
|
|
|
|
|
Hi,
Below link has a very useful tutorial related to
DLL implementation in VC++ 6.
http://www.codeproject.org/dll/XDllPt1.asp
Hope it will be useful to you.
Best Regards,
Irshad
|
|
|
|
|
Hello,
i want to develop a tool for winXP that dynamically
limits Intenet (IP) bandwith on a LAN host (LAN connected to Internet via router).
the tool should run on all LAN clients and send
information about the current IP traffic on the client to the other clients. with this information it should limit the bandwith to a predefined value, if the other clients need full bandwith, too.
for example: if three clients need full bandwith all
get limited to 1/3 of the full bandwith available.
if just one client need full bandwith it should get all.
thats the theory.
to manage this, i need to detect the current ip traffic on a client.
searching the web brought me to MS IpHlpApi.lib
but it only detects IP datagram amounts, not the real size if an ip-packet.
next solution is ip-packet sniffing, but this need
as far as i now, developing a kernel mode driver.
i know about pcap library for packet sniffing task
but it doesnt allow packet manipulation.
i dont need packet manipulation for my task, but
ive got another project in mind that does, so i want to go the straight (maybe hard) way.
i thought about using MS Visual C++ with MFC and DDK
so my question:
what would you suggest for solving my problem?
best regards
Robert
|
|
|
|
|
This sounds like any firewall code would do that. Maybe there is somethnig on Sourceforge ?
Elaine
The tigress is here
|
|
|
|
|
Have a scout about for "Packet Shapers". You may find some useful articles.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Hello !
I need to check if a specified directory exists. If not, I must create it (a complete path is specified).
How is the best way to do that ?
Thanks
|
|
|
|