|
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 ?
|
|
|
|
|
We LEARN by doing!
At least make an attempt at it, then we can help you with any problems. If you read the code and then look up keywords in the Visual Studio Help for C++, you can read what it does and translate into C#. C# and C++ are different languages, but not as much as you might think.
RageInTheMachine9532
|
|
|
|
|
Just wondering how this can be accomplished? I've played with fraps so I know it can be done. Just wondering how difficult ^^
|
|
|
|
|
Hi. I'm new to C# and I'm trying to create
C# implementations of Controls I did in
Delphi in the past. In Delphi there is
a flag 'csDesigning' that will be set in
'ComponentState' if you're in design mode.
Using that I can do stuff like create a
Guid String to get a unique program ID
and the control can do stuff like File
Mapping or whatever to share data between
instances of the same app etc..
In C# I see something called 'DesignMode'
but it seems like it's always false!
Is there an easy way to set properties
when a UserControl is dropped on a form
that will be the same for all instances
of the application?
IOW, if I create a Guid String just using
a constructor I'll get a different string
for each app instance when I want the
property values to be the same for all
app instances, but be unique in each
app where the control is used.
This one has me baffled!
TIA
|
|
|
|
|
hi,
Well at design time youi can set a default value to whatever property you are defining in your custom control. Here is the way to do that
// Attribute applied to a property.
[DefaultValue(false)]
public new bool TabStop {...
}
and also you can use
System.Windows.Forms.Design.ControlDesigner
class to give the design time support to your control. Here you need to override the Initialize method to do all your custom setting of properties.
Hope this helps you...
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Wow! That's like, way too much work.
All I'm trying to do is create a convenience
where a component is dropped on a form and
a unique string is generated to ID the app
as a property of the component.
I'm coding a simple instance component where
the programmer can set the number of concurrent
instances allowed to run on the same machine.
In the Delphi version (s)he just has to drop
it on the form and call one method on app startup.
Looks like in C# I'll have to settle for a string
property with a suggestive name( "GuidString" )
to hint that the programmer should use a Guid
Generator utility to paste a unique string in
this property. It works just as well but it's just cooler if it would fill in without the programmer's intervention. Unfortunately
with C# if you use any contructor you get
a different Guid every time the form is
created, which is no good for my purpose.
Oh well.. can't have everything I guess!
Thanks for the info. I would have looked
around for days only to find there ain't
no easy way to do it!
|
|
|
|
|
Just FYI after playing around for
about 6 hours I hacked my way into
a component that will initialize
the way I want when dropped on
a form.
Maybe I'll work up a short article
showing how 'cause it's definitely
a feature that's very convenient.
When my C# programming book arrives
in the mail I'll consult that first
of course.
|
|
|
|
|
I am trying to customize PrintPreviewDialog for changing functionality of existing buttoms and add a few new buttons using C#, please tell me which dll need to be imported and what are the various methods available or need to be overriden for the same.
Sample code will help a lot.
regards
|
|
|
|