|
|
Intellisense do not give you any hints?
No more Mister Nice Guy... >: |
|
|
|
|
|
I think i figured it out how to do.
First thing i set up the textbox properties of the texboxes to binding source next thing i used this code
this.txtAge.DataBindings[0].ReadValue();
this.txtAddress.DataBindings[0].ReadValue();
this.txtCity.DataBindings[0].ReadValue();
this.cboState.DataBindings[0].ReadValue();
this.txtZip.DataBindings[0].ReadValue();
something like this
It worked fine
thanks for the help everyone
Sai
|
|
|
|
|
hi,
I'm developing a web application for my graduation project and it's my first time to use asp.net and C# , the problem is I have an essential part of a code written in C and I need it to be converted or embedded in my project.
I found a couple of converters but they all say that they are not reliable, another problem is that the C code has LOTS of pointers and I'm afraid that I'll mess things up..
is there a reliable converter or a reliable way ? or anyone who can compare both and make sure that they are right ?
Thanks
|
|
|
|
|
To ensure that your C# works properly, you'll probably need to translate the code manually.
The pointers issue isn't really that big a deal, but will require a great deal of diligence and accuracy in your translation. I've never trusted auto-converters between languages. I find they tend to introduce some pretty crazy and hard to find bugs.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
AseelHadlaq wrote: embedded in my project.
You can use 'interop' to call external code in C#.
|
|
|
|
|
How can I use it ? I'm new to C# and can I send and retrieve variables ?
|
|
|
|
|
AseelHadlaq wrote: How can I use it ?
By learning how to use it of course.
You can google for information on it.
|
|
|
|
|
Yea I noticed it was a stupid question, I read about it and I found it a bit confusing and I didnt get the concept of it, can you give me a link where it is explained in a clear way ? and can I send and retrieve variables through interop ?
thank you
|
|
|
|
|
I can't figure out for you if it is clear. You can use the following in google to search for links that would most likely be of help to you.
"C#" interop example -com
This is dependent on you knowing a non-trivial amount of C and having some non-trivial experience in writing code. If you have neither then this is going to be a difficult task. Especially since if you mess it up the most likely outcome will be a system exception and the C# VM will exit will little information.
|
|
|
|
|
All converters will offer a free trial/demo version. Try it out and compare the results with some common sense. Even if the conversion is less than 100%, it may give you something you would have missed.
The main challenge of converting C/C++ code to other languages, especially with pointers, is that a C/C++ declaration alone does not tell you how something is used. This is in contrast to C# where the declaration does tell you all you need to know for a translation to other languages.
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
Instant C# - VB to C# Converter
Instant VB - C# to VB Converter
|
|
|
|
|
thnx I found it earlier but it's not free and I dont know about its reliability , I guess I have to try it
|
|
|
|
|
Conversion isn't usually that difficult once you get underway.
Pointers are fairly straight forward.
In C# all classes are 'reference' types, meaning that a pointer (actually a copy of the pointer) is passed, not the value - so these are often directly interchangeable with C code when translating.
structs are 'value' types so the value is copied rather than the reference. This can be changed by using out or ref to retrieve or pass a pointer.
Only if there is pointer arithmetic involved or pointers to pointers do matters get more complicated. Much of the time, by carefull examination of the code and refactoring it into smaller sections, you will find you can get rid of the pointers altogether
Good luck, and if you get stuck with any individual parts feel free to post.
|
|
|
|
|
That is scary a bit but I have to try ,, thank you
|
|
|
|
|
Use DllImport to get your C functions into your C# project.
If you actually wrote C++ objects, you can create a wrapper for them in managed C++, and the managed C++ dll can be called from you C# code.
|
|
|
|
|
My questions will sound stupid I know
But can I send and retrieve variables ? without changing my C code ?
can you explain more about it plzz
|
|
|
|
|
You might want to start here[^].
AseelHadlaq wrote: But can I send and retrieve variables ? without changing my C code ?
That really depends on how your C is written. In 10 years of working with .NET, I've never found a case where I couldn't P/Invoke because of variables, but that's not to say that some weird and wacky pointer manipulation couldn't cause an issue (although I do recall dealing with a particularly tricky void** parameter that caused some real headaches).
|
|
|
|
|
Hello all. I think I'm over using DirectoryEntry but I'm not sure how to do what I want in any other way.
What this tool is supposed to do is connect to the machines listed in AD and retrieve the members of the "Administrators" group on the local machine.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
using System.Data;
using System.IO;
using System.Xml;
namespace FindAdmins
{
class Program
{
static void Main(string[] args)
{
string connectionPrefix = "LDAP://" + FriendlyDomainToLdapDomain(Environment.UserDomainName);
DirectoryEntry entry = new DirectoryEntry(connectionPrefix);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(objectClass=computer)";
mySearcher.PageSize = 50000;
mySearcher.SizeLimit = 100000;
mySearcher.Asynchronous = true;
mySearcher.PropertiesToLoad.Add("cn");
SearchResultCollection results = mySearcher.FindAll();
Console.WriteLine("Number of machines found: " + results.Count);
int count = 0;
DataTable table = new DataTable();
table.TableName = Environment.UserDomainName;
table.Columns.Add("Machine");
table.Columns.Add("Group");
table.Columns.Add("User");
foreach (SearchResult result in results)
{
count++;
Console.Write(count + "\r");
try
{
DirectoryEntry remMachine = new DirectoryEntry("WinNT://" + result.Properties["cn"][0].ToString() + ",Computer");
DirectoryEntry admGroup = remMachine.Children.Find("administrators", "group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
if (member.SchemaClassName == "Group")
{
object admMembers = member.Invoke("members", null);
foreach (object admMember in (IEnumerable)admMembers)
{
DirectoryEntry membername = new DirectoryEntry(admMember);
DataRow dr = table.NewRow();
dr["Machine"] = remMachine.Name.ToString();
dr["Group"] = member.Name.ToString();
dr["User"] = membername.Name.ToString();
table.Rows.Add(dr);
membername.Dispose();
}
}
else if (member.SchemaClassName == "User")
{
DataRow dr = table.NewRow();
dr["Machine"] = remMachine.Name.ToString();
dr["Group"] = "Administrators";
dr["User"] = member.Name.ToString();
table.Rows.Add(dr);
member.Dispose();
}
}
admGroup.Dispose();
remMachine.Dispose();
GC.Collect();
}
catch (Exception e)
{
}
}
table.WriteXml(@"C:\admins.xml", true);
mySearcher.Dispose();
entry.Dispose();
}
public static string FriendlyDomainToLdapDomain(string friendlyDomainName)
{
string ldapPath = null;
try
{
DirectoryContext objContext = new DirectoryContext(DirectoryContextType.Domain, friendlyDomainName);
Domain objDomain = Domain.GetDomain(objContext);
ldapPath = objDomain.Name;
}
catch (DirectoryServicesCOMException e)
{
ldapPath = e.Message.ToString();
}
return ldapPath;
}
}
}
|
|
|
|
|
And your question is?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
LOL, forgot the question.
So, I'm thinking my implementation is leaky and slow due to the over usage for DirectoryEntry. IS there a less memory leaky and faster way to do this?
|
|
|
|
|
Erick Kinnee wrote: IS there a less memory leaky and faster way to do this? No idea. That's what development is about, finding the answers.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
What is "over usage"? My apps are using a lot of ints, do you think it could leak memory due to that? It won't, and speed is not an indication for a memory-leak. The amount of used memory is an indication.
A few remarks on the code;
if (member.SchemaClassName == "Group")
{
object admMembers = member.Invoke("members", null);
foreach (object admMember in (IEnumerable)admMembers)
{
DirectoryEntry membername = new DirectoryEntry(admMember);
DataRow dr = table.NewRow();
dr["Machine"] = remMachine.Name.ToString();
dr["Group"] = member.Name.ToString();
dr["User"] = membername.Name.ToString();
table.Rows.Add(dr);
membername.Dispose();
}
}
else if (member.SchemaClassName == "User")
{
DataRow dr = table.NewRow();
dr["Machine"] = remMachine.Name.ToString();
dr["Group"] = "Administrators";
dr["User"] = member.Name.ToString();
table.Rows.Add(dr);
member.Dispose();
}
Reads to me as;
if (something)
membername.Dispose();
else
member.Dispose();
I'd expect something along these lines;
foreach (object groupMember in (IEnumerable)members)
{
using (var member = new DirectoryEntry(groupMember))
{
if (member.SchemaClassName == "Group")
..
You could gain some speed perhaps, if you had a thread for each result in there. Depends on how many results and how many cores your CPU got. A progressbar is often appreciated for longer-running tasks.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for your answer.
I disable AppDomain.GetCurrentThreadId(), but I continue to get error.
Regards
|
|
|
|
|
So what you want? Be more specific..
|
|
|
|
|
Saridakis Manolis wrote: Thank you for your answer. I disable
AppDomain.GetCurrentThreadId(), but I continue to get error.
What answer? Is this from some other thread? If so, you should continue on that thread.
|
|
|
|