|
Thanks for your thoughts.
I already listen to the device change events -- but one can never trust those to be completely accurate.
Is there a way to differentiate "removable" drives from "floppy" drives?
Some day, there will be no more floppy drives and my problem will go away!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
Peter Weyzen wrote: Is there a way to differentiate "removable" drives from "floppy" drives?
Im pretty sure there is - but cant search for the info right now - I did have a great article on doing such
'g'
|
|
|
|
|
What about Win32API GetLogicalDrives() and GetDriveType()? Are they of any use?
|
|
|
|
|
sure they can be used to determine what drives you've got - the Setup API can also do it ... but they cant tell you wether there's media in a floppy drive for example
(personally I'd disconnect the floppy drives - but thats skirting his/customers issue)
'g'
|
|
|
|
|
When you insert a CD or DVD, Windows will send a WM_DEVICECHANGE message. Does the same thing happen for a floppy disk?
"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
|
|
|
|
|
Peter - have a look at CFileTreeCtrl from PJ Naughter - he has a comment under updates [v1.09 (18 July 2000)] "Code has been made smarter so that it does not have to spin up the floppy disk to determine if there are files on it. It now initially displays a "+" and only when you try to expand it will it do the actual scan. "
Maybe not having to 'Spin Up' means the user also doesnt see the floppy/select light come on !
http://www.naughter.com/filetreectrl.html[^]
'g'
|
|
|
|
|
Hi, folks
I met such a problem when implementing a CScrollView class.
what i want to do is to show two images in one CScrollView instance, so I have the following code (below only shows one image in the left part of the window).
void OnDraw(CDC* pDC)
{
CDC dcMem;
CRect lRect;
GetClientRect(lRect);
lRect.NormalizeRect();
dcMem.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = (CBitmap*) dcMem.SelectObject(m_SourceBitmap);
CPoint scrollPosition = GetScrollPosition();
pDC->BitBlt(scrollPosition.x, scrollPosition.y, lRect.Width() / 2, lRect.Height(), &dcMem, scrollPosition.x, scrollPosition.y, SRCCOPY);
DeleteDC(dcMem);
}
however, when I scroll the window, right half part of the window always has some problem, either too much background (scrolling left) or too few background (scrolling right).
when I hide and show the window, everything is fine.
alternatively, I tried calling Invalidate() from OnScroll, flicker happens because OnDraw is called multiple times.
anyone got a solution?
thanks!
baum
|
|
|
|
|
I don't know for sure if this will help you, but I used this (simplified version) and for me was working good.
CClientDC dc(this);
CDC dcNormMem;
dcNormMem.CreateCompatibleDC (&dc);
CString szTempText = "";
CPoint cpTempPos, cpTempTextPos, cpScrollPoint = GetScrollPosition ();
CBitmap bmNormIn;
BITMAP bmNormTemp;
if (bmNormIn.m_hObject != NULL)
bmNormIn.DeleteObject ();
bmNormIn.LoadBitmap (IDB_NORMIN);
bmNormIn.GetObject(sizeof(bmNormTemp), &bmNormTemp);
dcNormMem.SelectObject(&bmNormIn);
cpTempPos.x = pDoc->m_cmlInputSet[nIn].m_cpInCoord.x - cpScrollPoint.x;
cpTempPos.y = pDoc->m_cmlInputSet[nIn].m_cpInCoord.y - cpScrollPoint.y;
dc.BitBlt(cpTempPos.x, cpTempPos.y, bmNormTemp.bmWidth, bmNormTemp.bmHeight, &dcNormMem, 0, 0, SRCCOPY);
szTempText = pDoc->m_cmlInputSet[nIn].m_szInName;
dc.SetTextColor(RGB(0,0,0));
dc.TextOut (cpTempPos.x, cpTempPos.y + SIGHEIGHT + 1, szTempText);
.
.
dcNormMem.DeleteDC();
ReleaseDC(&dc);
and
BOOL CMyView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
{
Invalidate ();
UpdateWindow ();
return CScrollView::OnScroll(nScrollCode, nPos, bDoScroll);
}
And for me was working good, I had up to 48 tiny Bitmaps on the screen and the Scroll of the window worked fine.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek
thanks for the reply.
Do you have a counter to count how many times OnDraw is called per scroll? in my code, I found it was called 2 or 3 times per scroll, and it caused flicker when scrolling (when dragging the scrollbar).
any clue?
thanks!
|
|
|
|
|
No, I didn't use a counter.
For me the problem of flickering was when I was moving the signals or placing a conection between two signals because I was calling Invalidate and UpdateWindow inside OnMouseMove so I was expecting that fliccker, but with the clicks of mouse or when scrolling it was working fine.
In the worst case, if you know that it is getting updated more times you can use a bool to draw only the first call (you can do it false when the mouse moves or at button release). I know it is not an elegant solution but at least can help while you search for the real issue.
On the other hand, I am sorry I can not help you more. My previous laptop died and I have no MS in this one, I am speaking with my boss to Install MS 2008 but not have it yet.
By the way... which version of VC are you using?
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I am using a rather old vc, 2003.
It is amazing to see that mspaint doesn't have any flicker when you drag the mouse and scroll it around.
dunno how they achieved that.
I tried creating a DDB bitmap, but it doesn't help.
|
|
|
|
|
I've got a DLL I'm able to call into without a .lib or header file. I'm using LoadLibrary and GetProcAddress to find the entry points for the exported function names. However, I am unable to determine what the functions take as arguments.
I used DumpBin to determine the exported function names.
Functions that have a "(void)" parameter list work OK. How do can I determine what the function signatures (e.g. arguments) are so I can effect a proper function call?
|
|
|
|
|
If the exported names are C++, you've got some chance of determining the signatures (because C++ embeds the signature information into the exported name to allow function overloading). Otherwise, you're pretty much out of luck, I think.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
I was afraid that was going to be the case.
Thanks for the info.
|
|
|
|
|
I'd agree with Stuart - if the dll is c++, you can decode the 'mangled' function names, because there is info there on the parameters - if its straight 'c', you need a .h file or documentation to determine the parameters
'g'
|
|
|
|
|
Hi all,
I'm working on a backup project in C++ for Windows XP and Server 2003. I want to be able to backup locked files like the registry and database files. I've looked into Volume Shadow Copy and it seems like the right direction to head, but I can't understand how to implement it in C++.
Here is our current method for backing up a file.
1. FindFirstFile/FindNextFile
2. Send path to file to compression function
3. Compression function simply calls zip.exe with the proper arguments (path to file, path to zip, etc)
3a. zip.exe is Info-ZIP.org's zip program.
My major issue with shadow volumes is that I want to directly access the files and not copy them. Since I'm trying to backup database files, it doesn't make sense to copy them (they are several GB in size sometimes). I'm curious to know if there are other methods outside of VSS to read/process locked files. The majority of enterprise backup solutions can do it without any issue or delay, so I know it's possible, I just don't know how.
I've looked at Hobocopy and it seems to be a valid option, but I don't think it'll work with my current compression method. I tried creating a shadow copy and using the \\?\GLOBALROOT\... path with zip.exe, but it failed, of course.
Thanks.
|
|
|
|
|
What if you granted your code the SE_BACKUP_NAME privilege and then used CreateFile() with FILE_FLAG_BACKUP_SEMANTICS ?
"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
|
|
|
|
|
Here's my sample code and output:
#include <windows.h>
#include <iostream>
#include <time.h>
#include <tchar.h>
using namespace std;
BOOL SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege);
HANDLE hFile;
void main() {
BOOL ret = SetPrivilege(SE_BACKUP_NAME,TRUE);
cout << "Ret: " << ret << endl;
DWORD dwErr=0;
hFile = CreateFile(L"c:\\windows\\system32\\config\\system", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
cout << "Handle: " << hFile << endl;
if (INVALID_HANDLE_VALUE == hFile) {
dwErr = GetLastError();
CloseHandle(hFile);
cout << "Could not open file: " << dwErr << endl;
}
CloseHandle(hFile);
SetPrivilege(SE_BACKUP_NAME,FALSE);
}
BOOL SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege)
{
TOKEN_PRIVILEGES tp;
LUID luid;
HANDLE hToken;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
if ( !LookupPrivilegeValue(NULL, lpszPrivilege, &luid) )
return FALSE;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
return ( (GetLastError()!=ERROR_SUCCESS)?FALSE:TRUE);
}
<br />
Ret: 1<br />
Handle: FFFFFFFF<br />
Could not open file: 32<br />
As you can see, it gave an Error 32, which is:
ERROR_SHARING_VIOLATION
32 (0x20)
The process cannot access the file because it is being used by another process.
I think I'm doing it properly...
|
|
|
|
|
You'll need to update your code (based on hobocopy) to use this API -- ExposeSnapshot() -- will cause the snapshot to be mounted to a drive letter. Letting you use a "normal path".
http://msdn.microsoft.com/en-us/library/aa382662(VS.85).aspx[^]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
Thanks for the hint, Peter, but when I added the following, the program crashes. I assume I'm missing something.
IVssBackupComponents *pReq;
VSS_ID snapID;
PWSTR wszExposed;
CLSIDFromString(L"{3c8b7455-4f04-4ead-b666-578ddb608138}", &snapID);
hres = pReq->ExposeSnapshot(snapID, NULL, VSS_VOLSNAP_ATTR_EXPOSED_LOCALLY, L"x:", &wszExposed);
I am using vshadow -wait c: on a test machine to generate the snapshot, so I'm not sure if that will cause any conflicts. I'll go ahead and tinker with HoboCopy and toss it in there to see what happens.
Thanks.
|
|
|
|
|
Doing more research on ExposeSnapshot(), aside from my above implementation being incorrect (don't need the {}'s), I don't think it works on XP. The snapshot needs to be created with a specific context property, either VSS_CTX_APP_ROLLBACK or VSS_CTX_NAS_ROLLBACK. Sadly, XP does not support setting a different context other than the default, VSS_CTX_BACKUP. So, it seems that using ExposeSnapshot is not a viable option as it needs to work on XP and Server 2003.
Thanks, though. I learned quite a bit more about VSS by looking through this.
|
|
|
|
|
I want to read files into memory in C. But the fread function needs the buffer where files from disk will be read to. How do I know the size of the file so that I can allocate the required memory size with malloc() before I give it to fread as an argument? I don't want the program to assume any file size. Is there any C library function to give
me the size of the file been opened so that I can allocate the needed memory size? Please help.
|
|
|
|
|
|
But I think GetFileSizeEx is windows specific that requires a HANDLE to a file. I don't want it to be based on Windows.
|
|
|
|
|
Ok so you should use the functions of CPallini. They should work.
Greetings
Covean
|
|
|
|
|