|
You can call GetDriveType API function to determine if it's a CD Rom.
Check out the following wrapper class:
#include <windows.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
class DriveInfo
{
public:
DriveInfo()
{
char* buffer = 0;
size_t bsize = 0;
getDriveLetters(bsize,buffer);
parseDriveLetters(bsize,buffer);
delete [] buffer;
}
size_t NumDrives() const
{ return mDrives.size();}
std::string DriveName(size_t index) const
{ return mDrives[index]; }
char DriveLetter(size_t index) const
{ return mDrives[index][0]; }
DWORD DriveType(const std::string& driveName) const
{ return ::GetDriveType(driveName.c_str()); }
private:
void getDriveLetters(size_t& bufferSize, char*& driveStrings) const
{
bufferSize = MAX_PATH;
driveStrings = new char[bufferSize];
bool gotDriveNames = false;
while (!gotDriveNames)
{
DWORD pos = ::GetLogicalDriveStrings((DWORD)bufferSize, driveStrings);
if (pos > bufferSize)
{
bufferSize *= 2;
delete [] driveStrings;
}
else
{
gotDriveNames = true;
}
}
}
void parseDriveLetters(size_t size, const char* buffer)
{
std::string s(buffer, size);
std::string driveString;
for (size_t i=0; i<size; i++)
="" {
="" if="" (s[i]="=" 0)
="" (!drivestring.empty())="" mdrives.push_back(drivestring);
="" drivestring="" ;
="" }
="" else
="" +="s[i];
" }
="" std::vector<std::string=""> mDrives;
};
Example usage:
int main()
{
DriveInfo di;
for (size_t i=0; i
|
|
|
|
|
Or use something as simple as
<br />
for(int i=0;i<25;i++)
{<br />
if(RealDriveType(i,0) == DRIVE_CDROM)<br />
}<br />
|
|
|
|
|
Thanks for both your help.
I actually am using GetLogicalDriveStrings to get the available letters and then traverse through the letters using GetDriveType.
Thanks again....CP is the best!
|
|
|
|
|
NYTSX wrote: Thanks for both your help.
you can try warpper class for same here :-
http://www.codeproject.com/system/SysUtil.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi,
I am curious about how c++ stores it's array size after a call to new x[].
does it store the array size, or an object count?
If it is an object count then deleting an object recasted from what it was originally newed could cause an heap error right?
eg, would the code...
class objectx
{
// lots of things that make this an object much larger than bool!
};
objectx* myObject = new (myObject)bool[20];
// do code
delete[] myObject;
...cause a heap corruption as delete trys to delete 20 x objectx's?
-- modified at 16:22 Friday 9th December, 2005
|
|
|
|
|
lastgen wrote: objectx* myObject = new (myObject)bool[20];
???
what are you trying to do there?
lastgen wrote: delete[] myObject
the '[]' means this is an array of objects, so call their destructor (if there is one) before deallocating the memory. but the memory you allocated holds only bools, not myObjects.
massive trouble awaits those who lie to the compiler about what lies on the other side of a pointer.
Cleek | Image Toolkits | Thumbnail maker
-- modified at 16:19 Friday 9th December, 2005
|
|
|
|
|
I'm debugging code that was written by someone else. I'm fairly new to c++ but have been coding in other high level languages for years. I'm getting heap corruption but it's not occurring in previous version, but it seems to occur after leaving the scope of a function I call from the old code. One of the big changes is that 'objectx ' is now 4 times larger than it had previously been, although it had always been much larger than bool. I guessing that perhaps the call to 'delete[] myobject' would create code saying 'deallocate heap at myobject with a size of 20 * sizeof(myobject)' instead of the intended 'deallocate heap at myobject with a size of 20 * sizeof(bool)' and that was always causing heap corruption.
This why the old version never completely worked, but it didn't cause many critical crashes. Now with the much larger object (an array of ~1000 in size of objects roughly 1k each!) its corrupting so much of the heap it killing the app. Is this likely to be correct?
-- modified at 16:44 Friday 9th December, 2005
|
|
|
|
|
If you wish to allocate an instance of MyObject, then just say "MyObject *p = new MyObject". All this other stuff with bool has a terrible number of problems starting with the object won't be properly constructed.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
objectx* myObject = new objectx[20];
delete[] myObject;
|
|
|
|
|
The reason why they were allocating this way was the object is a union of static and dynamically sized data. Although not the best code this wasn't causing the issue. After following further I found a function that was being called was shifting the object but not updating the new pointer correctly.
|
|
|
|
|
We have a GUI application that hooks via TCP/IP to a child console process. I want to create a mini launcher console based app for these two applications.
I know the path to the child process. What I want to be able to do is obtain the child process executable and obtain some properties about...like what version it is. Then once I know this I can figure out what compatible version of the GUI to launch to hook the two together.
How can you open up an .exe file and get properties of it? Is there a way to get/set custom properties in the executable itself that you can compile in that another application can retrieve?
Kind of like the information shown in the "Summary" tab when you right-click and select 'Properties' from a .exe file. It lists Title,Subject,Category...Revision Number, etc. If I could figure out how to add to that list, and then obtain it programmatically, that would be perfect.
Thanks!
|
|
|
|
|
|
I'm guessing this is an MFC or .NET class. We're using just the straight WIN32 api. Nothing like that found.
I did find the GetFileVersionInfo() function, but it's not working since we don't have any version info resource in the child process executable. It may not be possible to do what I want without it, eh?
Thanks,
|
|
|
|
|
Well, I think I solved it...
What I have finally figured out is that you can export functions from a .exe. So, I created a header file that the .exe includes (indirectly, by other includes, so it will *always* be included) that exports a function. Then, I can call LoadLibrary() on the .exe, use GetProcAddress() to get a pointer to the exported function, then call it to obtain what I want, which is an integer value based on the version.
See my following post showing the .h:
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=1304933&df=100&msg=1304933#xx1304767xx
|
|
|
|
|
how can i tell if a window from one application is blocking a window in another application using VC++ and WIN32 API
|
|
|
|
|
What do you mean with "blocking"? Intercepting WM_CREATE messages using Windows message hooks? Periodically checking for a specific window title and killing it if it matches?
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
is there any max limit for it??? or is it unlimited???
regards
Supriya Tonape
|
|
|
|
|
The MSDN docs says "REG_QWORD 64-bit number". Hence it's not unlimited, but limited to 8 bytes of storage. Little endian format.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
For a SDI application, I can call AfxRegisterClass() in PreCreateWindow() to register class name. My question is -- how can it be done on a dialog based application since CMainFrame does not exist?
Thanks.
Vito
|
|
|
|
|
this is from the MSDN help for AfxRegisterClass:
BOOL COneT32App::InitInstance()
{
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS));
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hIcon = LoadIcon(IDR_MAINFRAME);
wndcls.hCursor = LoadCursor( IDC_ARROW );
wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = _T("MyNewClass");
if(!AfxRegisterClass(&wndcls))
{
TRACE("Class Registration Failed\n");
return FALSE;
}
..
no mainframe needed
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
I tried it before but it does not work. I used SPY++ which does not show the class name I wanted.
If it's a SDI or MDI application, I can set the class name with the CREATESTRUCT structure in PreCreateWindow().
|
|
|
|
|
|
Hey,
how can I draw a edge or a rectangle with thick LINES and correct edge.
When I draw it with e.g.
CPen test(PS_SOLID,5,RGB(10,10,10))<br /> I have a edge with a fringe.
Thanx for helping me
|
|
|
|
|
I'm not exactly sure what you mean by fringe, but IF I'm right in interpreting your problem, you need:
CreatePen (PS_SOLID | PS_INSIDEFRAME, nWidth, clrBrightPinkWithGreenBits);
I hope that helped,
Iain.
|
|
|
|
|
are you talking about lines with anti-aliased edges, to eliminate the jagged stair-step edges ?
you might try using GDI+, which can draw anti-aliased lines.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|