|
john5632 wrote: And I also checked all the recieving and sending threads, all are fine.
No they arent.
You have a server thread that is hogging the CPU when the client drops comms.
==============================
Nothing to say.
|
|
|
|
|
The most common cause of applications looping when communication closes is improper handling of the error returns from the various functions.
When you shutdown one end of a communications path the other end will recieve an error code or some other indication that the path is no longer functional. You are probably not handling those correctly. That's the first place I would look.
|
|
|
|
|
Hi,
I am using CMap. While adding and deleting elements I am using Locks because there are multiple threads Do I need to put lock before using pLookup function? Sometimes it crashes while looking up for an element. My lookup statement is like below :
if(cmap_buffer.PLookup(element.orderId) != NULL)
st_order = cmap_buffer[element.orderId];
Thanks,
Rahul Kulshreshtha
|
|
|
|
|
It is not thread safe. You will have to manually add the locking before accessing its data. Imagine what would happen if a node is removed while PLookup is using it.
The easies way of creating a thread safe container is to embed an existing container in a new class with the same interface, or a subset thereof if sufficient, forwarding all calls to the aggregated container and adding all the locking in between.
|
|
|
|
|
Thanks Niklas,
Using a thread-safe container will be a good solution. I wish Microsoft should provide some in-built thread-safe containers. As currently there is no inbuilt thread-safe way so I will go for creating my own. But I will not be able to use it in this project because it is 90% completed and implementing a new container and replacing it over existing map will take a big code-patching.
Thanks, I will take care this next time.
|
|
|
|
|
hi
i had created the menu.
i tried to add the image to the menu.
here is my sample code
CMenu menu;
CPoint point;
GetCursorPos(&point);
CBitmap Bmp_image,bmp1;
menu.CreatePopupMenu();
menu.AppendMenu(MF_STRING,ID__OPTION1,_T("Help"));
Bmp_image.LoadBitmap(IDR_bitmap1);
menu.SetMenuItemBitmaps(IDR_bitmap1,MF_BYCOMMAND,&Bmp_image,&Bmp_image);
reply it soon
thaks
best regards
sarfaraz
|
|
|
|
|
|
Your first parameter is wrong: see MSDN[^].
|
|
|
|
|
Hi,
Can anybody know about the fastest way to get folder size or the technique windows use to get folder size?
|
|
|
|
|
How about adding up the sizes of the files in that folder? I suspect a faster way would be to read the MFT but I don't know how to do that.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
|
This shows how to get the size of all the files in a folder,
and all its sub-folders on MS-Windows operating system.
It uses recursion to transverse all the directories, and return a 64-bit integer.
It was compiled with VC++ 2008 Express .
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
__int64 TransverseDirectory(string path)
{
WIN32_FIND_DATA data;
__int64 size = 0;
string fname = path + "\\*.*";
HANDLE h = FindFirstFile(fname.c_str(),&data);
if(h != INVALID_HANDLE_VALUE)
{
do {
if( (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
if( strcmp(data.cFileName,".") != 0 &&strcmp(data.cFileName,"..") != 0)
{
fname = path + "\\" + data.cFileName;
size += TransverseDirectory(fname);
}
}
else
{
LARGE_INTEGER sz;
sz.LowPart = data.nFileSizeLow;
sz.HighPart = data.nFileSizeHigh;
size += sz.QuadPart;
}
}while( FindNextFile(h,&data) != 0);
FindClose(h);
}
return size;
}
int main(int argc, char* argv[])
{
__int64 size = 0;
string path;
size = TransverseDirectory("c:\\dvlp");
cout << "\n\nDirectory Size = " << size << "\n";
cin.ignore();
return 0;
}
|
|
|
|
|
Hi,
I am looking into the issue of code signing. We distibute our software on CD Only. It is NOT available as Download on the Internet. Our suite is definitely not intended for distribution amongst the masses.
Currently, None of our customers' computers are connected to the Internet, and most probably will not be so for the forseeable future. The code signing issue is coming up because of the demise of windows XP. We want to avoid all those security warnings that Windows 7 shouts when the signature is absent.
Now how is a Win7 computer which is not connected to the internet going to check that the signature in the code is valid. More to the point, what is the advantage for me to registering and paying for the Code signing certificate, if the receiving computers can never walk up the chain to verify the certificate. Furthermore, what do I do to stop my customers getting those Security warning dialogs when using Windows 7.
By way of explanation, the computers our software runs on, act as Cash Registers in small businesses. Users have no physical access to the machine itself. Most of our customers have One machine only, a small minority run Peer to Peer Lan's of two three or 4 terminals. (The maximum is 16).
The Software Core has ran on Win95, Win 98, Win Millenium, and Win XP, and we have NEVER had any security issues. Our system has also always ignored the Windows Security System. Each terminal always runs in Windows Administrator Mode.
Code Signing for this suite causes hassle, and in this circumstance I cannot see any benefit. Is there a way to switch it off altogether.
In general, the machines do not run much other software. a few have MS Office installed, but that's it.
I was thinking along the lines of including a SelfSigned Cert with the CD.
How do I get such Cert installed without security screams via Win7, from my Installation Program, also on CD.
Any observations on the subject are wellcome.
Kind Regards,
Bram van Kampen
|
|
|
|
|
I've got an app I'm trying to migrate to visual studio 2008. The app uses MDI child windows. Inside of each of these MDI windows, when it creates it child view, it's create a custom class derived from CFrameWnd, to allow the creation of a toolbar. In VC6 this worked perfectly. In VS 2008 the toolbar creation code doesn't return any errors, but it doesn't display the toolbar either. Have there been changes here that you need to do? Is there some new magic MFC incantation that's required? Should I advertise on Craigslist for virgins to sacrifice, or barring that, magical unicorns?
//edit
turned out the solution was adjusting the toolbar's CreateEx call, and *NOT* passing in a CRect(0,0,0,0) and (UINT)-1 for the last to parameters. Well at least that saves me the hassle of dealing with virgins...
modified 22-Sep-11 10:56am.
|
|
|
|
|
Dear Friends
I have a dataset like below. 1 means Straight line with startPointX,startPointY,endPointX,endPointY.
//////////////////////////////////////////////////////////////
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -178.200000 52.000000 -138.200000 52.000000
1 0.000000 24.600000 0.000000 19.000000
1 -125.421613 36.515000 -138.200000 52.000000
1 -123.421613 36.515000 -107.873000 36.515000
1 -100.000000 19.000000 0.000000 19.000000
1 -105.873000 36.515000 -94.557821 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -100.000000 19.000000 0.000000 19.000000
1 0.000000 19.000000 0.000000 24.600000
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -94.557821 36.515000 -105.873000 36.515000
1 -107.873000 36.515000 -123.421613 36.515000
1 -125.421613 36.515000 -138.200000 52.000000
1 -138.200000 52.000000 -178.200000 52.000000
1 -115.000000 0.000000 -115.000000 15.000000
1 -115.000000 15.000000 -100.000000 15.000000
1 -100.000000 15.000000 -100.000000 19.000000
1 -100.000000 19.000000 0.200000 19.000000
1 0.200000 19.000000 0.000000 19.000000
1 0.000000 19.000000 0.000000 24.574923
1 0.000000 24.574923 -0.000000 24.600000
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -59.920000 36.515000 -66.103821 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -88.374000 36.515000 -94.557821 36.515000
1 -94.557821 36.515000 -105.873000 36.515000
1 -105.873000 36.515000 -107.873000 36.515000
1 -107.873000 36.515000 -123.421613 36.515000
1 -123.421613 36.515000 -125.421613 36.515000
1 -125.421613 36.515000 -138.200000 52.000000
1 -138.200000 52.000000 -178.200000 52.000000
1 -178.200000 52.000000 -178.200000 52.500000
1 -178.200000 52.500000 -178.200000 55.000000
1 -178.200000 55.000000 -190.000000 55.000000
1 5.000000 0.000000 5.000000 55.000000
1 5.000000 55.000000 -190.000000 55.000000
//////////////////////////////////////////////////////////////
I have to construct a profile which I can easily do by making a GL_LINES.
After that I need rotate the profile by x-axis and construct a surface of revolution. Please giveme some idea how can I achieve this. I have done something but I am not getting the surface.
Like I am storing the original startPoints and endPoints in an array with assuming z=0.
Then rotating each point by x-axis. so x-values will be same and y and z values I am calculating using this formula.
y = y cosq - z sinq;
z = ysinq + zcosq;
Is this correct...?? Then I am defining a number of loops and in loop I am creating GL_QUADS for each startPoint and endPoint...
1st loop 1ststartPoint, 1stLoop 1stendPoint
2nd loop 1stStartPoint, 2nd loop 1stEndPoint...
But I am not getting any 3D surface. Please help me.........Check the code below.
//////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct point3D{
float x;
float y;
float z;
}POINT3D;
int count1;
POINT3D *startPoints, *endPoints;
void CRevolutionProjView::drawProfile(CString filename)
{
pFrame->m_wndStatusBar.SetPaneText(0,L"DrawProfile !!");
// profile to be drawn
GLfloat PI = 4 * atan(1.0);
//file needs be open
double startPX, startPY, endPX, endPY;
double cenX, cenY, cenZ, rad, startA, endA;
ifstream indata; // indata is like cin
int id; // variable for input value
indata.open(filename); // opens the file
if(!indata) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
exit(1);
}
count1=0;
while ( !indata.eof() ) { // keep reading until end-of-file
indata >> id;
cout << "The id is " << id << endl;
if(id==1)
{
indata >> startPX >> startPY >> endPX >> endPY;
glBegin(GL_LINES);
glVertex2f(startPX, startPY); // origin of the line
glVertex2f(endPX, endPY); // ending point of the line
glEnd();
if(count1==0)
{
startPoints = (POINT3D *)malloc(sizeof(POINT3D));
endPoints = (POINT3D *)malloc(sizeof(POINT3D));
}
else
{
startPoints = (POINT3D *)realloc(startPoints,sizeof(POINT3D)*(count1+1));
endPoints = (POINT3D *)realloc(endPoints,sizeof(POINT3D) * (count1+1));
}
startPoints[count1].x = startPX;
startPoints[count1].y = startPY;
startPoints[count1].z = 0.0f;
endPoints[count1].x = endPX;
endPoints[count1].y = endPY;
endPoints[count1].z = 0.0f;
count1++;
}
}
indata.close();
cout << "End-of-file reached.." << endl;
}
void CRevolutionProjView::drawSurface()
{
double PI = 4.0 * atan(1.0);
//I have x and y points;
//count1 = numberof points
//theta = 0 to 360 degs.
//nsweep = number of sweeps. 360/nsweep = each angle;
int nsweep=4;
//no of profiles = nsweep + 1...
//each profile will have count1 no of lines...so count1 startpoints and count1 endPoints...
//so...total startPoints and endPoints for (nsweep+1) profiles = (nsweep+1) * count1...
POINT3D *totalStartPoints, *totalEndPoints;
totalStartPoints = new POINT3D[(nsweep+1)*count1];
totalEndPoints = new POINT3D[(nsweep+1)*count1];
int cnt1=0;
double theta, inter;
inter = (360/nsweep) * (PI/180);
theta = 0;
for(int i=0; i<(nsweep+1); i++)
{
for(int j=0; j
|
|
|
|
|
0. your formulae for y and z look ok
1. Do not use malloc (or any other alloc function) to allocate memory for POINT3D or any other class (or struct, which is essentially the same) type! Any class or struct may have constructors and destructors, neither of which will be called when using standard C allocation routines! Even though you didn't explicitely define either, the compiler does create some for you. And besides, you may want to add constructors or destructors later.
2. Don't use realloc, especially in the way you did (you're forcing a realloc on every single iteration of the loop!). Use standard container classes instead, such as std::vector (call #include <vector> ). They take care of reallocation and are orders of magnitude more efficient at it.
3. What happens with the rest of lines that do not start with '1'? Looks like the loop will just try their best on the rest of the line rather than skip to the next line. As there is no check on the number of inputs per line this will mess up the remainder of the input, as will any other unexpected mistake in the input file. Unfortunately the stream operators >> are not that helpful in this regard, check the member functions instead.
4. Your code is truncated.
6. Don't use global variables; the point arrays should be members of your revolution surface class. What would you do if you had two objects of type Revolution Surface?
7. A minor issue: make sensible objects and name them appropriately; a class that represents a 3D revolution surface is sensible, but what is the name 'RevolutionProjView' meant to indicate? What it does indicate is that this object is a view, which it is clearly not. Nor is it a projection. Why not just 'CRevolutionSurface' ?
Also the function name 'drawProfile' seems entirely inappropriate as it doesn't draw anything. Did you mean 'readProfile'?
|
|
|
|
|
Hi,
How to free the memory if memory is allocation using memset.
suppose,
ulong m_ularr[]; //declaration in header file
//In constructor we allocate memory as
memset(m_ularr, 0, sizeof(m_ularr));
Kindly help me how to free the memory in destructor for this one.
Freda
|
|
|
|
|
memset() doesn't do any allocations. Your array is allocated on the stack and will not require any deallocations. Only when allocating memory with an allocation method such as new/alloc/malloc/or other platform specific allocation methods, you will have to deallocate accordingly. memset() only writes data to a piece of memory that should allready have been allocated by you if you've done it properly.
|
|
|
|
|
Before worrying about memory deallocation, you should make sure you're writing (memset just writes) on previously allocated memory (in your code memory is never allocated).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
You dont need to free this memory, it is static.
You only need to free heap memory which you allocate with a new, or malloc, or alloc. (Use delete free and free respectively).
Or of course if you use smart pointers, which automatically free when they stack container goes out of scope, there isnt a need for a free, but thats getting a bit beyond your question.
==============================
Nothing to say.
|
|
|
|
|
I'm not a c++ programmer, but I need to be. I wrote a dll for installshield, that installs the web server program using shell as a custom action, but when I use their (IISHelper.dll) dll for programming the website, I run into problems. Thus I should write my own stuff in the same custom action.
So I working with some sample code, that gets the object, but the sample code returns the HRESULT, and not the object, unless the object is IIS_IADs, like getting the value of a registry key?, in which it's there but you have to sort of dig it out.
For now, I want to grab the default website in IIS5.1, and change the virtual path, the path to the code, and set the documents, mimes and so forth. If I can figure out how to grab the master object, I think I can program the rest and write the values.
hr = ADsGetObject( L"IIS://localhost/w3svc/1/root", IID_IADs, (void **)&pADs );
if ( FAILED( hr ) ) {
app_Level = 1;
goto error;
}
|
|
|
|
|
I think what you are talking about here is a COM object, which is a little different to a C++ object. I don't know enough about it to explain further, however, so i will let someone else do that .
But as far as i know, the "object" is returned as the pADs pointer, you need to cast it from void*
|
|
|
|
|
without seeing more code, pADs is the variable that will be holding the com object you want to manipulate. pADs is likely a pointer to some COM interface (if you're not sure what that means you'll have to read up on the c/C++ langhuage and how to use pointers), thus the use of
&pADs
the "&" means you're taking a reference to something, so a pointer to a pointer. That's how all (or most) of the COM API functions work - they return an HRESULT to indicate the success or failure of a call, and if the function is supposed ot give you back an object, then it's done like this, with a pointer to a pointer of some interface.
|
|
|
|
|
ohoooo
That was sort of like the registry function I wrote, In which it returns the Success code, and the object in the function contains the data.
Much different than VB or C#, or JavaScript.
Is it possible to export that com object, and pass it to another function for further processing?
HRESULT CA_WebInfo::get_IIS_VirtualDirectories( DWORD InstanceID ) {
HRESULT hr = CoInitialize( NULL );
if ( SUCCEEDED( hr ) ) {
USES_CONVERSION;
CComPtr<IADs> pADs;
CComPtr<IISApp2> pApp2;
WCHAR ADSIPath[50];
wsprintfW( ADSIPath, L"IIS://localhost/w3svc/%d", InstanceID );
hr = ADsGetObject( ADSIPath, IID_IADs, (void **)&pADs );
if ( SUCCEEDED( hr ) ) {
};
pADs = NULL;
hr = ADsGetObject( ADSIPath, IID_IADs, (void **)&pADs );
if ( SUCCEEDED( hr ) ) {
hr = pADs->QueryInterface( IID_IISApp2, (void **)&pApp2 );
if ( SUCCEEDED( hr ) ) {
CComBSTR bstrVarname = L"Path";
CComVariant varAppRootPath;
hr = pApp2->Get( bstrVarname, &varAppRootPath );
if ( SUCCEEDED( hr ) ) {
}
};
};
};
CoUninitialize();
return hr;
}
|
|
|
|
|