|
This is a known issue in printer monitoring and the only bulletproof solution is to parse the sppol file and count the actual pages sent to the printer yourself.
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
thank you.
but, how can I do this? how can I read the spool file?
thank you again
Sergio
|
|
|
|
|
In Settings->Printers select one printer and in Properties select the check box "Keep documents after they have printed".
Now when you print something the spool file will be in C:\winnt\system32\spool\printers\ directory and you can look at it with a text editor.
Spool files come in a number of possible formats. If it is in EMF format then:
(Note that this format is not documented and will be liable to change
in future releases of the Windows OS family so any code you write
based on this information should be flexible enough to be added to)
Layout of an EMF spool file:
The EMF file consists of a chain of spool records which can be
described as:
Private Structure EMFMetaRecordHeader
Dim iType As SpoolerRecordTypes
Dim nSize As Int32
End Structure
These records are read sequentially to create the printed document.
Currently the record types that I have discovered are:
Private Enum SpoolerRecordTypes
SRT_EOF = &H0 'End of file
SRT_RESERVED_1 = &H1
SRT_FONTDATA = &H2 'Font Data
SRT_DEVMODE = &H3 'Device Mode (DEVMODE)
SRT_FONT2 = &H4 'Font Data
SRT_RESERVED_5 = &H5
SRT_FONT_MM = &H6 'Font Data (Multiple Master)
SRT_FONT_SUB1 = &H7 'Font Data (SubsetFont 1)
SRT_FONT_SUB2 = &H8 'Font Data (SubsetFont 2)
SRT_RESERVED_9 = &H9
SRT_UNKNOWN = &H10
SRT_RESERVED_A = &HA
SRT_RESERVED_B = &HB
SRT_PAGE = &HC 'Enhanced Meta File (EMF)
SRT_EOPAGE1 = &HD 'End Of Page
SRT_EOPAGE2 = &HE 'End Of Page
SRT_EXT_FONT = &HF 'Ext Font Data
SRT_EXT_FONT2 = &H10 'Ext Font Data
SRT_EXT_FONT_MM = &H11 'Ext Font Data (Multiple Master)
SRT_EXT_FONT_SUB1 = &H12 'Ext Font Data (SubsetFont 1)
SRT_EXT_FONT_SUB2 = &H13 'Ext Font Data (SubsetFont 2)
SRT_EXT_PAGE = &H14 'Enhanced Meta File
SRT_JOB_INFO = &H10000
End Enum
So for example a very simple one page print job might consist of an
SRT_DEVMODE record followed by a SRT_PAGE followed by a SRT_EOF.
Within the SRT_PAGE and SRT_EXT_PAGE record is a single printed page
stored as a standard EMF record which can be displayed on screen or
transformed into any other graphics format as you wish. The
structure of this is:
1. EMF Header record which gives the version information and page
size etc needed to scale the metafile
2. A selection of EMF records which describe the infividual graphic
elements of the page (text, lines, etc.) The format of these
individual records is documented on MSDN.
Withing the SRT_DEVMODE is a record which is very similar to the
DEVMODE structure used in printer API calls that specifies things
like the number of copies, print quality, paper source etc.
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
|
Hi.
I have a problem downloading a file from the server into the user's machine.
I have the file in a directory on the server and now I want to download it or save it into the user's machine. The problem is that when I use
Client.DownloadFile(path_file_on_the_server.dat , "C:\\mysavedfile.dat")
or
StreamWriter sr = File.CreateText(fullPath);
it always saves the file INTO the server and not in the user's machine.
I just want to copy the file from the server into the user's machine.
Thank you all in advance
|
|
|
|
|
If the file is shared you can create a FileInfo object using "\\server\path" and then call CopyTo() .
If that doesn't work then have a function return the bytes for the file. Use the FileStream to write to disk. Depending on the size of the file you might want to split the file up.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
I can get the message device tpye DBT_DEVTYP_VOLUME,but my WndProc cann't get the DBT_DEVTYP_DEVICEINTERFACE message device type.My code is:
const int WM_DEVICECHANGE = 0x0219;
public enum DEVICETYPE:int
{
DBT_DEVTYP_OEM =0x00000000,// oem-defined device type
DBT_DEVTYP_DEVNODE = 0x00000001, // devnode number
DBT_DEVTYP_VOLUME = 0x00000002, // logical volume
DBT_DEVTYP_PORT = 0x00000003, // serial, parallel
DBT_DEVTYP_NET =0x00000004, // network resource
DBT_DEVTYP_DEVICEINTERFACE =0x00000005 //device interface class
}
public struct _DEV_BROADCAST_HDR
{
public int dbch_size;
public DEVICETYPE dbch_devicetype;
private int dbch_reserved;
}
public struct _DEV_BROADCAST_VOLUME
{
public int dbcv_size;
public DEVICETYPE dbcv_devicetype;//Set to DBT_DEVTYP_VOLUME
private int dbcv_reserved;
public uint dbcv_unitmask;
public int dbcv_flags;
}
public struct _DEV_BROADCAST_DEVICEINTERFACE
{
public int dbcc_size;
public DEVICETYPE dbcc_devicetype; //Set to DBT_DEVTYP_DEVICEINTERFACE
public int dbcc_reserved;
public System.Guid dbcc_classguid;
//char dbcc_name[1];
}
protected override void WndProc(ref Message devicemsg)
{
_DEV_BROADCAST_DEVICEINTERFACE
DevBroadcastInterface;
DEVICEEVENT Eventtype;
_DEV_BROADCAST_HDR Whicheventtype;
_DEV_BROADCAST_VOLUME DevBroadcastVolume;
uint unitmask;
uint drivenum=0;
StringBuilder thecomingdevicevid = new StringBuilder();
StringBuilder thecomingdevicepid = new StringBuilder();
base.WndProc(ref devicemsg);
if(devicemsg.Msg == WM_DEVICECHANGE)
{
Eventtype = (DEVICEEVENT)devicemsg.WParam.ToInt32();
switch(Eventtype)
{
case DEVICEEVENT.DBT_DEVICEARRIVAL:
{
Whicheventtype = (_DEV_BROADCAST_HDR)Marshal.PtrToStructure(devicemsg.LParam,typeof(_DEV_BROADCAST_HDR));
/*breakpoint*/ switch(Whicheventtype.dbch_devicetype)
{
case DEVICETYPE.DBT_DEVTYP_DEVICEINTERFACE:
{//this case can not be retrieved,why?
DevBroadcastInterface = (_DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(devicemsg.LParam,typeof(_DEV_BROADCAST_DEVICEINTERFACE));
//do something here.
break;
}
case DEVICETYPE.DBT_DEVTYP_VOLUME:
{// but this case can be retrieved.
DevBroadcastVolume = (_DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(devicemsg.LParam,typeof(_DEV_BROADCAST_VOLUME));
//do something here.
break;
}//end case DBT_DEVTYP_VOLUME
}//end switch(pDevBroadcastHdr.dbch_devicetype)
}//end case DBT_DEVICEARRIVAL
break;
}//end switch(Eventtype)
}//end if
}//end WndProc()
Why does the WndProc can not retrive the DBT_DEVTYP_DEVICEINTERFACE message device type?
Thanks!
|
|
|
|
|
Why post the same question twice
Cheers,
Paul Wilson
|
|
|
|
|
Hi!
The first one is too long and I think maybe no one want to read such a long question.So,I changed something to make it more readable.That's why I post the same question twice. If I do something wrong,I just wanna say I'm sorry.
Thanks!
momer
|
|
|
|
|
hi, i've drawn using GDI+ onto a form. now i need to save this drawing as bitmap. i used double buffering. my coding:
bt = new Bitmap (800,600); //delare bitmap
myGraphics = Graphics.FromImage(bt); //declare Graphics
private void btnSave_Click(object sender, System.EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Title ="Save File";
saveFileDialog1.Filter = "Bitmaps (*.bmp)|*.bmp";
if ((saveFileDialog1.ShowDialog() == DialogResult.OK))
{
string strFileName = saveFileDialog1.FileName;
bt.Save(strFileName,ImageFormat.Bmp); //is it the way?
}
}
how do i capture the drawing i did n save it?
Chris
|
|
|
|
|
nuttynibbles1984 wrote:
is it the way?
Did you try it? What happened? Was there an Error?
Your 1 question leads to 3 - go figure.
|
|
|
|
|
i managed to save the bitmap, but the outcome was just this black rectangle. none of my image were capture. i've search many webby, i think this method is correct, or almost
Chris
|
|
|
|
|
|
Hi!
We are seriously looking for an obfuscator. Most solutions are very expensive, but Xenocode[^] is fair priced. Anyone has an opinion on it?
Also, we're not sure if we should buy the basic or enterprise edition. The only feature we'd need in Enterprise would be string encryption, but then again... I'm not sure if we really need this. The basic edition included the ability to crash ILDASM. Would that be enough?
Our application is distributed to a small number of customers (about 50 small businesses).
Is there any other solution in the same price range I should check out?
Thanks!
Carl
|
|
|
|
|
In the follow code:
hDevInfo = SetupDiGetClassDevs(ptrGUID,
null,
null,
DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
if( hDevInfo == INVALID_HANDLE_VALUE)
{
MessageBox.Show("Can not get information set of this device class!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
how to define INVALID_HANDLE_VALUE in my c# code?
|
|
|
|
|
Within your class define the value as the following:
private const UInt32 INVALID_HANDLE_VALUE = 0xffffffff;
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi!Nick,
Thank you very much!I have settled this matter under your help.
Now when I finished my code,I found a nother problem,which I posted it on this board as you can see.
I hope you can give me some tips.
Thank you again!
Best regards!
momer
|
|
|
|
|
Hello,
Now, I develop a tool, this have a button. button's back color is black. When a mouse pointer is on the form( worked mouseEnter event ), button's back color changed white. When a mouse pointer leave a button, button's back color changed black. After that clicked, showInTaskBar is true(when tool start, showInTaskBar is false).
This tool have a problem. Before a button click, mouse event is enable. But after a button click, mouse event is disable.
The following is the code.
private void button1_MouseLeave(object sender, System.EventArgs e)
{
button1.BackColor=Color.Black;
}
private void button1_MouseEnter(object sender, System.EventArgs e)
{
button1.BackColor=Color.White;
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.ShowInTaskbar=false;
}
private void button1_Click(object sender, System.EventArgs e)
{
this.ShowInTaskbar=true;
}
I tried to escape this problem, so I investigate it. But I don't know.
I'd like to do "after a button click, mouse event is enable".
If you have some idias, tell me, please.
cheers,
yu-yu
|
|
|
|
|
Well, you can't disable mouse events, so, the problem is with your code not matching up with what you want to do. What EXACTLY are your trying to do?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello,
Thank you for your mail.
I try to do the following.
1.Usually enable mouse events.
2.Want to change showInTaskBar flag.
So, I develop the tools.
Cheers,
yu-yu
|
|
|
|
|
Hello,
I found this solution.
I make the following code in Button_Click().
private void button1_Click(object sender, System.EventArgs e)
{
Controls.Remove(button1);
this.ShowInTaskbar=!this.ShowInTaskbar;
Controls.Add(button1);
}
Thank you,
yu-yu
|
|
|
|
|
yu-yu wrote:
private void button1_Click(object sender, System.EventArgs e)
{
Controls.Remove(button1);
this.ShowInTaskbar=!this.ShowInTaskbar;
Controls.Add(button1);
}
You don't need to add and remove the button. All you need is the ShowInTaskbar line you have. Removing and adding the button will not change anything.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello Dave,
I don't want to add and remove the button.
But I think to change ShowInTaskBar flag change is changing windows handle, so this condition occuered.
To escape it, I think resetting object. But this solution have limit.
Do you have some ideas ?
yu-yu,
|
|
|
|
|
Hi Everybody,
I have created a client form and webservice application. Now, If there will be a new update or feature on the client side, I don't want to install everything again on the client, in short, I want my web service to update the client automatically. What do you think is the best approach for this type of scenario?
Thanks and sorry for my bad english.
|
|
|
|
|
Since an application cannot overwrite itself when executing you create a small launcher exe that will start the actual application. The launcher needs to be designed in a way so that it will never need to be updated. From here you have to make a decision:
A) Application will notify the user and shutdown after acquiring the new files. User will have to start application again manually.
- Launcher will call file copy code on startup before any assemblies are loaded.
- Launcher will load atual application using reflection.
B) Application will automatically reload assemblies and continue running. No user input will be required for restarts.
- Launcher will load actual application into a seperate AppDomain with ShadowFileCopy set to true.
- When all data is downloaded the launcher will start file copy process.
- When file copy process is complete the original AppDomain will be unloaded and new one will be started.
You have to use an AppDomain because you cannot unload individual assemblies. However you can unload the whole AppDomain . ShadowFileCopy enabled you to write over the files on disk.
Things to consider:
- downloading method
- security. can anyone download your app for free?
- downloading on slow connections
- when to check for updates (startup, poll server?)
- how to check for updates (data provided through webservices, data hosted in file on webserver)
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|