|
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
|
|
|
|
|
YOu may use ftell [^] and fseek [^]for the purpose.
Or you may use filelenght [^] (however you should pass a file descriptor to filelenght ).
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]
|
|
|
|
|
Thanks. The idea I'm getting from you is to seek to the end of the file and use ftell() to give me the size. I believe that's what you are saying.
|
|
|
|
|
You can do that, but that impliesm opening the file for (at least) read access. You could also use the _stat function.
|
|
|
|
|
Never met this _stat function before. Which header file is its prototype and how do I use it?
|
|
|
|
|
|
Based on what you told me I wrote the following function and it's working.
long get_file_size(FILE* fp)
{
fseek(fp, 0L, SEEK_END);
return (ftell(fp));
}
I checked the return value and compared with the size of a file read. It was correct. Thanxxx!
|
|
|
|
|
You are welcome.
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]
|
|
|
|
|
Dan_K wrote:
long get_file_size(FILE* fp)
{
fseek(fp, 0L, SEEK_END);
return (ftell(fp));
}
It was years ago i used these but didn't fseek() return the bytes, so:
long get_file_size(FILE* fp)
return (fseek(fp, 0L, SEEK_END));
Does the same? And wasn't Ftell() not enough?
long get_file_size(FILE* fp)
return (ftell(fp));
So this one does the same? Or I'm getting old?
Rozis
|
|
|
|
|
Small FYI. If you are going to read a file entirely into memory, buffered I/O (i.e. fopen()) is redundant.) If you want to stay with the CRT, you are better off using the _open()/_filelength()/_read() functions. (I just use the raw Win32 calls, but all my work is highly Windows specific.)
|
|
|
|
|
Hi All,
Can anyone provide me example for using zend library in vc++. I have to pass c++ object to php script is my requirement.
looking ahead for reply.
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|