|
Thanks Very Mush I try this and than i will tell you this code works or not. But I have a one more issue:
Probelm....
Main Application Form Code (mainfm)
-------------------------
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new fmapppas());
}
----------------------
Password Verify Form (fmapppas)
==================
if(User not found)
{
Messagebox.Show("Waqas");
}
else
{
mainfm.show();
this.close();
}
1: Now the problem is when user verif than first main form show but
than both forms close means application close.
2: If i write Hide() on the place of Close() in password form then if still running in processes. and when i close main form with application.Exit(); this form close but application still running in prcoessess.
Please help Me..
Muhammad Waqas Butt
Muhammad Waqas Butt
|
|
|
|
|
Thanks for your DB Connection String Help this code works.
But Please also give me this answer
Main Form
--------------
Constructor Method
public fmmainform()
{
InitializeComponent();
fmapppas objfmappps = new fmapppas();
objfmappps.ShowDialog();
objfmappps.Activate();
this.Hide();
}
--------------
Password Form
-------------
if(user == null)
{
MessageBox.Show("Invaild Login\n Please Enter Correct Password",
"Login Error",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
txtpass.Text = "";
txtpass.Focus();
}
else
{
this.Close();
}
-------------
Now Only Password Form Show But if i close Password form with doing work on it mean i close password form from the title bar closing button code
private void evtappclose(object sender, System.ComponentModel.CancelEventArgs e)
{
this.Dispose();
Application.Exit();
}
I want that if password verif than main form show but if user close password form without doing anything. Than application close.
[- The problem is When password is ok then else this.Close(); call now password closing event call than the whole application close. -]
Muhammad Waqas Butt
|
|
|
|
|
Hi
Well this is my first posting at CodeProject and in the past one month or so i had been actively using the codeproject site, it's vast expanse of knowledge base, code snippets and even full source code helps and samples has really impressed me a lot. Now i hope to remain an active member by submitting articles, posting and replying on quries.
here's my first query to the group
In a Web Browser control that i am using (C#.NET Windows app) i want to clear the history of pages that have been browsed, this being done at runtime may be at the hit of a button or after certain no. of pages have been browsed.
Any ideas there.
rgrds
the woods are lovely dark and deep.
but i have promises to keep.
there are miles to go before i sleep...
there are miles to go before i sleep...
|
|
|
|
|
Hi,
while connecting in the local machine there no porblem in the connection string. while connecting to the sql server from another machine through network. i got error of "login failed to uesr null". Sql Server is Windows authentication. Connection string is given below. what's the change need in connection string or sql server. bother machines are windows 2000. any one help to me.
strConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=atc;Data Source=" + m_strServer + ";User ID=sa;Password=;";
Have A Nice Day!
Murali.M
|
|
|
|
|
The wonders of blank sa passwords
You say your SQL Server is windows authentication and then you supply a user (sa), which is a SQL User. Try removing it and ensuring that the application is running as a domain user.
This is not a C# question, please post in the appropriate forum.
|
|
|
|
|
Hi,
thanks for your reply. please make me clear. without providing user name and passport, the error occured then only trying this option. if posssible send an sample.
strConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=atc;Data Source=" + m_strServer + ";";
you can make direct reply to murali_utr@vsnl.net also.
Have A Nice Day!
Murali.M
|
|
|
|
|
I believe you are missing "Trusted_Connection=true;", but even with this addition,
your connection string will only work if you are logged in as a member of the NT domain the server is running on (or a trusted domain) and that user or group has been granted access to the requested database.
Why would anyone waste time arguing with an accountant about anything? Their sole function is to record what happenned, and any higher aspirations are mere delusions of grandeur. On the ladder of productive contributions they are the little rubber pads at the bottom that keep the thing from sliding out from under you. - Roger Wright
|
|
|
|
|
Hi all,
I am design a three layer system in C# (view layer, business object layer
and data layer). But when I look into the J2EE infrastructure, the object
bean(business object) incorporates the SQL data function into the object itself. It seems violates the layer design principles coz it mixes the data layer with the business object layer. But in the other hand, it seems a more OO design coz the business object integrates all those related information into the business object, so when there is a later change in the business object specificiation, the developer needs to change only the business object instead of changing the object and the data layer.
So what approach should I choose ?
Thanks
|
|
|
|
|
Hi everyone!
I want to write a program in C#, that can listen windows messages of a specific program, much like Spy++.
Is there a way of listening windows messages of another program in C#. I would be very greatful if you help me.
Thanks in advance.
|
|
|
|
|
You need to P/Invoke SetWindowsHookEx and register a hook to process/view messages before (and/or after) they are dispatched to their destination windows.
For more information about SetWindowsHookEx , read http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp[^].
There's also a few articles[^] about writing Windows hooks in managed code here on CodeProject. Be forewarned, however, that you are hooking the system at a pretty low level. Make absolutely sure that you understand what you're doing and about marshaling native and managed Types, and that your code runs as efficiently as possible and can recover from errors. If you don't mind any of those things I mentioned you may bring down your entire system.
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 have been given a task to web enable an COM component, and have looked at acheiving this with a c#/ASP.NET solution. All works fine, except the initial creation of the COM component is fairly slow as there is some underlying initialisation occurring. This is currently happing in the one of the webservice methods.
Is there anyway I can instantiate the COM component (via interop wrapper) just the once, and on each web service method invocation call the same instance?
Regards
Glenn
|
|
|
|
|
Normally you should post this in the ASP.NET forum, despite whatever language you're using (since it's specific to ASP.NET), but I'll answer this once anyway.
Store the RCW (runtime callable wrapper, or the "interop wrapper" as you called it - more typically called an interop assembly) in the Application object. This is for application-wide state, similar to how sessions are specific to a user. Only create an instance of the COM object if the key into the application object returns null, and set that state variable once you've created the COM object. If it's not null, then use it.
The Application property is defined for a WebService , so you should have no problem using it:
MyComObject obj = (MyComObject)Application["MyComObject"];
if (obj == null)
{
obj = new MyComObject();
Application["MyComObject"] = obj;
}
obj.DoSomething(); This is one of many ways and is one of the easier ways. If ever the application is unloaded (like when the application or site's Web.config file is changed, or the machine.config file is changed) the COM object is destroyed and will have to be re-initialized.
Storing COM objects in a state service like this can be a performance drain on its own, however. COM objects are not serializable and, if you're running your ASP.NET web application in a server farm, you can have affinity problems since an instance is created on a single server.
To get around this use COM+, or Enterprise Services. Install your COM object as a COM+ object (some modificatio may be necessary, but you can leverage basic functionality from normal COM objects) and use the System.EnterpriseServices namespace classes to make calls on the object. This is definitely outside the scope of this forum, however, so I'll give you some links you should really read. This is probably the best solution to your problem and is one of the many of the features that COM+ was designed for.
Read Writing Serviced Components[^] and about the System.EnterpriseServices Namespace[^]. Also read COM+ (Component Services)[^] in the Platform SDK.
As far as the COM object goes you must make sure that the methods run within an MTA (multi-threaded apartment), otherwise you could hang your ASP.NET application.
In the future, please direct ASP.NET questions to the ASP.NET forum.
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]
|
|
|
|
|
Anyone know how to get a machine's local IP number, other than by parsing the output from IPCONFIG?
|
|
|
|
|
Please refer the following article on CP:
How To Get IP Address Of A Machine[^]
Hope this helps.
|
|
|
|
|
Jay...
Thank you! That's exactly what I needed.
BTW, I really did search CP before posting, but I guess I missed that article.
|
|
|
|
|
|
|
I am curious if anyone has any experience in instanciating/using a singleton object via reflection?
I guess if I have a singleton class like so in a ASP.net application:
<br />
public sealed class Services<br />
{<br />
private Services() {}<br />
...<br />
public static Services Instance<br />
{<br />
...<br />
}<br />
}<br />
and lets say this is a lazy singleton (i.e. not created until the first call to the Instance method). Is there a way for me to work with this instance in a Type Library using reflection. I am sure there must be a way, but I am missing it..
|
|
|
|
|
lcarriere wrote:
Is there a way for me to work with this instance in a Type Library using reflection.
Assemblies are not type libraries, which describe COM types. You can't reflect COM types in .NET, though you can reflect their RCWs (runtime callable wrappers), but that's definitely not the same thing. Type metadata and IL modules are stored in assemblies.
If you want to reflect the singleton in such a way that when you access a property then you shouldn't have a problem if you follow the recommend pattern, in which each property gets an instance - which creates the instance if not created already - and returns a value from the instance using the private instance field. The following example also uses the double-checked locking method, which is the safest way of creating a singleton:
using System;
class Singleton
{
static object sync = new object();
static Singleton instance;
int serialNumber;
Singleton()
{
}
static Singleton Instance
{
get
{
if (instance == null)
lock (sync)
if (instance == null)
instance = new Singleton();
return instance;
}
}
public static int SerialNumber
{
get
{
return ++Instance.serialNumber;
}
}
} Notice how the SerialNumber property uses the static private Instance property, which will create a single instance if necessary. When you reflect the static property SerialNumber and instance gets created.
To reflect static members you need to use the overload that allows you to specify a BindingFlags , providing to it at least BindingFlags.Static . The default implementations like GetProperty search for public instance properties, not static and non-public properties. Other than that you would reflect it as you normally would reflect a type with an assembly.
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]
|
|
|
|
|
I am sorry I meant to say Class Library (to much rum and eggnog last night - just kidding).
Thanks this helps a lot. Do you have a small example of reflecting a static method?
|
|
|
|
|
If you look at the Type.GetMethods documentation - along with the BindingFlags enumeration documentation, it's quite easy:
Type t = typeof(Singleton);
MethodInfo[] methods = t.GetMethods(BindingFlags.Public | BindingFlags.Static); This will gather public static methods. For more options, see the BindingFlags enumeration documentation in the .NET Framework SDK, which is installed by default with VS.NET, can be installed stand-alone from http://msdn.microsoft.com/netframework[^], or is available online at http://msdn.microsoft.com/library[^].
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]
|
|
|
|
|
yes sorry, I should have replied sooner. I discovered the methods you mentioned and it is working perfectly.
Thanks for your help!
|
|
|
|
|
I posted to this board almost a month ago, and no one had a response for any of my questions. Can anyone offer any comments on these topics?
Thanks much.
***********************************
(from 1 December 2004)
I'm a total newbie in the land of C#, Visual Studio, .NET, and all-things-Microsoft. I'm trying to do a number of things with a C# application that has a builtin web browser (AxSHDocVw.AxWebBrowser). Most of the code I've inherited from someone else who knew a lot more about this stuff than I do, so I'm barely treading water at the moment.
If anyone can help shed some light on the following things, I'd be very grateful.
1) Is there a way to control the browser to not display until DocumentComplete has been called (i.e. READYSTATE_COMPLETE)? I want the page to *not* show anything until it's fully loaded, and can't figure out how to do this.
2) Is there a way to modify the UserAgent sent by the browser? Some of the docs have suggested (at least in C++ land) that in the Navigate() method I can postpend to the header argument to add things, such as the user agent. However, I'm not sure that a) this works, or b) what the appropriate syntax is in calling this from C#. I've tried just throwing in a string argument, but am not 100% sure of the syntax, nor did it seem to affect anything.
I've also seen:
http://support.microsoft.com/kb/q183412/
but don't know how I can do something similar in my project.
3) I've tried, unsuccessfully, to make a call to create a desktop shortcut using IWshRuntimeLibrary. Here's my code:
WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(title);
link.TargetPath = url;
link.Save();
This always throws an exception, even when the app is being run by an administrator account. It's a System.Runtime.InteropServices.COMException, and the message is just "Exception occurred." I took this code directly from:
http://www.codeproject.com/dotnet/shelllink.asp
Any idea what might be going wrong here?
Thanks much. Sorry if these questions are too broad. Let me know if I can be more specific.
|
|
|
|
|
dkarlton wrote:
I posted to this board almost a month ago, and no one had a response for any of my questions.
This is a community forum - not a managed newsgroup. Older messages sometimes slip through the cracks as there are times us regulars aren't around to answer questions.
dkarlton wrote:
1) Is there a way to control the browser to not display until DocumentComplete has been called (i.e. READYSTATE_COMPLETE)? I want the page to *not* show anything until it's fully loaded, and can't figure out how to do this.
No. The browser renders objects - including the DOM as certain elements are loaded - as they are read.
dkarlton wrote:
2) Is there a way to modify the UserAgent sent by the browser? ...
While the documentation is not clear, it does state that the second-to-last parameter (PostData ) is a SAFEARRAY (native type), which is a common array type in COM (since native arrays imply no bounds; SAFEARRAY s do). The CLR will marshal a string[] array as a SAFEARRAY but you need to specify UnmanagedType.SafeArray in the MarshalAsAttribute for the parameter. Without defining the interface yourself (instead of using the imported RCW) you'll have to take a chance.
Define a string[] array like so:
string[] headers = new string[] {"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)"}; Then pass headers as the last parameter. It's already a reference type so don't try to marshal it as a pointer. Problems will definitely arise (like, perhaps, an AV exception) if you do.
The important thing is to understand marshaling managed and native types. Read Interop Marshaling[^] in the .NET Framework SDK for more information.
dkarlton wrote:
3) I've tried, unsuccessfully, to make a call to create a desktop shortcut using IWshRuntimeLibrary. Here's my code:
A quick search[^] on "WshShell" returned the following article as the first result: Creating Shell Links (Shortcuts) in .NET Programs Using WSH
[^]. Take a look at the sample project for details, and be sure to read the documentation for the native interfaces. With that information and the marshaling information I linked above it's quite easy.
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]
|
|
|
|
|
Thanks for the info, incredibly helpful.
1) If it's not possible to suspend layout during document load of the browser control, can you recommend a good way to "hide" it until it's finished? Currently, I am using this:
<br />
[DllImport("User32")] <br />
private static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);<br />
<br />
private bool FreezePainting { <br />
set { <br />
if (value && IsHandleCreated && this.Visible) <br />
SendMessage(Handle, WM_SETREDRAW, 0, 0); <br />
if (!value) { SendMessage(Handle, WM_SETREDRAW, 1, 0); <br />
Invalidate(true);<br />
} <br />
} <br />
}<br />
I then just call FreezePainting at NavigateComplete and DocumentComplete. The problem is that the app is essentially "dead" to input during the load. Any novel ideas?
2) I'm a little unclear on how to correctly marshal the argument, for overriding the user agent. I wasn't sure if I should just pass the string[] as the last argument, or if I need to additionally declare marshaling. I tried just simply passing the string[] argument, but it seemed to have no effect. I assume I need to do more than this. Although I think I understand conceptually what is required to bridge the gap between C# code and unmanaged libraries, I'm not sure how to actually do it.
3) I got the shortcut creation to work. The link you gave was actually the same one I had indicated before, as well. The problem I had been having the entire time is that the link title apparently must end with ".lnk". I wasn't aware of this, and never saw this in any documentation. It was just throwing an exception. So one problem down...
Thanks. Appreciate the help!
David
|
|
|
|
|