|
Havent tried that. Will check it out
|
|
|
|
|
I tried the method you suggested. I did not work. The code snippet is
std::string path = Devices[0] + "\\context.cfg";
HANDLE hUsbDevice = CreateFile(Devices[0].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hUsbDevice == INVALID_HANDLE_VALUE)
return 1;
char data[MAX_PATH];
DWORD nNumberOfBytesToRead = MAX_PATH;
DWORD lpNumberOfBytesRead = 0;
if(!ReadFile(hUsbDevice,(void*)data, nNumberOfBytesToRead, &lpNumberOfBytesRead,NULL))
{
int err = GetLastError();
return 0;
}
GetLastError() returns ERROR_INVALID_PARAMETER
|
|
|
|
|
koumodaki wrote: I tried the method you suggested.
But the code snippet you posted does not reflect such. You are not using path .
I like Judy's suggestion better.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I used the path but made a mistake while copying the code here. Ok so maybe I will try using WMI.
Do you have any tutorial which explains how to use Windows API in such situatuons?
|
|
|
|
|
koumodaki wrote: I can pass the handle I obtain while opening the usb flash drive from CreateFile() to this function.
The problem is that this handle is a handle to the physical drive. You can't use that to easily find a file on the drive.
Your basic problem is how to convert from a USB identifier to the logical hard drive letter. Using WMI you can go from something like USBSTOR\\DISK&VEN_SANDISK&PROD_CRUZER_MINI&REV_0.1\\20041100801E102869&0 (to take an example not at random) to G:. Stick the USB flash in your system, fire up the WMI object browser and you can see the queries you need to make to WMI to go from the former to the latter.
Judy
|
|
|
|
|
Thanks Judy. I will try this
|
|
|
|
|
JudyL_FL wrote: ...fire up the WMI object browser and you can see the queries you need to make to WMI to go from the former to the latter.
Interesting tool. I inserted a PNY Attache drive and tried it.
I found "E:" under the Win32_LogicalDisk node, and "USB\VID_154B&PID_0005\6E68190046F6" under the Win32_USBHub node. I then found "USBSTOR\DISK&VEN_PNY&PROD_USB_2.0_FD&REV_PMAP\6E68190046F6&0" under the Win32_DiskDrive node.
Where are these queries to which you refer?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
If you follow Win32_SystemDevices to Win32_PnPEntity, you should find a leaf with a device id something like USBSTOR.....
From there, you can get (look under Win32_PnPDevice) the correct DeviceId to use for Win32_DiskDrive.
From there, you can get (look under Win32_DiskDriveToDiskPartition) the correct DeviceId to use for Win32_DiskPartition.
From there, you can get (look under Win32_LogicalDiskToPartition) the correct DeviceId to use for Win32_LogicalDisk.
That final device id is the logical drive number.
(Whew!! <wiping brow="">)
Getting that first USBSTOR... monster string is what's usually the hardest part of this sort of thing since you have to use the SetupDi API. That is truly nasty!!
Judy
|
|
|
|
|
Wow! I need an elevator to come back to the surface from drilling down that deep. It works, though.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm looking for a way of identifying the data members of a number of classes that need to be serialized
Boost serialization would be used - but what I'm looking for is a way to automatically generate the serialization helpers.
The idea would be to:
1) Run an utility (parser) that scans the C++ code and identifies the data members
2) From the data members generate .inl files (one for each class) that would contain the boost::serialize() method
3) Have the .inl files included in the corresponding cpps
4) Compile and link...
These are classes that are modified on a daily basis by other people. Maintaining the serialization code manually would not be an option - looking for an automated way.
Definitely someone else had solved this problem (with this approach or a different one). Let me know if you know anything about that.
Thanks,
Adrian
|
|
|
|
|
Adrian R. wrote: 2) From the data members generate .inl files (one for each class) that would contain the boost::serialize() method
What about pointers?
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
|
|
|
|
|
I'm using a Gdiplus::Bitmap object as a buffer bitmap.
When do some, I can't open the file used by the bitmap in CFile::modeRead mode.
Is there any mehod to make it read-share?
|
|
|
|
|
i want to hook the windows API such as messagebox, i find the code in the net, but it dosn't work, why? the code as follows:
typedef struct tag_HOOKAPI
{
LPCSTR szFunc;
PROC pNewProc;
PROC pOldProc;
}HOOKAPI, *LPHOOKAPI;
HOOKAPI api[1];
api[0].szFunc ="MessageBoxA";
api[0].pNewProc = (PROC)MessageBoxA1;
HookAPIByName(GetModuleHandle(NULL),"User32.dll",&api[0]);
extern "C" __declspec(dllexport)PIMAGE_IMPORT_DESCRIPTOR
LocationIAT(HMODULE hModule, LPCSTR szImportMod)
{
PIMAGE_DOS_HEADER pDOSHeader = (PIMAGE_DOS_HEADER) hModule;
if(pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE) return NULL;
PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS)((DWORD)pDOSHeader+
(DWORD)(pDOSHeader->e_lfanew));
if(pNTHeader->Signature != IMAGE_NT_SIGNATURE) return NULL;
if(pNTHeader->OptionalHeader.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress == 0)
return NULL;
PIMAGE_IMPORT_DESCRIPTOR pImportDesc =
(PIMAGE_IMPORT_DESCRIPTOR)((DWORD)pDOSHeader + (DWORD)
(pNTHeader->OptionalHeader.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress));
while (pImportDesc->Name)
{
PSTR szCurrMod = (PSTR)((DWORD)pDOSHeader +
(DWORD)(pImportDesc->Name));
if (stricmp(szCurrMod, szImportMod) == 0) break;
pImportDesc++;
}
if(pImportDesc->Name == NULL) return NULL;
return pImportDesc;
}
extern "C" __declspec(dllexport) HookAPIByName( HMODULE hModule, LPCSTR szImportMod, LPHOOKAPI pHookApi)
{
PIMAGE_IMPORT_DESCRIPTOR pImportDesc = LocationIAT(hModule, szImportMod);
if (pImportDesc == NULL) return FALSE;
PIMAGE_THUNK_DATA pOrigThunk = (PIMAGE_THUNK_DATA)((DWORD)hModule + (DWORD)(pImportDesc->OriginalFirstThunk));
PIMAGE_THUNK_DATA pRealThunk = (PIMAGE_THUNK_DATA)((DWORD)hModule + (DWORD)(pImportDesc->FirstThunk));
while(pOrigThunk->u1.Function)
{
if((pOrigThunk->u1.Ordinal & IMAGE_ORDINAL_FLAG) != IMAGE_ORDINAL_FLAG)
{
PIMAGE_IMPORT_BY_NAME pByName =(PIMAGE_IMPORT_BY_NAME)((DWORD)hModule+(DWORD)(pOrigThunk->u1.AddressOfData));
if(pByName->Name[0] == '\0') return FALSE;
if(strcmpi(pHookApi->szFunc, (char*)pByName->Name) == 0)
{
MEMORY_BASIC_INFORMATION mbi_thunk;
VirtualQuery(pRealThunk, &mbi_thunk, sizeof(MEMORY_BASIC_INFORMATION));
VirtualProtect(mbi_thunk.BaseAddress,mbi_thunk.RegionSize, PAGE_READWRITE, &mbi_thunk.Protect);
if(pHookApi->pOldProc == NULL)
pHookApi->pOldProc = (PROC)pRealThunk->u1.Function;
pRealThunk->u1.Function = (PDWORD)pHookApi->pNewProc;
DWORD dwOldProtect;
VirtualProtect(mbi_thunk.BaseAddress, mbi_thunk.RegionSize, mbi_thunk.Protect, &dwOldProtect);
}
}
pOrigThunk++;
pRealThunk++;
}
SetLastError(ERROR_SUCCESS);
return TRUE;
}
static int WINAPI MessageBoxA1 (HWND hWnd , LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
{
return MessageBox(hWnd, "Hook API OK!", "Hook API", uType);
}
|
|
|
|
|
OK - you are not getting any replies because of the following issues, which I suggest you correct ASAP:
1: You code snippet neets to be inbetween <PRE> tags
2: In order to ask why something does not work, you have to specify what exactly is not working (error codes, crashes, etc.)
I have successfully used a CBT hook to capture, log the contents of, and pop MessageBox(...) -based dialogs successfully in the past, so I know this is not too hard.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
1. Format your code so it's readable. I know it's a pain, but it's also a pain from this end: I don't even bother to look at such messes.
2. What's going wrong?
Steve
|
|
|
|
|
yes, it was my fault to post such long and boring code!
but ,frankly to say, i got the code from the website, i didn't understand it with my little HOOK and DLL knoledge. i debuged the code , and found that it cound not get the User32.dll IAT location, i didn't know the matter.
my aim is to hook the window API , such as messagebox or winsocket, would you please give me some help? refering materials or codes?
thanks!
|
|
|
|
|
I have exe file generated of compile C++ code using Microsoft Visual Studio 2005 on my Laptop , and i need to take this exe file to run it on my pocket PC.
Is it possible to run this exe file on pocket PC ?????
ahmed.rayan@hotmail.com
|
|
|
|
|
Member 4174639 wrote: Help me please
Is it urgent?
led mike
|
|
|
|
|
led mike wrote: Is it urgent?
Of course it is. Did you not notice the five question marks?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Did you not notice the five question marks?
No and based on the thread below it's probably due to the inter-dimensional rift I seem to be caught in.
led mike
|
|
|
|
|
yes
It is urgent ,If u have time
|
|
|
|
|
So it's urgent, but depending on other people spare time, right?
Anyway, did you compile it for Pocket PC ?
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
|
|
|
|
|
Thanks for your time , but how can i compile it for Pocket PC?
|
|
|
|
|
Ask the Mobile Development [^] forum.
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
|
|
|
|
|
CPallini wrote: Ask the Mobile Development [^] forum.
no. Ask you compiler !
|
|
|
|