|
INVALID_HANDLE comes from the create file. The function says its specifically for getting USB serial numbers, I guess i just cant find the propper file\device name. Ive tried just the iManufacture and iProduct tags, even the address of the hub its located on.
There is a record of the serial number in the registry. But to get to it, you must know the USB location, and even after that, multiple SN show up. So Im assuming this wont help becuase each user will have differnt usb locations when they hook our printer up.
|
|
|
|
|
Does the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBPRINT key offer any help?
Or you could try CreateFile("\\\\.\\USB00#", ...) (where # is 1, 2, 3, 4, ...) until you find your printer.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
<br />
typedef struct _MEDIA_SERIAL_NUMBER_DATA {<br />
ULONG msn_SerialNumberLength;
ULONG msn_Result;
ULONG msn_AuthCommand;
ULONG msn_Reserved;
UCHAR msn_SerialNumberData[1];
} MEDIA_SERIAL_NUMBER_DATA, *PMEDIA_SERIAL_NUMBER_DATA; <n> <br />
<br />
HRESULT hr;<n><br />
HANDLE hdStgDrvr;<n><br />
PMEDIA_SERIAL_NUMBER_DATA pMSN;<n><br />
DWORD dwRet, dwLen;<n><br />
<br />
dwLen = DEFAULT_MEDIA_SERIAL_NUMBER_LENGTH;<n><br />
pMSN = (PMEDIA_SERIAL_NUMBER_DATA)malloc(sizeof(MEDIA_SERIAL_NUMBER_DATA)<n><br />
+dwLen + 1);<br />
<br />
if(pMSN)<n><br />
{<br />
hdStgDrvr = CreateFile((LPCWSTR)"\\\\.\\USB006", GENERIC_READ,<n><br />
FILE_SHARE_READ, NULL, OPEN_EXISTING,<n><br />
FILE_ATTRIBUTE_NORMAL, NULL);<n><br />
<br />
if (hdStgDrvr != INVALID_HANDLE_VALUE && <n><br />
DeviceIoControl(hdStgDrvr, IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER,<n> <br />
NULL, 0, (LPVOID)&pMSN, (DWORD)sizeof(*pMSN)+dwLen, &dwRet, NULL))<n><br />
{<br />
printf("You Win1!\n");<n><br />
hr = 0L;<n><br />
}<br />
else<n><br />
{<br />
printf("You Should Commit Sepiku1!\n");<n><br />
hr = GetLastError();<n><br />
}
this is basically what im trying to get to work where "\\\\.\\USB001" is the many things ive tried up to this point.
the registry suggestion does show i have a c86 printer on USB006, but provides me with no information as to serial number.
|
|
|
|
|
When CreateFile() fails, what does GetLastError() return?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The error returned is INVALID_HANDLE_VALUE.
|
|
|
|
|
So you're saying that both CreateFile() and GetLastError() return INVALID_HANDLE_VALUE ?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
sorry, i was mistaken, the create file error is ERROR_FILE_NOT_FOUND
|
|
|
|
|
So what does GetLastError() return?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
hr = GetLastError();<n><br />
printf("%i", hr);<n>
ERROR_FILE_NOT_FOUND
|
|
|
|
|
Is a device plugged into the USB port?
You might want to peruse this document for more information.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The printer is plugged in the USB port, and shows up in device manager. I will now investigate the above document you suggested.
|
|
|
|
|
UPDATE: i've found the source to USBView, and after digging through the above suggested document, ive found the answer to my problem. Thank you to everyone who helped out.
|
|
|
|
|
How about posting an excerpt of the solution?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
<br />
wsprintf((LPWSTR)HCName, (LPCWSTR)"\\\\.\\HCD%d", HCNum);<n><br />
hHCDev = CreateFile((LPCWSTR)HCName,<n><br />
GENERIC_WRITE,<n><br />
FILE_SHARE_WRITE,<n><br />
NULL,<n><br />
OPEN_EXISTING,<n><br />
0,<n><br />
NULL);<n><br />
This opens the handle to the USB device at Location %d, thats one small victory. Im still working on the SN part of my problem, but that should come a lot quicker now that I actually have a device or 2 to poll.
|
|
|
|
|
I am trying to overwrite/replace the text on the 'save' button in a common file dialog.
I have previously used SetControlText(IDOK, "NewText") without trouble, however this does not seem to work under Vista RC1. I can replace the text on several controls in Vista (eg the cancel button), by this method, but not the save/IDOK button!
Does anyone know anything about this, or able to give me some ideas to try?
TIA,
Hugh
|
|
|
|
|
|
The code I used was
#include <iostream.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<process.h>
class cust
{
// int cuno;
char name[20];
char address[50];
public:
int cuno;
void getdata(fstream &xyz)
{// ifstream ifil("abc.txt");
if (xyz)
{
xyz.seekg(-sizeof(cust),ios::end) ;
cuno=xyz.tellg();
}
else
{ cuno=1;
}
cout<<cuno;
cout<<"enter="" the="" customer="" name";
="" cin="">>name;
cout<<"Enter The Customer Address";
cin>>address;
}
friend class node;
friend class list;
};
class node
{
cust c1;
node *next;
public:
node (cust c2, node *n=NULL)
{
c1.cuno=c2.cuno;
strcpy(c1.name,c2.name);
strcpy(c1.address,c2.address);
next=n;
}
friend class list;
};
class list
{// friend class node;
node *start, *current, *precedence;
public:
list()
{
start=current=precedence=NULL;
}
addnode (cust *c)
{
if ( start ==NULL || c->cuno > start->c1.cuno)
{
start=(c , start);
return(0);
}
node *prv,*curr;
for (prv=curr=start;curr!=NULL &&c->cuno>curr->c1.cuno;prv=curr,curr=curr->next);
node *n = new node (*c,curr);
prv->next=n;
}
void traverse ()
{ cout<<endl<<"good one";
="" for(node="" *temp="start;" temp!="NULL;" temp="temp-">next)
{
cout<<"the student is"<<temp->c1.cuno;
cout<<temp->c1.name;
cout<<temp->c1.address;
}
}
};
void main()
{
clrscr();
list obj;
cust e1;
int c1;
char ch1='y';
while(ch1=='y')
{
cout<<endl<<"enter 1="" for="" entering="" the="" data";
="" cout<<endl<<"enter="" 2="" to="" view="" cin="">>c1;
if (c1==1)
{
fstream ofil("abc.txt",ios::in|ios::out|ios::app|ios::binary);
char rep= 'y';
while (rep== 'y')
{
cout<<"enter the details";
e1.getdata(ofil);
ofil.write((char*)&e1,sizeof(e1));
obj.addnode( & e1);
cout<<"do u wish to continue";
cin>>rep;
}
}
if (c1==2)
{
obj.traverse();
cout<<"bad one";
cout<<e1.cuno;
}
if="" (c1="=0)
{exit(0);" }
cout<<"do="" u="" wann="" to="" continue";
cin="">>ch1;
}
getch();
}
|
|
|
|
|
You really think that we will analyse your code in order to know what the problem is ? There is even no code indentation and no formatting at all.
You could at least tell us what you try to achieve and what the problem is (and with sufficient details for us to understand).
|
|
|
|
|
Asking about "automatic generation of employee no" does not mean a whole lot out of context. Trim your code snippet down to just a small handful of relevant lines so that it matches the question.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
hi
how to create 2 views with one document and not at a time .its like if i open one another should be closed .If anyone of u have any answer plz let me know
"Men never do evil so completely and cheerfully as when they do it from religious conviction"
-Pascal
|
|
|
|
|
Dear everyone;
I have got a pure C++/ algorithmic question that i would appreciate your input towards.
I have a number of files (lets say 100 files) of similar input formats (Strings). To reduce the complexity of the problem I will give you a simplied example:
File 1: File 2: File 3: File4:
A A B A
B E A B
C D D A
D D F E
E F E E
I want to write a program which reads the files and produces a tree, in which the first node is the node from the first line (from above) with the highest number of occurences (so we basically check every first item in each file 'A, A, B, A' in this case. Item 'A' has occured three times so it will represent the root node). Consequently File 3 is ignored.
The resulting tree will be something like
A (3/4 occurrences = 75%)
B ( 2/4 occurrences = 50%) E (1/4 occurrences = 25%)
C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
D (2/4 occurrences = 50%) E (1 occurrence = 25%)
E (2/4 occurrences = 50%) F (1 occurrence = 25%)
SO basically the program should go through the files and construct a tree with a % value of each node. every time branching occurs the % will be divided depending on the number of children.
My question is, is there any specific algorithm / similar algorithms which i can use to overcome this problem ? and What's the best way to visualise the tree?
Your help is very much appreciated
Best Regards
llp00na
|
|
|
|
|
Hi,
I am a bit confused by your example.
It appears that you keep only the highest value for the first line, but keep all values for the following lines.
On the following lines the percentage is based on the number of times the string occurs total, not as part of the tree.
My reading of your algorithum is:
Take the first line from each file.
Find the most common 'first line' value.
Discard all file that do not have this as the first line value
Using all the remaining files, for each line, count how many of each string occurs.
This, to me, is not really a tree.
If it were a tree you would get:
A (3/4 occurrences = 75%)
B ( 2/4 occurrences = 50%) E (1/4 occurrences = 25%)
C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
D (1 occurrence=25%) E (1 occurrence= 25%) D (1 occurrence= 25%)
E (1 occurrence=25%) E (1 occurrence= 25%) F (1 occurrence= 25%)
Could you please clarify what you are after?
Hugh
|
|
|
|
|
thanx for your reply,
The problem is exactly how you understood it. except for your proposed tree,
A (3/4 occurrences = 75%)
B ( 2/4 occurrences = 50%) E (1/4 occurrences = 25%)
C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
D (1 occurrence=25%) E (1 occurrence= 25%) D (1 occurrence= 25%)
E (1 occurrence=25%) E (1 occurrence= 25%) F (1 occurrence= 25%)
unfortunately i cant show you the arrows of the tree. the tree you proposed is correct. if you check level 4 and level 5 of the tree you will see 2 nodes labelled D and 2 nodes labelled E. The only difference between my tree and yours is that I have grouped the two similar nodes in one node (and increased the % to 50 instead of 25% for each node). If i would represent my tree i would have two arrows coming from Node C and Node D (level three) towards Node D in level 4. So a node can get have two parents or more.
Why did i think a tree would be appropriate? I need to store the data of my files into a data structure for later processing. Please if you do have any other / better suggestion i would be grateful.
Regards
llp00na
|
|
|
|
|
llp00na wrote: C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
D (2/4 occurrences = 50%) E (1 occurrence = 25%)
E (2/4 occurrences = 50%) F (1 occurrence = 25%)
What parent node do these child nodes belong to? It would help if you'd line things up so that they are visually intuitive.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanx for your reply;
Unfortunately i cant use arrows to show what i really mean. I will try to explain.
Level 1: C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
Level 2: D (2/4 occurrences = 50%) E (1 occurrence = 25%)
Level 3: E (2/4 occurrences = 50%) F (1 occurrence = 25%)
Node D (in level 2) will have two arrows coming towards it (from Node C and D -level 1-). So the % will accumulate to 50%. Node E is the child of node A.
Node E (in level 3) will have two arrows coming from node D and node E (both are being the parent of E in this case). Node F (level 3) is the child of Node D.
I hope this is clearer.
Regards
llp00na
|
|
|
|