|
Just for documentation sake (we should add this to the article):
[StructLayout(LayoutKind.Sequential)]
public struct BrowseInfo
{
public IntPtr hwndOwner;
public IntPtr pidlRoot;
[Out] public StringBuilder displayname;
public string title;
public int flags;
public BrowseCallBackProc callback;
public IntPtr lparam;
public int iImage;
}
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
static extern IntPtr SHBrowseForFolder(ref BROWSEINFO lpbi);
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thanks for the suggestions, Heath.
I still have one question, how I can get the user Desktop folder, MyDocument Folder etc. ?
I was tried to use Environment.GetFolderPath(); function, but the specialFolder Emun is not in namespace, is it also not supported in dotnet 1.0 version ?
I'm going to make my folder tree, but seems has no method to get the special folder. Do you have any suggestions? Thanks
|
|
|
|
|
Here is the situation, I have a windows form and I want to pass some info from the form to another one, so I thought about puting it in a global variable like in a session based application, how do I do so, and is this the best way to aproach the problem??? If not what should I do then, and how???
Thanks
Oakcool
|
|
|
|
|
Hmmm... I can smell spaghetti... can you?!
|
|
|
|
|
If you can pass the data directly - that would probably be better. However if you really need something like a what you are talking about you can declare a static Hashtable and store whatever you want in there.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
There's no such thing as a "global" variable in the .NET Framework. But, you can use static classes to simulate such functionality. There is an article on MSDN, in the Smart Client Developer Center that describes such a technique. The example code is written in VB.NET, but it demonstrates the concepts and is easily converted to C#. Just look for the section header called "Global data in .NET".
Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks the article was exactly what I needed
Oakcool
|
|
|
|
|
Implement the singleton pattern using a static class:
public class MyGlobalClass
{
private MyGlobalClass()
{
// Init any local info
}
public readonly static Instance =
new MyGlobalClass();
private int someField;
public int someProperty
{
get { return someField; }
set { someField = value; }
}
}
Gary
While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'
- Dilbert
|
|
|
|
|
were should i start, im still reading about neural networks and how to implement them, but how would i make it in a real-life situation, i would like to scan documents from my scanner, save them to a bitmap, and then get the text from it. I would like to expirement and this is just a project i am interested in doing..
|
|
|
|
|
There are some books on Amazon that talk at length about OCR. I've never seen useful info on the web, nor have I done it myself.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi, I have a question about the function SendInput from the Win32 API. Does it send the input to the active application? The documentation states that it puts it serially into the keyboard and mouse streams, but I am calling it as follows: with Notepad or Microsoft Word open
SendInput(1, ref input, Marshal.SizeOf(input));
where input is define as follows:
public struct INPUT
{
public int type;
public MOUSEINPUT mi;
public KEYBOARDINPUT ki;
}
I am getting the information to fill in the structs from another computer, and they are the same, but it does not actually send a keystroke. For example, if I type 'a' on computer 1, then it should SendInput 'a' on the second computer.
Thanks for your help.
Keith La Force
|
|
|
|
|
The SendInput API function only works on the local machine. SendInput sends keyboard and mouse message to whatever application has the input focus at the time. It will NOT inject input into a remote machine's message queues. There is no function that will do this for you.
In order to do something like this, you'll need to write two applications. One to receive and interpret commands and data on what to do (like posting keyboard messages and what keys to post), and a second app to send appropriate commands to tell the first app what to do.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, I'm sorry for the confusion. The app that you describe is exactly what I have setup. I have the SendInput calls in the recieving application, which interprets the data from the sending application, and proceeds to call SendInput.
|
|
|
|
|
Your struct isn't declared correctly. The mouse, keyboard, and (other) hardware input is a union. Right now you're not only mis-aligning your data but more than likely clobbering the stack. To declare unions in .NET, you must use an explicit layout like so:
[StructLayout(LayoutKind.Explicit)]
public struct INPUT
{
[FieldOffset(0), MarshalAs(UnmanagedType.U4)] public int type;
[FieldOffset(4)] public MOUSEINPUT mi;
[FieldOffset(4)] public KEYBOARDINPUT ki;
}
[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT
{
public int dx;
public int dy;
[MarshalAs(UnmanagedType.U4)] public int mouseData;
[MarshalAs(UnmanagedType.U4)] public int dwFlags;
[MarshalAs(UnmanagedType.U4)] public int time;
[MarshalAs(UnmanagedType.SysUInt)] public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct KEYBOARDINPUT
{
public short wVk;
public short wScan;
[MarshalAs(UnmanagedType.U4)] public int dwFlags;
[MarshalAs(UnmanagedType.U4)] public int time;
[MarshalAs(UnmanagedType.SysUInt)] public IntPtr dwExtraInfo;
} The way you've declared it your keyboard data would not even be read because the SendInput function will read the data immediately after INPUT.type , which is your unused MOUSEINPUT . A union is declare in unmanaged code so that, depending on some variable (like type ), data representing different structures is packed onto the stack in the same location (this may, however, affect the bit alignment of fields after the union, which is why unions are typically declared last in a structure - but not always).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi, I changed my code to fix the align problems, but it still does not do the SendInput correctly. Does SendInput send it to the active application? If not, how does it determine what program it will send it to?
Thanks for your help.
Keith
|
|
|
|
|
Given that you don't specify an HWND , logically it targets the foreground window's message pump. This is what you should assume since the documentation does not specify (this is typically the case when no HWND is specified with Windows APIs).
Have you looked at the documentation for the KEYBDINPUT struct to determine to what every field should be set?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
can anyone please explain this code to me. What it is doing in detail? I still don't get the way override TOstring functions are used. This particular one is used in a class that is creating tokens for an interpreter program:
public override string ToString()
{
return "[" + kind.ToString() + "(" + (int)kind + "):" + line + ":" + column + ":" + str + "]";
}
Thank you in advance,
Newbie in tha block
|
|
|
|
|
BelMcGrady wrote:
I still don't get the way override TOstring functions are used
They are used to provide a string representation of the information a class represents.
BelMcGrady wrote:
"(" + (int)kind + "):"
I'm not sure how this would work. There's no default conversion from int to string that I know of.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
|
wow - cool. I will try that out next time I need it
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
BelMcGrady wrote:
can anyone please explain this code to me.
Sure, they are simply overriding what ToString() will produce when the ToString() method is called of the class instance it refers to. kind is some type defined within the class itself, where they are calling the ToString() method on the type of data type that kind represents. The (int)kind portion of the statement is simple a C-style cast of whatever value is held within the data type kind to an integer.
- Nick Parker My Blog | My Articles
|
|
|
|
|
i'm trying to track down why my app sometimes does not remove itself from memory when i hit the upper right hand X close button. what are some of the common things that don't get cleaned that would keep an app from closing down? i only create one other thread in my app, and i know that's not the problem because it wasn't even created yet at the times the app hung at close. thanks
|
|
|
|
|
actually, after further inspection, it appears it might be thread related. after a thread is created, it seems to not clean up sometimes. the thread is cleaned up by calling .Abort() on it. is this a guaranteed way to clean up a thread?
|
|
|
|
|
As MSDN states: "The thread is not guaranteed to abort immediately, or at all. This situation can occur if a thread does an unbounded amount of computation in the finally blocks that are called as part of the abort procedure, thereby indefinitely delaying the abort. To ensure a thread has aborted, invoke a Join method on the thread after calling Abort."
www.troschuetz.de
|
|
|
|
|
Are you hiding any forms? If the form is hidden it doesn't close, therefore the application stays open.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|