|
Here's the code:
// Reference InteropServices;
using System.Runtime.InteropServices;
// define constants for the physical offset values
private const int PHYSICALOFFSETX = 112;
private const int PHYSICALOFFSETY = 113;
// Define DLL and prototype the Win32 API method
[DllImport("gdi32")]
public static extern int GetDeviceCaps(IntPtr hdc, int cap);
// get the device context handle from the graphic object that is being printed
// call GetDeviceCaps to return the offsets
// release the handle to the device context
int unprintableleft, unprintabletop;
IntPtr hdc;
hdc = e.Graphics.GetHdc();
unprintableleft = GetDeviceCaps(hdc,PHYSICALOFFSETX);
unprintabletop = GetDeviceCaps(hdc,PHYSICALOFFSETY);
e.Graphics.ReleaseHdc(hdc);
MessageBox.Show("Unprintable: " + unprintableleft + " " + unprintabletop);
Kyle
|
|
|
|
|
Does anyone know what all the lag is about when I run my C# console apps? It just seems to take ages before it actually start the programs. Is there anything I can do to minimise it?
Thanks in advance
Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.
|
|
|
|
|
What you're experiencing is the JIT taking place. To get rid of it you can run ngen.exe on your executable to pre-JIT it. I think to run ngen you might have to sign your exe. sn -k keyfile.snk creates your keyfile, the docs tell how to get it signed (I'm not at my PC right now otherwise i could give you the code for it )
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Thanks matey, ngen ran without signing the exe. And now my app runs immediately. I think all this stuff should go into an FAQ somewhere. I wonder how many other people are puzzled by the same stuff.
Thanks again, you're a great help
Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.
|
|
|
|
|
Hi,
When I call the Directory.GetFiles() funcion, it returns an unsorted string array.
I would write a sorting algo, but if theres a class that can sort a string array can someone let me know.
cheers
|
|
|
|
|
You can use the static method System.Array.Sort(). This method has overloads for sorting an array in place, for customizing the sort order (non-case sensitive, etc.), or for just sorting sections of an array. The sorting algorithm employed is QuickSort.
--
Peter Stephens
|
|
|
|
|
Is it possible to create a toolband with C# similar to http://www.codeproject.com/useritems/toolband.asp
|
|
|
|
|
argh, can you define template classes in c#???? Or is there an alternative that Microsoft would prefer you to use?
Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.
|
|
|
|
|
No , you can't
With luck , next c# version will support generic programming, until then ...
Cheers,
Joao Vaz
|
|
|
|
|
Templates don't exist in C#, this is coming in Version 2.
There is a "trick" that'll help you get by until then.
using System;
using T = System.Int32;
namespace Test
{
class Testing
{
public Testing()
{
Console.Writeline(typeof(T).ToString());
}
}
}
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Thanks for the response, I wanted to port a generic tree class over to C# but looks like I can't for the minute, or maybe I can. What if the class took a type of Object?
class Testing
{
public Testing(Object arg)
{
m_Object = arg;
}
Object m_Object;
}
I'm very new to C#, but would this work? Also when is version 2 out???
Thanks again
Windows 98 (win-doze): a 32 bit Extension to a 16 bit Graphical Shell of an 8 bit Operating System originally coded for a 4 bit Processor by a 2 bit company that can't stand one bit of competition.
|
|
|
|
|
TheFLC wrote:
What if the class took a type of Object?
That would work, but you would have lots of casting to do (Object could be called the equivalent of void* in C). This is generally the reason that the technique I mentioned came up; while you'll have a specific class for each type of tree; you'll eliminate all casting.
TheFLC wrote:
Also when is version 2 out???
Not for a while, version 1.0 came out a week ago today My guess would be at least a year before version 2.0 comes out.
James
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
No, you can't.
The next version of the CLR will support template classes, and so will be available to all languages that want to support it, not just c#
|
|
|
|
|
the code is in the SDK,but wen i run it,nothing happened,except print "Connected xxx.xxx.xxx",it cann't receive message from the server,but the SDK say it can Receive Message From The Server,why??
The Address in SDK is:ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconnon-blockingclientsocketexample.htm
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
// State object for receiving data from remote device.
public class StateObject {
public Socket workSocket = null; // Client socket.
public const int BufferSize = 256; // Size of receive buffer.
public byte[] buffer = new byte[BufferSize]; // Receive buffer.
public StringBuilder sb = new StringBuilder();// Received data string.
}
public class AsynchronousClient {
// The port number for the remote device.
private const int port = 21;
// ManualResetEvent instances signal completion.
private static ManualResetEvent connectDone =
new ManualResetEvent(false);
private static ManualResetEvent sendDone =
new ManualResetEvent(false);
private static ManualResetEvent receiveDone =
new ManualResetEvent(false);
// The response from the remote device.
private static String response = String.Empty;
private static void StartClient() {
// Connect to a remote device.
try {
// Establish the remote endpoint for the socket.
// "host.contoso.com" is the name of the
// remote device.
IPHostEntry ipHostInfo = Dns.Resolve(Ftp.xxxx.com);
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
// Connect to the remote endpoint.
client.BeginConnect( remoteEP,
new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
// Send test data to the remote device.
Send(client,"USER xxx\r\n");
sendDone.WaitOne();
// Receive the response from the remote device.
Receive(client);
receiveDone.WaitOne();
// Write the response to the console.
Console.WriteLine("Response received : {0}", response);
// Release the socket.
client.Shutdown(SocketShutdown.Both);
client.Close();
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
private static void ConnectCallback(IAsyncResult ar) {
try {
// Retrieve the socket from the state object.
Socket client = (Socket) ar.AsyncState;
// Complete the connection.
client.EndConnect(ar);
Console.WriteLine("Socket connected to {0}",
client.RemoteEndPoint.ToString());
// Signal that the connection has been made.
connectDone.Set();
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
private static void Receive(Socket client) {
try {
// Create the state object.
StateObject state = new StateObject();
state.workSocket = client;
// Begin receiving the data from the remote device.
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
private static void ReceiveCallback( IAsyncResult ar ) {
try {
// Retrieve the state object and the client socket
// from the async state object.
StateObject state = (StateObject) ar.AsyncState;
Socket client = state.workSocket;
// Read data from the remote device.
int bytesRead = client.EndReceive(ar);
if (bytesRead > 0) {
// There might be more data, so store the data received so far.
state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));
// Get the rest of the data.
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,
new AsyncCallback(ReceiveCallback), state);
} else {
// All the data has arrived; put it in response.
if (state.sb.Length > 1) {
response = state.sb.ToString();
}
// Signal that all bytes have been received.
receiveDone.Set();
}
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
private static void Send(Socket client, String data) {
// Convert the string data to byte data using ASCII encoding.
byte[] byteData = Encoding.ASCII.GetBytes(data);
// Begin sending the data to the remote device.
client.BeginSend(byteData, 0, byteData.Length, 0,
new AsyncCallback(SendCallback), client);
}
private static void SendCallback(IAsyncResult ar) {
try {
// Retrieve the socket from the state object.
Socket client = (Socket) ar.AsyncState;
// Complete sending the data to the remote device.
int bytesSent = client.EndSend(ar);
Console.WriteLine("Sent {0} bytes to server.", bytesSent);
// Signal that all bytes have been sent.
sendDone.Set();
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
public static int Main(String[] args) {
StartClient();
return 0;
}
}
|
|
|
|
|
Are any exceptions being thrown?
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Hi,
Any suggestion on handling WM_NOTIFY, LVN_ODCACHEHINT and LVN_ODFINDITEM events from C# app?
-Kasturi
|
|
|
|
|
I am just learning C# and I was wonder if there is a way to make an instance of a class that is globally availible. Anyhelp would be appreciated. Thanks.
Steve
|
|
|
|
|
Can you describe what you mean by "globally available"?
When you say that I'm thinking something to do with the GAC (Global Assembly Cache), but then you refer to an instance of a class.
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Hello,
I have this private assembly, and I want to ensure that it can be used only
in my application. I have signed the assembly using strong name key pair
that I generated.
But when I am calling it dynamically (i.e. Assembly.Load) how can I ensure
security, i.e. check for the public key, so that only my application will be
able to use it coz only my application knows my public key?
Any ideas?
- Tariq
|
|
|
|
|
Role based security uses the OS's security DB to authenicate users (i.e. all the users of a particular application will have an account in the server, right?) If so, how many users can it hold?
|
|
|
|
|
How do I listen to events happening in any particular folder? (e.g. if a new file has been added to the folder or a file is deleted from the folder.)
|
|
|
|
|
System.IO.FileSystemWatcher
There is a cavet though:
(from the docs)
"FileSystemWatcher only works on Windows 2000 and Windows NT 4.0.
Remote computers must have one of these platforms installed for the
component to function properly. However, you cannot watch a remote Windows
NT 4.0 computer from a Windows NT 4.0 computer."
I'm not familiar with the respective Win32 APIs, but if this cavet doesn't exist there you could write some managed C++ to use the APIs directly, allowing you to target Win98/ME.
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Hi,
Im assuming an ArrayList is similar to Java's Vector class, however im having trouble accessing individual elements in the ArrayList and I cant see any methods there to get elements.
someone ?
|
|
|
|
|
You access it just like an array
ArrayList al = new ArrayList();
MyDataType elementZero = (MyDataType) al[0];
MyDataType elementOne = (MyDataType) al[1];
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Hi,
I have managed to get my program to load types successfully, but when it comes to try and invoke a method that they support i get a compile error.
Exception of type System.InvalidCastException was thrown.
The type array has been filled using this short code.
if(null != type.GetInterface(typeof(IPlugable).FullName)) {
Console.WriteLine("Loaded");
loadedTypes[idx++] = type;
}
This is the code which doesnt work. Anyone have a dime of an idea ?
public void LoadTypes(Type[] types) {
IPlugable yer = (IPlugable)Activator.CreateInstance(plugins[x]);
yer.AFuntion();
}
|
|
|
|