|
Hello,
In order to open an existing project in vc++, we usually click on the .dsw file. This automatically loads all the files related to the project into vc++.
I want to create a program which saves data into a file with .spa extention. When the file is later clcked on, it should automatically opens into the program. Similar to .doc of MS Word, .m file of Matlab etc.
Please can you guide me on how to do this?
Thanks.
Fortitudine Vincimus!
|
|
|
|
|
This happens automatically if you create an SDI or MDI application. Otherwise, you'll need to create a .reg file, and then call the RegisterShellFileTypes() method in conjunction with EnableShellOpen() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thank you. I got an idea.
Fortitudine Vincimus!
|
|
|
|
|
Hey guys and gals,
I have a question about obtaining the serial number of a USB device via the USB connection. Ive searched the MSDN documentation, and I know I have to use the _MEDIA_SERIAL_NUMBER_DATA structure, and a call to the DeviceIoControl() function with the IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER flag as the second parameter; however, the documentation is unclear as to the proper way to open the device using CreateFile() to obtain the HANDLE for the first arguement for the DeviceIoControl()function. Any help or suggestions would be greatly appreciated.
|
|
|
|
|
VonHagNDaz wrote: ...the documentation is unclear as to the proper way to open the device using CreateFile() to obtain the HANDLE for the first arguement for the DeviceIoControl()function.
HANDLE hDrive = CreateFile(driveName, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks David,
I should have been a little more specific. The device im trying to get the Serial Number from is an Epson C86 printer. I need the Serial Number as displayed when you examine the device using a program such as USBview. Under the driveName variable in the above sample code, Ive tried things such as the iProduct tag, the iManufacturer tag, and even the hub address i.e. USB#ROOT_HUB#4&379abcce&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8}, and I always get the INVALID_HANDLE_VALUE error.
|
|
|
|
|
Maybe my idea is bad, it is just a suggestion: wouldn't it possible to obtain this information through the registry ? I suppose it will be easier that trying to get it via the driver, because you will need to know which IO code to send to the driver and everything.
It is just a thought.
|
|
|
|
|
Cedric,
That is a nice suggestion, I'll look into that. What im trying to accomplish is: suppose a customer(I work for a small printer modification company) wants to use multiple printers so they can send differnt jobs to diffent printers. What were trying to accomplish is an automated approach to minimize customer effort so they can manage everything through our software and take out any "complicated" steps that may detract them from our product
|
|
|
|
|
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();
}

|
|
|
|