|
|
Does anyone know how I would display the date that my program has been installed on a system? Also would anyone know how I would display the date(most recent) a report I have made in crystal reports has been printed?
|
|
|
|
|
An installation date is specific to the installer technology used to install the product. Windows Installer, for example, writes a registry key named InstallDate in the format YYYYMMDD. Looking at my Uninstall reg key (HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall), most of the installers besides Windows Installer don't.
If you want to have a printed date on your reports, then Crystal Reports already has support for that (just like the Office products like Word let you insert a print field). I don't remember what the field name is right off hand, but if you read the documentation for the Crystal Reports designer (or just search through the list of available fields when designing your report) it should be obvious.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hi everybody! First post here, I have a question which might be simple but who knows...
You know about the SendKeys class, right? It lets you send keystrokes to another Windows application. Well, my question is, is there anything similar which will let me send mouse clicks to another application?
In case you're wondering why I want to do this, no, I am not planning on writing any trojan horse software! I'm just going to write a sort of plugin for a strategy game I have which would replace the starship design module of the game - except the game doesn't support plugins, so I'm going to do it as an external program, and I want to be able to save the user a lot of repetitive clicking - in Space Empires IV, you have to click 750 times to add 750 "plasma projection armors" to your ship (should the mod you're playing have components small enough to fit 750 of on a ship!), but in my program you would just type in 750 and it would do the clicking for you!
Thanks in advance for any help!
|
|
|
|
|
This has been asked many times in this forum. The answer is to P/Invoke SendInput . See http://pinvoke.net/default.aspx/user32.SendInput[^] for the method signature. This sends the input to the foreground window. If you have simple input you want to send (keyboard input only), you can use the SendKeys class, which also sends input to the foreground window.
This means that your application should switch the other application to the foreground before sending input. There are many ways of doing this, such as getting the processes using Process.GetProcessesByName , getting the MainWindowHandle , and pass that to a P/Invoke'd SetForegroundWindow (see http://www.pinvoke.net/default.aspx/user32.SetForegroundWindow[^]).
There are other ways but these deal with Windows messaging, something you should understand before trying to use. You can learn more about Windows messaging in the Platform SDK in the MSDN Library[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks!
Now I've heard bad things about PlatformInvoke... I know for one it's platform-specific, of course, but is there anything else I should be aware of before I go using it willy-nilly?
|
|
|
|
|
Bad things? Besides not being portable code... What bad things?
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
P/Invoke is used throughout the entire .NET Framework Class Library (FCL). Almost all the Windows Forms controls, for example, "simply" encapsulate the Windows Common Controls. They P/Invoke many native methods, send and handle messages, etc. Many other classes in the FCL P/Invoke native functionality.
Sending input is platform-specific anyway.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I've developped a Windows Application that needs to know the list of all the files that are opened in all running instances of MSDev (Visual Studio 6.0).
Thanks to Mr H. Stewart I succeeded in getting the files of one instance : the first that has been registered in the ROT (running objects table)... but despite having tried many differents ways, I can't manage to get the files opened in the other instances.
Hereafter is the latest version of my code which uses iteration through UCOMIEnumMoniker and calls UCOMIRunningObjectTable.GetObject for each UCOMIMoniker. Even so, these objects are seemingly all representing the same first MSDev instance...
using Microsoft.Win32;
using DSSharedObjects;
public static string[] ImportFilesFromMSDev()
{
ArrayList AL = new ArrayList();
try
{
object[] Objects = GetActiveObjects("MSDEV.APPLICATION");
foreach( object Obj in Objects )
{
DSSharedObjects.IApplication App = Obj as DSSharedObjects.IApplication;
if ( App==null ) continue;
DSSharedObjects.IDocuments Docs = App.Documents as DSSharedObjects.IDocuments;
if ( Docs!=null && Docs.Count>0 )
foreach ( DSSharedObjects.IGenericDocument D in Docs ) AL.Add(D.FullName);
}
}
catch{}
return AL.ToArray(typeof(string)) as string[];
}
[DllImport("ole32.dll")]
private static extern int GetRunningObjectTable(int reserved, out UCOMIRunningObjectTable prot);
[DllImport("ole32.dll")]
private static extern int CreateBindCtx(int reserved, out UCOMIBindCtx ppbc);
private static object[] GetActiveObjects(string ProgId)
{
ArrayList objs = new ArrayList();
UCOMIRunningObjectTable prot;
UCOMIEnumMoniker pMonkEnum;
GetRunningObjectTable(0,out prot);
prot.EnumRunning(out pMonkEnum);
pMonkEnum.Reset();
int fetched;
UCOMIMoniker []pmon = new UCOMIMoniker[1];
while( pMonkEnum.Next(1, pmon, out fetched)==0 )
{
UCOMIBindCtx pCtx;
CreateBindCtx(0, out pCtx);
string str;
pmon[0].GetDisplayName(pCtx,null,out str);
try
{
RegistryKey Clef = Registry.ClassesRoot;
if ( Clef!=null )
{
int P1 = str.IndexOf('{');
int P2 = str.IndexOf('}');
if ( P1>0 && P2>P1 )
{
string ClassHive = @"\CLSID\"+str.Substring(P1,P2);
RegistryKey SK = Clef.OpenSubKey(ClassHive+@"\ProgID", false);
if ( SK!=null )
{
string Val = SK.GetValue("") as string;
if ( Val!=null && ProgId==Val )
{
object objReturnObject;
prot.GetObject(pmon[0],out objReturnObject);
objs.Add(objReturnObject);
}
}
}
}
}
catch {}
}
return objs.ToArray();
}
Any idea ??
Best regards,
- Éric -
|
|
|
|
|
Have you actually tried breaking into your GetActiveObjects method with the debugger and see if the while loop is entered twice? Looking at your code, there's a lot of problems , especially with the way you're using the IBindCtx s. I recommend you read over the COM documentation in the Platform SDK, especially the IBindCtx and IMoniker . Most of your code is just fine, but some of those problems could lead to what you're experiencing.
To note, you will see a CLSID (Item Monikers) for msdev.exe for each instance. You can use irotview.exe in the Common\Tools directory for Visual Studio 6.0.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes, I've worked with the debugger : the while loop is entered twice (and even one time per MSDev) but it seems that the call prot.GetObject(pmon[0],out objReturnObject) always returns the same object. Therefore I get each time the same list of files.
Well I've already tried to read carefully the COM documentation but I got lost and bogged down in too much detail (in the more so as I'm not so familiar with english).
I'm groping...
If you would mind guiding me a little bit more to get the ActiveObject for each MSDev, it would be very kind of you
What is the right way to use IBindCtx here ?
Kind regards,
- Éric -
|
|
|
|
|
Ah...details: the heart and soul - and bane - of COM programming. It is a wild beast and difficult to tame at times.
When you say you're getting the same object, what exactly do you mean? The Item Moniker will be the same because the same moniker (though referring to different instances) is registered in the ROT. Do you get a duplicate file list or something?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I mean that after calling this method :
object[] GetActiveObjects(string ProgId)
{
while ...
{
prot.GetObject(pmon[0],out objReturnObject);
objs.Add(objReturnObject);
}
}
I get an array of N objects (N=number of MSDev instances) but when casting them into DSSharedObjects.IApplication and asking for the App.Documents I get for each one the same array of files...
Ahhh... (sigh) If only I could get different DSSharedObjects.IApplication objects !
- Éric -
|
|
|
|
|
I'm sorry, but I really don't know what's wrong in that case. Out of curiosity, though, does the documents list for one application object contain a complete list of all documents open in all instances of msdev.exe?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
No, the documents list for one application object contains only the list of the documents open in the first instance of msdev.exe in the ROT. No way to reach others. So it seems that all application objects represent the same one.
So finally all I have is the number of msdev.exe and I can interoperate with only one
I'm sure it's possible... what a pity to be in a deadlock
Anyway, thank you all the same !
- Éric -
|
|
|
|
|
Hi!
I am trying to grasp the usage of SOAP extensions, and was wondering if someone can help me with this scenario:
I have a command line client which invokes a webservice. In response, the webservice is sending some XML which I would like to validate. I understand that in the case where a client _calls_ a webservice, validation can be done in a SOAP extension for the request that is coming to the webservice. The same thing can be done for a request that is outgoing from the webservice.
In my scenario, the called webservice does need to know (or does not care)about validation, it simply sends out the response. I am not sure how I can validate a response from this webservice to my client (at the client side).
Can I use a SoapExtension here? In which case, how would I configure the client so that when it receives a response, the extension is used?
Thanks in advance!
|
|
|
|
|
There are no configuration sections to configure SOAP extensions on the client. Often times you can attribute your proxy methods with SOAP extension attributes to understand the extensions.
You should take a look at Web Service Enhancements 2.0, OR WSE 2.0, that was just released yesterday. These are classes that implement industry standards (like WS Addressing, WS Security, etc.) that make extensive use of SOAP extensions. That should provide quite a bit of insight, especially if you install the SDK and look over the examples.
Otherwise, you're responsible for parsing the SOAP extensions yourself on your client.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How to use this DBNull.IConvertible.ToDecimal Method
|
|
|
|
|
IFormatProvider formatter = CultureInfo.InvariantCulture.NumberFormatInfo;
decimal d = ((IConvertable)DBNull.Value).ToDecimal(null); When you see an explicit interface declaration like that, you must first cast it to the interface; then you can call the explicit interface method implementation (or get/set a property or handle an event).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
But I am getting I dont have reference to assembly...
do i need to include any classes..
Thanks for the immediate reply
|
|
|
|
|
You need to reference all necessary assemblies (in this case, mscorlib.dll which is always referenced unless you tell the compiler otherwise) and import the System namespace:
using System;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am able to do that...
after that also i am unable to convert DBNull value to decimal...
I have a decimal , if nothing is there in that i need to assign a dbnull value to that , but i am not able to do that
Once again thanks for the immediate response
|
|
|
|
|
Because DBNull.IConvertible.ToDecimal always throws an InvalidCastException . But I answered what you asked.
You might want to be more specific about what you're trying to do. If you need to insert a null value for a decimal field in a database, then you actually use DBNull.Value , not the decimal equivalent (which isn't even possible since value types - such as the primative types - can't be null).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there anyway i can do that......
|
|
|
|