|
In MSDN I found this for dll import used with PInvoke:
Kernel32.dll on Windows 7 and Windows Server 2008 R2;
Psapi.dll if PSAPI_VERSION=1 on Windows 7 and Windows Server 2008 R2;
Psapi.dll on Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000
So how do i do programaticly find PSAPI_VERSION? I already Can determent windows version. But i am missing from the List Windwos 2008 and R2. I am doing the folowing way:
public static EnumWinVer GetWindowsVersion()
{
OperatingSystem os = Environment.OSVersion;
Version vs = os.Version;
if (os.Platform == PlatformID.Win32Windows)
{
switch (vs.Minor)
{
case 0:
return EnumWinVer.Win95;
case 10:
if (vs.Revision.ToString() == "2222A")
return EnumWinVer.Win98SE;
else
return EnumWinVer.Win98;
case 90:
return EnumWinVer.WinME;
}
}
else if (os.Platform == PlatformID.Win32NT)
{
switch (vs.Major)
{
case 3:
return EnumWinVer.WinNT3_51;
case 4:
return EnumWinVer.WinNT4_0;
case 5:
if (vs.Minor == 0)
return EnumWinVer.Win2000;
else
return EnumWinVer.WinXP;
case 6:
if (vs.Minor == 0)
return EnumWinVer.WinVista;
else
return EnumWinVer.Win7;
default:
break;
}
}
return EnumWinVer.Undefined;
}
I am looking into GetModuleFileNameEx. QueryFullProcessImageName also can do the job. But minimum OS is Vista.
So what would happen when Dllimport calls function that doesn't exsist on current OS. So how do i handle that.
Thanks in advance for any answers to those question.
Have a nice day
edit:
[DllImport("kernel32.dll", EntryPoint = "GetModuleFileNameEx")]
static extern int K32GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, int nSize);
[DllImport("psapi.dll", EntryPoint = "GetModuleFileNameEx")]
static extern int PSAPIGetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, int nSize);
After this i will Handle System.EntryPointNotFoundExpection.
Now i only need how to detect Windows version for Windows 2008.
modified on Sunday, September 4, 2011 6:02 AM
|
|
|
|
|
Why are you using unmanaged code? It seems that Process.MainModule.FileName will get this information without worrying about this sort of thing (which is the entire purpose of using a framework like .Net in the first place).
|
|
|
|
|
Because I am gonna use WriteProcessMemory and ReadProcessMemory. Those calls does not support in .NET. I am creating a Memory Scanner. My personal project for hobby. I am creating similar to CheatEngine. The second thing is I want to learn PInvoke, even if it is harder.
|
|
|
|
|
Looks like you can get the parameters you need for Read/WriteProcessMemory (which is resident in one place) via Process.Handle and Process.MainModule.BaseAddress.
|
|
|
|
|
Hi...I'm new in image processing and I have to recognize shapes from monochrome bitmap. I puled the matrix from image and now I have to create chain code for it. It has to be 8 directional. If someone has the finished code please send me or if not please give me some directions of how to create it myself. Thanks in advance.
|
|
|
|
|
|
Thanks
|
|
|
|
|
hello guys... I have couple of IP cameras which I have managed to configure, and assigned them the IPs. But I dont know how to discover these IP cameras in some c# application.
Like, the form should show all the discoverable (available) ip cameras and when upon clicking a camera from the list, it should start showing the video from that camera.
What should be the first step? thnx
|
|
|
|
|
|
Hi there,
I have another problem in my code,
this is my code :
private void SendEmail(MailMessage message, MailAddress from)
{
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = false;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("someone@gmail.com", "password");
try
{
smtpClient.Send(message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
message.Dispose();
}
}
and now I have following exception in line "smtpClient.Send(message)" :
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 209.85.143.108:587
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at EmailSender.EmailSenderForm.SendEmail(MailMessage message, MailAddress from) in
is it from my code or my machine or my network or ...?
|
|
|
|
|
Gmail requires EnableSsl = true
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
|
|
|
|
|
I set EnableSsl = true but I have same exception
|
|
|
|
|
I alreayd told you what the problem is. There's nothing wrong with your code. You've got a network problem that we cannot solve for you.
Your errors are telling you that the gmail network isn't reachable. That means you've got one or more firewalls blocking traffic to either gmail, or blocking anything on port 587, or you're got much larger network issues to deal with.
There is no code in the world that is going to get around that problem. You either have to have your network administrators fix this, or give up on getting this to work.
|
|
|
|
|
|
Regarding the other post about connectivity.
A simple test for connectivity is the following at the command line.
telnet smtp.gmail.com 587
If the above succeeds you will get a cursor blinking waiting for you to type something (you don't need to type anything, you just need to have it waiting.)
If it doesn't work then it will say something like "connecting..." for a while and then tell you that it timed out, of failed to connect or some other error.
Notice that the above has nothing to do with C# or any other programming language. And until that work nothing you do in C# will make it work.
And I will note that I tried the exact line above and it worked for me. So the host and port are correct.
|
|
|
|
|
Thanks for this
|
|
|
|
|
PING and TRACERTE can also help you in your issues as well.
If you do a PING SMTP.GMAIL.COM and you get no resolve then you know it is a DNS error in your network.
If you do a PING and you get a resolve but then timeout, you might have a firewall issue.
A TRACERTE (not sure of utility name....sorry) will show you how far you go in connecting to the server. It may stop inside your network or you are getting to the firewall and to an external router but no further. In that case your router isn't forwarding it out to the internet.
Software Zen: delete this;
|
|
|
|
|
i recent develop a project,this use C sharp 4.0,now
need connect to crystal report ,but I will not use the crystal report .
if anyone can offer some advice or learning crystal report example,i would appreciate it.
thanks very much
Ayu
hi Vijjuuuuuuuuu...........
you provide address display error
summary is:page not found
thanks
Ayu
modified on Sunday, September 4, 2011 1:32 AM
|
|
|
|
|
Here[^] is a video tutorial section on Crystal Reports.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
|
hi,Vijjuuuuuuuuu...........
thanks for your answer
Ayu
|
|
|
|
|
C# Crystal Reports step by step
A step by step tutorial for beginners who is creating their Crystal Reports for the first time in C#.
All C# Crystal Reports Tutorial in this website is based on the following database - crystaldb. So before you begin this section , please take a look at the database structure of crystaldb - Click Here C# crystaldb
Here we are going to create a new Crystal Reports in C# from Product table in the above mentioned database crystalDB. The Product Table has three fields (Product_id,Product_name,Product_price) and we are showing the whole data from Product table to the C# - Crystal Reports project.
Open Visual Studio .NET and select a new CSharp Windows project.
Now you will get the default Form1.cs.
From the main menu in Visual Studio C# project select PROJECT-->Add New Item . Then Add New Item dialogue will appear and select Crystal Reports from the dialogue box.
Select Report type from Crystal Reports gallery.
Accept the default settings and click OK.
Next step is to select the appropriate connection to your database (here crstaldb). Here we are going to select OLEDB Connection for SQL Server to connect Crystal Reports in C#.
Select OLE DB (ADO) from Create New Connection .
Select Microsoft OLE DB Provider for SQL Server .
The next screen is the SQL Server authentication screen for connecting to the database - crystalDB. Select your Sql Server name , enter userid , password and select your Database Name .
Click next , Then the screen shows OLE DB Property values , leave it as it is , and then click finish button.
After you click the finish button , the next window you will get your Server name under OLEDB Connection, from there selected database name (Crystaldb) and click the tables , then you can see all your tables from your database.
From the tables list double click the Product table then you can see the Product table will come in the right side list.
Click Next Button
Select all fields from Product table to the right side list .
Click Finish Button. Then you can see the Crystal Reports designer window in your C# project. In the Crystal Reports designer window you can see the selected fields from Product table. You can arrange the field Objects and design of the screen according your requirements. After that your screen is look like the following picture.
Now the designing part is over and the next step is to call the Crystal Reports in your C# application and view it through Crystal Reports Viewer control in C#.
Select the default form (Form1.cs) you created in C# and drag a button and a CrystalReportViewer control to your form .
After you drag the CrystalReportViewer to your form , it will look like the following picture.
You have to include CrystalDecisions.CrystalReports.Engine in your C# Source Code.
using CrystalDecisions.CrystalReports.Engine;
Copy and paste the following source code and run your C# project
Download Source Code
Print Source Code
using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(PUT CRYSTAL REPORT PATH HERE\\CrystalReport1.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
}
}
NOTES:
cryRpt.Load(PUT CRYSTAL REPORT PATH HERE\\CrystalReport1.rpt");
The Crystal Reports file path in your C# project file location, there you can see CrystalReport1.rpt . So give the full path name of Crystal Reports file like c:\projects\crystalreports\CrystalReport1.rpt
When you run the source code you will get the report like the following picture.
When you click the button, the application will ask the username and password. Later in this tutorial you can find how to avoid asking username and password - C# Dynamic logon parameters in Crystal Reports
|
|
|
|
|
hi,palanidothis
very good, thanks your answer.
thanks!
Ayu
|
|
|
|
|
hi,palanidothis
thanks for your answer.
Ayu
|
|
|
|
|
How can i lock (or encode) my dll file in C# so that cant be decode by reflector or ect.
|
|
|
|
|