Issue when running a Process under a user's context - High Hi,
I am trying to execute a dos command under a different user. Following is the code..
// We create a process, assign its ProcessStartInfo and start it
System.Diagnostics. Process proc = new System.Diagnostics. Process ();
proc.StartInfo.UserName = "UserName" ;
proc.StartInfo.Password = passwd;
proc.StartInfo.Domain = "DOMAIN" ;
proc.StartInfo.UseShellExecute = false ;
proc.StartInfo.FileName = "cmd" ;
proc.StartInfo.Arguments = "/c dir" ;
proc.StartInfo.RedirectStandardOutput = true ;
proc.StartInfo.CreateNoWindow = true ;
proc.Start();
// Get the output into a string
result = proc.StandardOutput.ReadToEnd();
The last line gives me the output of the command execution. When I try executing a command under the default login i.e. without providing any username, password and domain name, the command gets executed properly. But when I try to execute this command under some user's context, it throws an exception S ystem.ComponentModel. Win32Exception --> "The handle is invalid.". Also, this exception is raised when we include the following line of code :
proc.StartInfo.RedirectStandardOutput = true ;
Can somebody help me in resolving this problem
Thanks a lot !
-Sandeep Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

C# interop - passing array of struct to a DLL. Thanks for the answers folks, that looks to be exactly what I needed to know.
2 quick points while I go and make the amendments you've suggested:
1. Maximum results issue from the first answer post. I can actually find out what the max number of results will be, so hopefully I can add that to the marshaller instruction as suggested.
2. I take it that on the C++ side I can just say:
__declspec ( dllexport ) bool SearchTest(SID_SEARCH_RESULT_DATA structArray[], int &size)
{
// populate structures in array
// set size parameter
// return successful
}
Rather than do anything horribly exciting with pointers to the passed in array Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Process from Windows Service I solved my problem. There is no windows service fault. it is my wrong. The process move files to system32 directory because of my wrong argument.
Sorry for disturbing you... Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

How can I quit the execution from the recursive function? Thanks. Actually it should quit the recursion once it meet certain condition else it should continue with the recursion.
If you see the code in my first update, I am checking for .csproj / .vbproj and set a bool flag and it should quit the recursion at that point. But it does not work in my case. It keeps continuing with the recursion. Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Save an Array (Collection) to a DAT file? I need to check if the DAT file contains a string, then write a string (add a string) to the DAT file if it doesn't.
The DAT file can start out empty.
How can I do this using the post idea "Save contents of list view"
Thanks, Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Math with datetime?? There is no "one" answer to this problem. It is all a matter of how you define "age". You haven't provided a rock solid definition of "age" (which, of course, needs to say what to do about the differences in the number of days per month). Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Converting date to system current date time format I think that this code is not as you expose. There must be something between, which probably change CurrentThread culture. Because when you want to see what is in EffectiveDate, what is presented is the ToString() result of the variable. So if You did succesfully parse the data as you write "15/01/2007" that means ShortDatePattern is dd/MM/yyyy. But when you check the variable it is presented as in format MM/dd/yyyy. Probably you have changed the CurrentThread to "en-US" but you didn't return it back to the previous one. To make a check why don't you check ShortPatern at the point when you check EffectiveDate value.
Also, using ParseExact for converting string to date is the right way to do. TryParse and even more Parse should not be used for DateTime. Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Debugging system error Hi All,
I ran into a problem yesterday whereby I get the followig system error when I try to debug a basic "Hello world!" Windows application:
"Error while trying to run project: Unable to strat debugging.
The binding handle is invalid."
When I first wrote the application it worked no problem. I also installed XNA development SDK but don't know if that broke anything. Funny enough I get a different error when I try to run the sample MySpacewarWin1 (but can't seem to even open this one now...).
Running: XP pro on a IBM T41 with 512MB RAM, 1.6GHz Intel Pentium M...
Is there a way of fixing this error Obviously I would prefer being able to debug...
Thanks!
Pano Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

