|
Hi,
Maybe your problem is connected with string marshalling. Native functions returns char* strings - 1 byte per letter, as far as I know, c# automatically tries to marshal strings as unicode charaters (2B per letter), try maybe such code:
[DllImport("sqlite3.dll", EntryPoint = "sqlite3_libversion", CharSet=CharSet.Ansi)]<br />
private static extern string sqlite3_libversion();
Alternatively you could also try using this attribute:
[return:MarshalAs(UnmanagedType.LPStr)]
|
|
|
|
|
Thank you for your reply,
unfortunately I had no luck with your tips. Googling I found a solution, even if it seems a workaround to me instead a properly solution.
[DllImport("kernel32")]
private extern static int lstrlen(IntPtr str);
String PointerToString(IntPtr pointer)
{
Encoding enc = Encoding.UTF8;
int pLen = 0;
if (pointer == IntPtr.Zero)
pLen = 0;
else
pLen = lstrlen(ptr);
Byte[] bytes = new Byte[pLen];
Marshal.Copy(pointer, bytes, 0, pLen);
return enc.GetString(bytes, 0, pLen);
}
|
|
|
|
|
Hi,
I've checked my solution on functions that return ascii strings and unicode strings, and those attributes work pretty well, so maybe the problem is somewhere else?
Btw in function you are using, you have utf8 encoding, but you assume that strings are 1B per letter, which is not always true for utf8.
|
|
|
|
|
I tryed to sort out the problem so I made this
public partial class Form1 : Form
{
[DllImport("sqlite3.dll", EntryPoint = "sqlite3_libversion",CharSet=CharSet.Ansi)]
private static extern string sqlite3_libversion();
[return: MarshalAs(UnmanagedType.LPStr)]
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
sqlite3_libversion();
}
}
Kept it simplier as possible.
This should return a string with the version of sqlite. But this always gives the Accession Violation Exception. You can easily try this downloading the sqlite3.dll from the official site.
Thank for you help I really appreciate.
|
|
|
|
|
Hi,
This code should work flawlessly, I've tried it on the newest library. Program prints "3.6.7"
public class Program
{
[DllImport("sqlite3.dll")]
[return: MarshalAs(UnmanagedType.LPStr)]
private static extern string sqlite3_libversion();
public unsafe static void Main()
{
Console.WriteLine(sqlite3_libversion());
}
}
Few hints:
1. If you want to bind attribute to function, you have to place function under [] tags.
2. EntryPoint has to be given if c# function name differs from function declared in native dll
|
|
|
|
|
Thank you so much for your patience
|
|
|
|
|
|
Hi,
In Windows Vista, while calling a process from a service......I am using CreateProcessAsUser()
( If better way possible, please suggest )
As you know, while using CreateProcessAsUser(), we need a token. I am obtaining this using DuplicateTokenEx() along with other functions.
It's syntax is : bool DuplicateTokenEx(.......,ref SECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType,........);
When I declare this, I get an error saying,
"The type or namespace name 'SECURITY_ATTRIBUTES' could not be found (are you missing a using directive or an assembly reference?)"
Same applies to SECURITY_IMPERSONATION_LEVEL and TOKEN_TYPE.
Questions :
1. Can anybody please let me know the probable reason for this and also the solution ?
2. Which directive/assembly is this referring to?
Awaiting your reply......
Thank You
|
|
|
|
|
Those are types that you haven't defined in your code anywhere. Well, anywhere accessible to the code having the problem anyway. You won't find those types anywhere int he .NET Framework, so you have to write them yourself.
Ahh, the joys of Copy'N'Paste coding...
|
|
|
|
|
Dave Kreskowiak wrote: Ahh, the joys of Copy'N'Paste coding...
Cross-language copy-n-paste is the BEST!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
queries365 wrote: If better way possible, please suggest
System.Diagnostics.Process.Start(ProcessStartInfo)
If you must use interop, you can find the macro declarations in the
Win32 SDK header files. For example:
SECURITY_ATTRIBUTES is declared in winbase.h
SECURITY_IMPERSONATION_LEVEL and TOKEN_TYPE are declared in winnt.h
You can also often find it already done for you at pinvoke.net[^]
(I recommend verifying and testing - I've seen incorrect stuff there).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hai,one and all,
i want to create a usercontrol in the form of a window form that usercontrol can be used to display data from database to frontend,that user control should contain a datagridview ,that usercontrol should be used in entire application.how to create the usercontrol,plz give me that type demonstration.
thanks in advance.
|
|
|
|
|
You write code. It sounds like all you're talking about IS a datagrid, so why do you need a control ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
No one here is going to code things for you, sites like rentacoder exist for these things.
|
|
|
|
|
The simplest thing is create a form and put all the controls(grids, labels, textboxes, etc) that you will be needing into that form.
Now go to the class declaration(.cs file) where it says "public partial class Class1 : Form" and change it to "public partial class RSIntexPA : UserControl"
Compile the project and generate it a dll. Now you can use your usercontrol via this dll anywhere.
|
|
|
|
|
I can demonstrate squeezing off a loaf for you...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Dear All,
I am trying to send attachment using MailMessage, attachment method in c#.
sure i recieve the body text but not the attachment it self.
Your Aid is really Appreciated.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
The e-mail server might be blocking attachments.
|
|
|
|
|
can you give your piece of code?Which will help to give specific answer.
Cheers!!
Brij
|
|
|
|
|
let me understand u, that i can recieve attachment from other emails but not attachment from this code.
I am using MailMessage
[code]
MailMessage m=new MailMessage();
....
m.Attachments.Add(new Attachment(filePath));
SmtpClient sC=new SmtpClient(HOST,PORT);
sC.send(from,to,subject,body);
[/code]
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
What have you tried? You need to post the code you are using to actually add the attachment to the mail message. It's also possible that your email server is blocking the attachment. What type of file are you trying to attach?
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
let me understand u, that i can recieve attachment from other emails but not attachment from this code.
I am using MailMessage
[code]
MailMessage m=new MailMessage();
....
m.Attachments.Add(new Attachment(filePath));
SmtpClient sC=new SmtpClient(HOST,PORT);
sC.send(from,to,subject,body);
[/code]
the file which i am attaching is simply txt file, and for sure i would like to upload different files as doc,pdf,xls,jpg,png and others.
Thanks
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
Have you set breakpoints in your code and verified that the attachment is actually getting created and added to the collection properly?
Also, your code
SmtpClient sC=new SmtpClient(HOST,PORT);
sC.send(from,to,subject,body); doesn't appear to actually send the MailMessage you created.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Thanks for reply, indeed it works if i use the method smtpClient.send(MailMessage m).
but it does not work with smtpClient.send(from,to,subject,body) method.
Thanks a lot, I did it,
I really appreciate your cooperation.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
Hi All,
I am new to C# programming with ADO.NET. I tried to delete the specific row but it is not getting affected in the database table. however when i wrote to a XML file, the record seems to be deleted.
SqlDataAdapter da = new SqlDataAdapter("select * from details", con);
DataSet ds = new DataSet();
da.Fill(ds, "details");
DataRow row = ds.Tables["details"].Rows[0];
if (row["Name"].ToString() == fi.Name)
{
ds.Tables["details"].Rows[0].Delete();
da.Update(ds.Tables["details"]);
}
ds.AcceptChanges();
Can any one help me out with an example(C#) for better understanding.
Thanks in advance..
Suresh.
|
|
|
|
|