|
|
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;
}
|
|
|
|
|
Yes, it's just like any other parameter, though you do have to be careful to keep track of the ref count.
Also, are you sure you want to be initializing/un-initializing COM in the one function? Wouldn't it make more sense to put that in your modules startup/shutdown code?
If get_IIS_VirtualDirectories is part of some other COM object (implemented in C++) then CoInitialize should already have been called, making your call redundant. If the code has to execute in another thread, then you really want to put the CoInitialize call in the thread's initialization before it starts doing anything else (and you don't want to use CoInitialize, you'll want to look at CoInitializeEx and use the multi-threaded settings).
|
|
|
|
|
I was using the code sample to try and sort of reverse engineer some sample code, and get a clear understanding of it first. The Big Picture is that I'm trying to write my own Custom Action DLL for InstallShield Pro, that installs the web server, looks at the metadata, if it's XPPro/Vista/7 with 1 default website, then change the virtual path, program the mimes, documents so my asp.net product will work.
I didn't know what the scope of coinitialize was, or what it does, and I prefer to just write 1 giant function first.
I wrote this first, as the main function, in which I want to fork out to another function based on the IIS Version installed. But I'm stuck creating my first engine function, that does the work. in switch case 5, I want to run the IIS job.
void CA_WebInfo::create_WebServer( CString msi_DIR_AppVolumeFolder_II ) {
bool iis_Result = false;
int program_ExitCode = 0;
unsigned long iis_MajorVersion;
unsigned long iis_MinorVersion;
CA_Registry caReg;
iis_Result = IIS_Installed();
if ( iis_Result == false ) {
program_ExitCode = install_WebServer( msi_DIR_AppVolumeFolder_II );
}
iis_Result = IIS_Installed();
if ( iis_Result == true ) {
iis_MajorVersion = caReg.get_IIS_MajorVersion();
iis_MinorVersion = caReg.get_IIS_MinorVersion();
int result_ADSI = 0;
switch ( iis_MajorVersion ) {
case 5:
attach_IIS5_XP();
result_ADSI = get_IIS_VirtualDirectories( 1 );
break;
case 6:
break;
case 7:
break;
}
}
}
I know I have to attach to the metadata first, see what it is, and then take action. I have written this in VB with great success, but c++ is lights years away. This is my intialization of the IIS MetaData.
I hope my explanation makes sense, this is my first c++ project since 28 years ago.
HRESULT CA_WebInfo::attach_IIS5_XP(void) {
HRESULT hr;
IADs *pADs = NULL;
IISApp2 *pApp2 = NULL;
IISApp3 *pApp3 = NULL;
DWORD instanceID = 1;
int app_Level = 0;
hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
if ( FAILED( hr ) ) { goto error; }
hr = ADsGetObject( L"IIS://localhost/w3svc/1/root", IID_IADs, (void **)&pADs );
if ( FAILED( hr ) ) {
app_Level = 1;
goto error;
}
hr = pADs->QueryInterface( IID_IISApp2, (void **)&pApp2 );
if ( FAILED( hr ) ) {
app_Level = 2;
goto error;
}
hr = pADs->QueryInterface( IID_IISApp3, (void **)&pApp3 );
if ( FAILED( hr ) ) {
app_Level = 3;
goto error;
}
error:
if ( pApp3 )
pApp3->Release();
if ( pApp2 )
pApp2->Release();
if ( pADs )
pADs->Release();
CoUninitialize();
return hr;
}
|
|
|
|
|
hi ,
i made a simple application for encryption and decryption of a text file using c language.
i want to know if a text file contains language symbols other than English , than how C language take care of it. Please also tell me if we can add other languages support in C language.
|
|
|
|
|
Check out http://en.wikipedia.org/wiki/Unicode[^]. You may want to use strings of unicode characters rather than just char Of course then you will also have to figure out and use encodings. Here's a good introduction on Unicode and encodings: http://www.joelonsoftware.com/articles/Unicode.html[^]
I'm probably not the best person to ask about what libraries and system functions to use, but it shouldn't be too hard to google for. I do know Visual Studio provides built-in support for unicode strings, it's right in the project options.
|
|
|
|
|
|
Hi Dveleopers,
I have some problem regarding combo-box control. In one situation it give the list properly and in the other one it appears till the mouse is hold after that it get hides. If we click on arrow part of combo box it behaves properly, but if we click on the text part it give the list while mouse is in hold after that it get hide.
In 1st condition I have added almost 15 items and in other situation almost 500 items is being added.
The only difference between these items is that 1st one is CString and the 2nd one is char*.
Here the sel change of another combo based on that combo box ""m_chap"" ( in which I have problem is being populated ). pFnameMap is a structure and pFnameMap->fullName is a char*.
CString szTemp;
m_nUserType = m_Rep.GetCurSel();
m_Chap.ResetContent();
if(m_nUserType != LB_ERR)
{
m_Rep.GetLBText(m_nUserType, szTemp);
if (szTemp.Find("Materia") >= 0)
{
FNAMEMAP1 *pFnameMap = NULL;
for( int i=0;i& heApp.m_ChapterNameMap.GetCount();i++)
{
if(APP->m_ChapterNameMap.Lookup((WORD)i,(void near *&)pFnameMap))
{
if(stricmp(pFnameMap->repName, "Complete")==0)
{
m_Chap.AddString(pFnameMap->fullName);
}
}
}
}
else
{
szQuery = "Repertory = '" + szTemp + "'";
m_pRsRepChaps->SetFilter(szQuery);
while(!m_pRsRepChaps->IsEOF())
{
m_pRsRepChaps->GetFieldValue("Chapter", szTemp);
if(m_Chap.FindStringExact(-1, szTemp)==LB_ERR)
{
m_Chap.AddString(szTemp);
}
m_pRsRepChaps->MoveNext();
}
}
}
Combo box style is dropdown.
Thanks in advance.
Amrit Agrawal
Software Developer
|
|
|
|
|
When do you add the items?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Hi there,
I've got a trouble of memory leak. I use Process Explorer to watch my app's status, and find that the "virtual size" keep increasing, and get to 2GB eventually, but the app never crashed.
I use windbg to check the app's memory status, the memory committed and memory reserved are also good(130MB),in my understanding, the "virtual size" is composed of the memory committed and reserved,but the fact is not. Please tell me how to calculate "virtual size", Thanks very much!
|
|
|
|
|
|
|