C# backgroundWorker with C++ Hello,
I have a new C# application that we have develop in the last couple of weeks, and now we call it from a C++ application and run it in that solution. From that, it's works fine (with the \clr enabled).
The problem that we've got, is that we use, in the C# app, a BackgroundWorker, which work fine in "local" mode (Alone, without C++). But when we run the same BGW with the app embedded in the C++ app, we've got a cross-thread exception.
We try to figure where come the problems, we look the thread that runs, and there is the bug...
In local mode, the BGW_doWork is running in a other thread, calling the ProccessChanged in the main thread(with the UI), that the good behavior, but when running embedded, the BGW_doWork is running in a other thread, create a new thread when reporting progress (that's not good), and calling the ProccessChanged in the same thread as the BGW_doWork is running(That's really not good !! ) and then we got the cross-thread error.
So, we want to know if the BGW isn't ready for that kind of application and how can we make it works!
I know that only a few people running C# along with c++ in the same application, so this might be tough questions to answers.
Thanks Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

failed to get C#2005 file from PC to another PC If it's a compile error you'll have to post the error code and description. If it's a runtime error you'll have to post the exception and details. We could go forever guessing what you problem is. Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Converting from IntPrt to int32[] I try to do exactly the opposite. Access to a managed byte[] from unmanaged c++.
And it would be a LOT better no to have to copy the data.
You seem to say that this is not possible to work without copy. But dotNet exposing COM does!
I wrote a managed component exposing a managed byte[] to COM, with the following methods.
byte[] GetData() (in C#)
void CheckDataChanges()
From a native c++ application, I acces the managed object through COM.
GetData() returns a SAFEARRAY. I modify the data using classic native arrays access, and then I call CheckDataChanges, and the managed code sees the modified data.
So there was no copy. And also no memory alignement problems on more than 400MB!
Any idea how to do the same magic (managed and unmanaged arrays referring the SAME data) without COM Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Get custom type by sting-parameter First you'll need to make sure the assembly is loaded:
string assemblyname = "......"; Assembly.Load(assemblyname);
Then you need to get the Type:
string typename = "......"; Type myType = Type.GetType(typename);
Then you just have to create it:
object myInstance = Activator.CreateInstance(myType); Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

C# 2005 to VB.net 2005 Project conversion? I believe that SharpDevelope will do the conversion for you as well. For that matter, its not a bad C# IDE for the price (free). Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

array combinations Hi, Thanks for the reply. Yes, the second option is what i am expecting........
(AB,AC,AG,AH, BA, BC, BG, BH, CA,CB,CG,CH, GA, GB,GC,GH,HA,HB,HC,HG)
Any idea about it
Thanks in advance............ Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

How To iterate Through array 2 dimension I've got a couple of ideas...but I'm not sure what you're asking for...
You have the single input array with two dimensions:
int[] input=new int[] {{0,0,0,1,1,8,8,5}{1,2,1,5,5,6,6}};
but in your example you say you need a 2-dimensional output...but based on your example it looks like you need 2 2-dimenstional arrays of output. Can you please clarify
Is it actually a single array of integers returns a 2-dimensional assar of pairs and then this operation has to be performed twice Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Culture independent "Convert.ToDouble" Your variable itself does not matter what culture you are using. The only time the culture comes to play is when you want to display the value to your screen - I.E. send it to a string
Parse(string s, IFormatProvider provider) Converts the string representation of a number in a specified culture-specific format to its double-precision floating point number equivalent.
http://msdn2.microsoft.com/en-us/library/system.iformatprovider(VS.71).aspx
http://msdn2.microsoft.com/en-us/library/system.globalization.cultureinfo.createspecificculture.aspx Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

References not getting set hi,
Also what I noticed yesterday was that when I change the file in CVS Eclipse by right click and save while comparing and taking the changes, its not popping up the dialog until I build the application.
regards,
Cati Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Convert ArrayList to byte[] I am using ArrayList to store a number of byte element. In the end of the day, I want to convert the ArrayList to byte[]
This is how I do.
Code Snippet
ArrayList arr = new ArrayList ();
arr.Add(0x1b);
arr.Add(0x41);
arr.Add(0x1b);
arr.Add(0x46);
arr.Add(0x44);
...
...
byte [] data = new byte [arr.Count];
data = ( byte [])arr.ToArray( typeof ( byte ));
But I got runtime InvalidCastException. At least one element in the source array could not be cast down to the destination array type.
Please help. I will reward you. Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

number of files in a directory I'm
having a problem getting the number of files in a directory in an
efficient manner. currently my c# program uses the
Directory.GetFiles(path).Length to get the number of files in a single
directory. This works but takes a very long time for directories
with a lot files, 10,000+. A couple of the directories contain ~300,000
small files. So is there an easier way to get this number or am I
stuck with what I'm doing The GetFiles method is creating a very
large collection of strings with all the names of the files when I
don't use this information at all. Thanks for the help!! Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Code Generator (winforms) Tutorial/example Hi, I am soon to start writing a database application (winforms). I am planning on using a .net framework type thing (MS SQL Backend, C# winforms frontend). While I am an experienced developer in other environments, I have little experienced in a .net environment (besides some C# open source project I work on). My research so far as has indicated that for such an application, I should use a code generator to assist me. Right now, I am leaning towards codesmith/nettiers. The problem is, I dont know how to use them. I can install them, and generate the code easily enough (there is adequate instructions on the net for this), but I dont know what to do after this. While there are plent of tutorials on how to build a winforms database application via other means, I have not found one which shows how to do it using generated code (such as codesmith/nettiers). So, my question is, can someone direct me to a tutorial or example of what I should do with my generated code It doesnt have to be C# (VB.NET will do - I can go off that). Thanks. Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Playing an mp3 Byte[] Array how? well one way would be to write it to disk, then play it in either an embedded WMP component or launch a process on the mp3 file. Example:
System.Diagnostics.Process.Start("filename.mp3"); Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Parent class, not base Hi,
So if the field is Private, the only reflection is the way to go.
But keep in mind that you can create a property for accessing that member.
You do need to think about designing it right, meaning that you can choose to inherit from class1 and creating a Protected property to that private member.
I hope this helps,
guy kolbis Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Hi, I need help in C# HI, Thanks for the help
But I got into anothe problem,
If I got something like this " How is your day going"
I am writing a loop and in this loop I am detecting whether the string is red, bold, underline....
so if I turn my rich text box into an array
//What I did here is when I click the tab control of SourceView, it will scan everyword and determine the font style, font color.....
string [ ] designer = rtbDesignerView.Text.Split(' ');
string [ ] source = rtbSourceView.Text.Split(' ');
for(int i = 0; i < designer.length; i++)
{
//How do I write the code here to detect if the string is bold or red or anything
//I got something like this
StringBuilder text = new StringBuilder(source );
if(designer == Color.Red)
{
text.Append("[/red]");
text.Insert(0, "[red]");
source = text.ToString();
}
}
But what should I write to know if the string array is bold or not, or anything Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

moving auto generated event handlers? Adam Bretz wrote:
You could make the frmMain.cs a partial class. Implement all the logic in one part and all the events in another. I don't know how the IDE will react to that, but it will at least keep the file shorter. Hope this helps.
Thanks, that's what I'm doing now. frmMain is already a partial class when the IDE is used to add a new form so that part is already taken care of for me. It's just that even with event handlers alone, some form files get quite large.
Steve Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

Using a #define statement I'd also like to point out that #define in C# is not the same as it is in C++ #Define C# #Define C++ Basically you're limited to Define in c defining a symbol and can check if a symbol exists or not using #if In C# you could not do something like: #define backcolor = Color.Blue ... this.BackColor = backcolor; develop your own class or structure, use static constants, or use the provided resources from .net framework Tag: Visual C# General Using multimedia timer with managed C++ Visual C#

SW Sam

I need a timer with the resolution of the multi media timer and the timeSetEvent function but it is not supported with CLR.

Is there an alternative with CLR

If not, Is there a way to use the multi media timer with CLR and be able to pass a managed object as an argument to the timeSetEvent call to be used in the timer callback

Re: Visual C# General Using multimedia timer with managed C++

nobugz

Here's a sample application that uses timeSetEvent(). A couple of problem I ran into when developing it. The IDE debugger can't handle the callback, avoid breakpoints in that code. I had trouble shutting down the timer with timeKillEvent(); calling Invoke() caused a strange ObjectDisposedException and asking for a synchronous kill just hung the program. Please post back any improvements you make. Good luck!