|
|
I am translating some code from VB to C# all was going swimmingly until I hit these lines :
Const SC_MP = &HF170&
Public Const M_ON = -1&
Public Const M_OFF = 2&
Const WM_SYSCOMMAND = &H112
Now I assume that these are int declarations but what format are they in and how can I translate them to standard hex/number representations
|
|
|
|
|
They're hexidecimal, or base 16 numbers (at least the first and last ones). In C# they'd look like this:
const int SC_MP = 0x0170;
public const int M_ON = -1;
public const int M_OFF = -2;
const WM_SYSCOMMAND = 0x0112;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hai there,
i got little bit information about Borland C# Builder. give me some detailed information about this. And Recomanded books or CDs
hai, enjoy coding
Sreejith SS Nair
|
|
|
|
|
sreejith ss nair wrote:
give me some detailed information about this.
Ever heard the word "please"? You often demand things from others on this site. There's not a languages I've heard of that doesn't have a word similar to "please".
If you want information about Borland's C# Builder, the logical place is their web site[^]. There's plenty of whitepapers to download.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How to compare two files,like "Microsoft Visual SourceSafe"!
Code by C#!
I am English is poor!
thank you!
|
|
|
|
|
Comparing files isn't something for beginners. Start basic. If you don't already know the types of pattern matching algorithms for comparing text files, then do it the easy way. Redirect the output from a new Process you can create using the FC command or various console-based diff tools out there, like that in cygwin[^] ('diff').
A .NET console application that wraps the FC command (it's not an application, but an interpreted command in the command shell) would look like this:
using System;
using System.Diagnostics;
public class Diff
{
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.Error.WriteLine("You must provide two filenames.");
Environment.Exit(1);
}
string cmd = "cmd.exe";
if (Environment.OSVersion.Platform == PlatformID.Win32Windows)
cmd = "command.exe";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = cmd;
p.StartInfo.Arguments = string.Format(
@"/c fc ""{0}"" ""{1}""", args[0], args[1]);
p.Start();
p.WaitForExit();
string line = p.StandardOutput.ReadLine();
while (line != null)
{
Console.WriteLine(line);
line = p.StandardOutput.ReadLine();
}
}
} If you're interested in actual text diff'ing, there are projects on SourceForge[^] where you can browse the source, as well as otherplaces with open source code for utilities like diff. It's not something easy to cover in a forum.
Some books on programming algorithms will have this information as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i want to invoke some functions in API dlls or other 3rd part dlls.
and i learn to use [dllimport]declaration to invoke them.
but there are still some problems:
how to invoke such function with pointer param as this:
C++Function( byte* b ){} ?
i dont know how to convert pointer type to c# type.
and also this function in GDI32.dll:
int GetDIBits(
HDC hdc, // handle to DC
HBITMAP hbmp, // handle to bitmap
UINT uStartScan, // first scan line to set
UINT cScanLines, // number of scan lines to copy
LPVOID lpvBits, // array for bitmap bits
LPBITMAPINFO lpbi, // bitmap data buffer
UINT uUsage // RGB or palette index
);
how to declare the LPVoid type(it should be a pointer) ?
|
|
|
|
|
From www.pinvoke.net [^]:
[DllImport("gdi32.dll")]
static extern int GetDIBits(IntPtr hdc, IntPtr hbmp, uint uStartScan,
uint cScanLines, [Out] byte [] lpvBits, ref BITMAPINFO lpbmi, uint uUsage);
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Oh , and for ppointer I think you have to use IntPtr .
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
A pointer can always be declared as an IntPtr , but often times you really have to know the difference between value types and reference types. For a reference type, if you see an unmanaged declaration like ISomeInterface* , then you should (after declaring a managed interface named ISomeInterface just declare it as ISomeInterface . Interfaces are always reference types (a managed pointer) so the address is already passed. If you need to pass an array (like byte* or byte[] , then just pass the array byte[] . An array is also a reference type, regardless of the element type. If you need to pass a reference to a struct (declared as SOMESTRUCT* in unmanaged code), then use either the out (for [out] declarations) or ref (for [in,out] declarations).
Also, while not required (in most cases) you should use the InAttribute and OutAttribute</copde> for parameters documented as [in] and [out], respectively. Many times you will also need to use the <code>MarshalAsAttribute to help the CLR determine how to marshal parameters across managed boundaries. See the documentation for those three aforementioned attributes in the .NET Framework SDK for more information.
There's also a topic in the .NET Framework SDK you should read, Platform Invoke Data Types[^], which have the type-maps for common unmanaged and managed types (like a common mistake is thinking a LONG in C/C++ is a long (Int64 ) in .NET; it's not - it's a 32-bit integer and hence an int (Int32 ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for your discussion.
i can learn many from it!!!
|
|
|
|
|
Hello every1,
Ive added a ADO DataSet and drag dropped on it a Stored Procedure from my DB. Filled up my SQL adapter and so on......the code is given below
rptmgFAR1 mgReport = new rptmgFAR1();
DataSet1 ds = new DataSet1();
System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection();
sqlConn.ConnectionString = Configuration.ConnectionString;
System.Data.SqlClient.SqlCommand sqlComm = new System.Data.SqlClient.SqlCommand();
sqlComm.CommandText = "sp_rptReg";
sqlComm.CommandType = System.Data.CommandType.StoredProcedure;
sqlComm.Connection = sqlConn;
System.Data.SqlClient.SqlDataAdapter sqlAdapt = new System.Data.SqlClient.SqlDataAdapter();
sqlAdapt.SelectCommand = sqlComm;
sqlAdapt.Fill(ds);
sqlAdapt.Dispose();
mgReport.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = mgReport;
CrystalReportViewer1.Visible = true;
After doin all this....when i run the report......Logon screen appears. What is the problem...
In the report,the Command has all the feilds available which are in the select of the SP.
Thanks in advance.
|
|
|
|
|
I guess you have to provide username and password of your database in youur connection string so it won't ask for it.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
How can I create contols on a form with the data from a loaded object (I load it from a file)? Where do I put the code that creates this controls in order for them to be visible as long as the form is visible? I suppose I cannot instantiate them in a method of the form's class because in this case they will be treated as locals. Is there a way to make them global in the form's class, if I don't know how many controls do I have to instantiate (this depends on the data that the loaded object gives me)?
I dont't know if I've been clear enough but I hope you can help me or give me an advice.
Thanks!
Best regards,
Cristina
|
|
|
|
|
Hi Cristina!
After creating your controls you have to add them to the controls collection of your form to be visible. Therefor you can use either Controls.Add or Controls.AddRange depending on how many controls you want to add.
Take a look at the "Windows Form Designer generated code" region to see how your form gets created to get an idea on how to use this.
Hope this helps 
|
|
|
|
|
As far as reading controls from a file, that is entirely up to you. You could use a runtime serialization format (better for saving state), or an XML format (as many do), or make up some crazy format of your own. As you read this file in, you use reflection to create the types (like using Type.GetType to get the type and Activator.CreateInstance to create an instance of that type) and then setting properties, etc.
There are already many projects out there. I recommend MyXaml[^] from CP's own Marc Clifton, which even has the attention of Microsofties. It already provides a pretty complete framework for doing this. There's already projects out there that do this - many of which are free to use. It's not as easy to do as you might think.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
(new to c#)
I'm trying to use the Find method to search text in a richtextbox...
eg.
myTextBox.Find("Text",0,RichTextBoxFinds.WholeWord);
The problem is I want to combine RichTextBoxFinds options
- WholeWord (value = 2)
- MatchCase (value = 4)
- Reverse (value = 16)
The microsoft web site says:
"You can combine one or more values from this enumeration to specify more than one search option when calling the Find method."
Can anyone show me (in code) how I'd use the values? Do you add them together, or list them?
Thanks,
Ron
|
|
|
|
|
hi Ron,
You can specify multiple enumerations by using "|" character between the enums... like :
myTextBox.Find("Text",0,RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Cool, works like a charm... thanks Aryadip!
So what's up with the values though, can you use them instead of the text?
Ron
|
|
|
|
|
Hey,
Anybody know how to generate a LM and NT hashes? This is for generating samba passwords.
Sample C# code would be greatly appreciated. Im writing a windows forms application. I need to be able to get text from a text box hash it to LM and NT then write it to my ldap server.
Cheers,
Rhys
|
|
|
|
|
First of all, it's "NTLM" not "LM and NT". It stands for "Windows NT LAN Manager". The older "LM" just refers to LAN Manager (before NT, but still supported in part).
Second of all, it's not just a simple hash like MD5 or SHA1. The server creates a 16-byte random number (the challenge). The client hashes the password and encrypts the challenge with it. This is the response. If it's the client hash you're talking about, this is described in the Samba ENCRYPTION[^] documentation.
Why are you communicating with the LDAP server directly, though? If possible, you should use the negotiate security package, or Windows Integrated security. Since the hash of the password will always be the same, sending across the wire would be subject to replay attacks. A cracker wouldn't need the plain-text password - the hash would suffice, which is why the server sends a challenge to the client with either authentication request to be encrypted (the response).
You should go through the proper "channels" to authenticate the user, not do it yourself. One such easy way is to call the LogonUser API. This negotiates the security package and authenticates the user. If youre LDAP server is part of the Active Directory domain, there should be no problems doing it this way.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Aight, cool thanks for that, that clears things up for me a bit.
I'll give a little more background... My clients/users will be authenicating with with samba. My openldap Server is being used for a samba backend. I am writing a windows app to manage the directory backend, that is adding users and so on. The directory seems to store the the password in two seperate attributes: sambaLMpassword and sambaNTpassword.
Currently I have to two ways of adding users: (1)using the smbpasswd samba tool wich generates the passwords it self and (2)also the idealx smbldap-tools, wich use a little linux util called mkntpwd wich when you feed it a string it spits out two hases a LM and a NT. Both of these are command line tools, I'd like to try my hand a creating a small and usable windows GUI.
Kind Regards,
Rhys
|
|
|
|
|
My suggestion would be, then, to find the source for those two utilities. Being open-source software, it's around somewhere. You might check the Samba web site[^]. They probably have CVS instructions somewhere - typically - to download the source. You could see how they do it, then.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have the following code but i don't know c++ language.
How to write in C# language ?
http://www.codeguru.com/Cpp/controls/treeview/misc-advanced/article.php/c679/
Anybody can ?
|
|
|
|