|
Thanks - I set the defines up as
public const int, seems to be compiling OK.
Since I am a beginner in C#, I don't really know about P/Invoke, marshaling etc. Would appreciate any help.
I am trying to create structures to replace the C structures, ie:
[StructLayout(LayoutKind.Sequential)]
public struct PSOPERATOR
{
public string szOprID;
public string szOprPswd;
}
But when I try to assign values I get an error. Do I need to overload '='???
PSOPERATOR Opr = new PSOPERATOR();
Opr.szOprID = "USER";
Opr.szOprPswd = "PASSWORD";
......PeopleSoftAccess\Class1.cs(112): Invalid token '=' in class, struct, or interface member declaration
|
|
|
|
|
Read the following to learn more about P/Invoke and COM interop:Pay close attention to Platform Invoke Data Types[^] under the first section I linked. For example, a native long is actually a managed Int32 (int in C#), not an Int64 (long in C#).
As far as the error you mentioned, it seems like you're using a different keyboard layout that may not be using character code 61 ('=').
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks very much Heath I will read those articles.
I'm surprised to hear you think the '=' problem is from a keyboard layout. I'm running a US Toshiba laptop, XP media center edition.
The '=' worked fine for assigning values to int variables:
public const int PSMSG_SHORTNAMELEN = 15;
public const int PSMSG_MAXVALUELEN = 30;
Not sure where to go from here....
|
|
|
|
|
"Invalid token" means that the compiler encountered an invalid token. It's possible that invalid whitespace appears before or after the = assignment operator as well. If you click on the Edit menu in VS.NET, there's an option buried somewhere to show all characters. Somewhere there's an invalid token, and if a different = sign was used (there are multiple characters that look like that in the Unicode character set), they would both cause a problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath - I worked it out - the code was outside of main. Newbie mistake...
Thanks for the pointers.
|
|
|
|
|
Oops! I do not believe you wanted to do that!
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
This is cool, were getting the inside scoop.
/\ |_ E X E GG
|
|
|
|
|
I'm creating a user control which constists of a Panel control containing multiple Panel controls layed out in a grid format. I've overridden the WndProc method in my UserControl class to attempt to trap the WM_LBUTTONCLICK message to determine which child Panel in the grid was clicked. However the WM_LBUTTONDOWN messag (0x0201) never makes it to the WndProc procedure. I tested this out by overrriding the WndProc in the Parent Form that my UserControl is in and the messsage was trapped fine, but it appears to stop there. Will the main Form's message pump change the message to soemthing else when it passes it to one of it's child controls ?
I used Debug.WriteLine to see what messages are being sent to the UserControl's WndProc when the mouse is clicked and it seems to be message 33 (0x0021) WM_MOUSEACTIVATE, but its not a reliable message (not sent every click)
Anyone have any input ?
|
|
|
|
|
You have to handle WM_PARENTNOTIFY (assuming the child control notifies its parent of that message), of which the Message.WParam contains the child message as an IntPtr (so declare a readonly static (can't be a const since it's not a primative) to new IntPtr(0x0201) ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I was able to solve the problem by implementing an IMessageFilter in my UserControl. I'm glad you cleared this up for me, since I'm sure I'll run into it again.
|
|
|
|
|
I wouldn't recommend that - it's overkill and can decrease the performance of your application. Just handle the WM_PARENTNOTIFY (0x0210) like I mentioned before:
public class MyControl : UserControl
{
static readonly IntPtr WM_LBUTTONDOWN = new IntPtr(0x0201);
const int WM_PARENTNOTIFY = 0x0210;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_PARENTNOFITY)
{
if (m.WParam == WM_LBUTTONDOWN)
{
}
}
base.WndProc(ref m);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I am currently (at runtime) adding some menu options to a context menu. When the user clicks the added items I need to obtain the text value from the item clicked as well as set it as a checked item.
Any help to do this would be appreciated.
Thanks
Stephen
|
|
|
|
|
My system is in 'push' state right now so I'm limited at checking VS to validate this....but here goes.
First you would create a Context Menu item on the form you want to have the menu popup in.
Next in your code -- for each item you want to add, create a MenuItem. Set the name and subscribe to its' click event pointing all of them to the single event handler in your code. Now the part I cannot verify: add each menuitem via myContextMenu.Controls.Add(myMenuItem);
Now when the right button is clicked you handle the event and show your context menu. When one of the items is clicked on, your event handler is passed the information to it. You will have to investigate the EventHandler method signature either EventArgs passes the menu info or sender is the actual MenuItem.
I'd me more specific if I could run VS right now. Hope this gets you started.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Basically, what theRealCondor is trying to say, is that all the MenuItem s you create should reference the same event handler for their Click events. You then get the MenuItem that was clicked using the first parameter of the event handler:
for (int i=0; i < 5; i++)
{
MenuItem menu = new MenuItem("Menu " + i.ToString());
menu.Click += new EventHandler(MenuItem_Click);
contextMenu1.MenuItems.Add(menu);
}
private void MenuItem_Click(object sender, EventArgs e)
{
MenuItem menu = sender as MenuItem;
if (menu != null) MessageBox.Show(menu.Text + " was clicked.");
} ...and I didn't even need VS.NET.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Remember the bad old days of VB6?
You wanted a global variable, you added a module, and that was it.
I know its bad programming... :p
Now, my app loads one Form only. But, the app has a lot of classes
that are created to deal with network data.
How can I have the app's main Form(the ui) get modified by those other classes?
How do you modify a form's progress bar from another class?
ARgh..
Thanks for your help
Antoine
This by our hands that dream,
"I shall find a way or make one!"
|
|
|
|
|
Pass a reference of the Form instance to the class you want to modify. For example,
OtherClass theOtherClass = new OtherClass(this);
public class OtherClass
{
MyForm myFormInstance = null;
public OtherClass(MyForm frmInst)
{
this.myFormInstance = frmInst;
this.myFormInstance.DoSomething();
}
}
Of course you can always make your Form class have a public static variable to make it accessible from other classes, like so:
public class MyForm : Form
{
public static MyForm TheFormInstance = null;
public MyForm()
{
TheFormInstance = this;
}
}
MyForm.TheFormInstance.DoSomething();
Now as far as using the singleton pattern above, Heath or some other very talented developer will chide me for not mentioning the correct way to do it (when using multiple threads and such). But the above code should suffice if you're just using one Form instance.
#include "witty_sig.h"
|
|
|
|
|
hi!
What is the correct way to do ti when using multiple threads?
Thanks
Antoine
This by our hands that dream,
"I shall find a way or make one!"
|
|
|
|
|
The search button is your friend: clickity[^]
#include "witty_sig.h"
|
|
|
|
|
antoine@orchus-tech wrote:
How can I have the app's main Form(the ui) get modified by those other classes?
How do you modify a form's progress bar from another class?
Your classes are not getting instantiated by the form??? The form could grab this info from the classes after they are created. If you need info established in a class and passed around then you could make that class using the Singleton pattern which involves alot of static methods and getter/setters.
If the form must be modified from outside, then you expose public accessors (getter and setter) for internal fields and pass reference to that form to everyone from the central controller in the app.
antoine@orchus-tech wrote:
How do you modify a form's progress bar from another class?
Go to the C# projects in this site and search for SplashScreen. There is one that is really good and demonstrates the ability of having a smooth status bar based on actual event timings. My class design is as such
main form --> loads main class (contains some static methods etc
main form --> loads splash screen
main form --> calls each init step notifying SplashScreen of event end
main form completes init --> calls SplashScreen with 'all done' event
splash screen goes away.
main form loads MainForm and shows it.
Notice that the main class is still around and everything spawned by the main form has access to that class and its' methods. This is similar to the global thing in VB6 but a purer object approach. Search the net for c# patterns and then check on the Singleton pattern for more info.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Is it not allowed to have unsafe code in an user control that I want to host on a browser? The user control is working properly, and when I compile with the unsafe flag, it stops appearing on the web page. Is there some workaround?
|
|
|
|
|
It depends on the code. There is some stuff that you just cannot do in a browser because it's a security violation. You can't, for instance, P/Invoke code in a .DLL from a browser hosted instance of a control. Manipulating the File System of a client is also a no-no. Let's see a code snippet of what your trying to do and maybe there will be a workaround.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
No, it is just turning on the Allow Unsafe Code blocks in the Project Settings page.
My user control has an Image control, and have raw image bits. I am trying to use BitmapData to render the image bits fast. I think this should not pose a security violation.
|
|
|
|
|
The 'unsafe' switch tags you entire assembly as unsafe code. This means, in IE, that your code isn't safe and won't be executed, depending on the security setting your running in IE and the Code Access Security policies you have setup. You'll have to check with the .NET Framework Configuration tool or the Code Access Security Policy tool and make sure that you can run unsafe code from a remote location. By default, you can't run untrusted code from a remote location, like a component loaded from a server.
You can also start by reading Securing Applications[^] for an explanation about how Code Access Security works and why you can't run Unsafe code in IE and how to make it work.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I'm building a custom control from scratch that is sorta hard to describe...kinda like a futuristic combination of a listview and folder view but not really...eh :P
Anyway i want to make it so when you see this control in the designer and click "Items..." in the properties box that you can add stuff using the vs.net menus like you'd see when you add a column or item to a listview.
Not even sure what this sorta scripting or whatever with the ide is called...reason i didn't just google it
|
|
|
|
|
You are about to enter the fun world of custom property descriptors. That is what you google on.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|