|
Seems you want to call an existing native function. All it takes is a little P/Invoke, there is no need to load libraries, use delegates, and such. You might learn what you need by reading this unfinished article[^] and watching some of its examples.
|
|
|
|
|
[DllImport("ntdll.dll")]<br />
unsafe public static extern int RtlSetProcessIsCritical(Boolean bNew, Boolean* pbOld, Boolean bNeedScb);<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
unsafe private void Form1_Load(object sender, EventArgs e)<br />
{<br />
RtlSetProcessIsCritical(true, null, false);<br />
}
Here my new code, but doesn't work... :/
|
|
|
|
|
According to the article, the function is
typedef long ( WINAPI *RtlSetProcessIsCritical ) (
IN BOOLEAN bNew,
OUT BOOLEAN *pbOld,
IN BOOLEAN bNeedScb );
Looking at that I think you may have a problem with your second parameter - try:
[DllImport("ntdll.dll")]
public static extern int RtlSetProcessIsCritical(bool bNew, out bool pbOld, bool bNeedScb);
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Doesn't work. And I have the administrator privileges.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
[DllImport("ntdll.dll", SetLastError = true)]
unsafe public static extern int RtlSetProcessIsCritical(bool bNew, out bool pbOld, bool bNeedScb);
public Form1()
{
InitializeComponent();
}
unsafe private void Form1_Load(object sender, EventArgs e)
{
bool outer;
RtlSetProcessIsCritical(true, out outer, true);
}
}
}
|
|
|
|
|
OK - this is interesting so I've done a little more investigation. It seems that the function you are trying to use actually calls ZwSetInformationProcess . This[^] forum thread indicates that it may not be availble on Vista/Weven and is probably not valid on any 64bit OSes. Also, an Administrator account may not be high enough, System privileges may be required. I don't know if any of these apply to you but if so then that could be the reason.
If not, you need to check the error code set by SetLastError and get the relavant error message string.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Night Lol wrote: but doesn't work...
that is not informative.
what happened to the PRE tags?
did you understand the article you referred to?
does the Win32 function return a status, does it use GetLastError? did you check them?
don't you need to manipulate some privileges?
have you ever used Google on this subject?
|
|
|
|
|
Yes, I have used google.
I have the administrator privileges (In the article, we use SE_DEBUG privilege), I have read some parts of the article.
|
|
|
|
|
This is from an example in Professional C#2008 from Wrox Chap 17, p491.
Using a VS2008 C# class library project I've created a simple shared assembly. I've used the string name tool to create a name "sn -k mykey.snk" and used the VS Project | Properties | Signing tab to sign the assembly with this key. After building, by using idlview, I can view the key in the manifest. Opening a VS Command prompt to RunAs Administrator I've installed it using "gacutil /i SharedDemo.dll".
But I can't seem to reference it from a VS2008 C# Console Application project. From Solution Explorer I right-click the solution and use Add Reference. I can find the assembly in C:\Windows\assembly using the Add Reference Browse tab but am unable to select it. The book says "... referenced in the same way as a private assembly..."
I'm not trying any Delayed Signing, just to make a compile time reference. I tried starting VS2008 with RunAs Administrator but it made no difference. Any ideas appreciated.
The assembly is in the GAC as shown by:
>gacutil /l SharedDemo
Microsoft (R) .NET Global Assembly Cache Utility. Version 3.5.21022.8 Copyright (c) Microsoft Corporation. All rights reserved.
The Global Assembly Cache contains the following assemblies:
SharedDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c5bbc6da95e06b44, processorArchitecture=MSIL
Number of items = 1
modified on Monday, July 19, 2010 10:02 AM
|
|
|
|
|
I think you're doing it wrong. Don't try to reference the assembly in the GAC, just try to reference the assembly in the directory where you created it and the system will figure out the rest. That's what works for me. Your application shouldn't have to know whether or not the assembly is in the GAC.
|
|
|
|
|
You seem to be right. In my client console project I referenced the local copy of the shared assembly SharedDemo.dll which I was able to do. But if I rename the local directory the console client still runs OK which must prove it using the shared one in the GAC.
Thanks
|
|
|
|
|
Hello Everyone,
I have one simple static HTML file, with a table i am trying to extract the contents of the table to a file.
can anyone please give some some suggestions how to proceed with this work.
HTML File:-
<html>
<body>
<table border="1">
<tr>
<th>Team Name</th>
<th>Place</th>
</tr>
<tr>
<td>Kings XI Punjab</td>
<td>Punjab</td>
</tr>
<tr>
<td>Chennai Super Kings</td>
<td>Chennai</td>
</tr>
<tr>
<td>Deccan Chargers</td>
<td>Hydrabad</td>
</tr>
</table>
</body>
</html>
I am trying to extract the text with this code :-
using System.Diagnostics;
using System.Net;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System;
using System.IO;
using System.Linq;
class Program
{
static void Main()
{
StreamReader str = new StreamReader("C:\\Sample1.html");
string strLings = str.ReadToEnd();
int startIndex = strLings.IndexOf("<table>");
int endInedx = strLings.IndexOf("</table>") + "</table>".Length - startIndex;
string strTab = strLings.Substring(startIndex, endInedx);
str.Close();
StreamWriter strWr = new StreamWriter("C:\\test2.txt", true);
strWr.Write(strTab);
strWr.Close();
}
}
Problem is i am getting an error
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: StartIndex cannot be less than zero.
|
|
|
|
|
As you already figured out, a table starts and ends with a TABLE tag, holds rows delimited by TR tags, which in turn hold columns delimited by TD tags. You did make two mistakes:
1. tags can be upper- or lower-case in HTML (XHTML requires lower-case);
2. opening tags may contain extra information (see the border='1' attribute in your example).
So code accordingly, either by providing your own GetDelimitedSubstring() method (similar to what you already have), or by using Regex.
|
|
|
|
|
Thanks Luc Pattyn for the response.
I corrected the mistakes as follows
HTML File :-
<html>
<body>
<table>
<tr>
<th>Team Name</th>
<th>Place</th>
</tr>
<tr>
<td>Kings XI Punjab</td>
<td>Punjab</td>
</tr>
<tr>
<td>Chennai Super Kings</td>
<td>Chennai</td>
</tr>
<tr>
<td>Deccan Chargers</td>
<td>Hydrabad</td>
</tr>
</table>
</body>
</html>
Program :-
<br />
static void Main()<br />
{<br />
StreamReader str = new StreamReader("C:\\Test.html");<br />
string strLings = str.ReadToEnd();<br />
int startIndex = strLings.IndexOf("<table>");<br />
int endInedx = strLings.IndexOf("</table>") + "</table>".Length - startIndex;<br />
string strTab = strLings.Substring(1, endInedx);<br />
str.Close();<br />
StreamWriter strWr = new StreamWriter("C:\\test2.txt", true);<br />
strWr.Write(strTab);<br />
strWr.Close();<br />
<br />
Console.ReadLine();<br />
}<br />
Getting the output as below written to the file ..
Not getting the required out put .. I will try with Regular Expression now.
html>
<body>
<table>
<tr>
<th>Team Name</th>
<th>Place</th>
</tr>
<tr>
<td>Kings XI Punjab</td>
<td>Punjab</td>
</tr>
<tr>
<td>Chennai Super Kings</td>
<td>Chennai</td>
</tr>
<tr>
<td>Deccan Chargers</td>
<td>Hydrabad</td>
</tr
|
|
|
|
|
|
This question is an example of what every question here should be like.
You posted the problem, gave data on the situation that was relevant, and posted code showing what you had tried. You asked for assistance and you have done a follow up with your new attempt and the results along with your reaction to that result.
I wish every poster in this forum did as well. A well earned 5 and I hope your regex works. I still get headaches from them. Good luck.
If I have accidentally said something witty, smart, or correct, it is purely by mistake and I apologize for it.
|
|
|
|
|
Are you kidding? I mentioned two mistakes in his code, he fixed none of them, instead he changed the input data. And my sig (as most always telling people to use PRE tags) got completely ignored too. I wonder why I'm still replying to questions?
PS: I wish the pinning bug got finally fixed, comparing two posts is pretty hard right now.
|
|
|
|
|
Please refer to this[^] post.
|
|
|
|
|
How to read a users/group in my local machine at the same time can update and delete
users.
I am currently doing it manually and it takes a lot of time doing that.
I am developing it in c#. Local machine not windows directory using network domain.
Thanks
even link on how to that will do
Dabsukol
|
|
|
|
|
HI.
I have a small software build in Access.I need to build a new version of this software with C# interface and the DB in Access again.How to create an installer that I can use the file of DB separately???
I mean the guys who will use this software cannot have a continuously access to internet so till now they enter the data in the existing Access 2003 software and then they send this data by email to the center where the main operator merge this files to one.I need to implement the new C# software because of reporting possibilities and nice interface.But the DB data has to be the same and used the same way as before.Please every idea of best practices or solutions will be appreciated.
|
|
|
|
|
It's a simple matter of creating a connection to the access database and building your user interface. Take a look at connectionstrings.com for the syntax for the connection string.
This is not a design I would recommend as it requires too much manual intervention, however this may meet your requirements and skill level. Consider getting a professional to build this app based on sql server, CE and replication.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I agree with you that SQL is much better regarding DB.
But my users are not IT professional and I don't have any idea how to make simple for them file sending from different cities and merging all the data at the center.With Access DB they just send their Access file not bigger than 2 Mb by email and the center operator has an Access file merger software.
If you got any clues on this issue please consult me and I will use SQL with joy
|
|
|
|
|
|
Find below code for the same.
XDocument doc = XDocument.Parse("<Hello>World</Hello>", LoadOptions.PreserveWhitespace);
string host = "localhost";
int port = 1234;
IPHostEntry address = Dns.GetHostEntry(host);
IPEndPoint ipe = new IPEndPoint(address.AddressList[0], port);
using (Socket sock = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(ipe);
using (NetworkStream sockStream = new NetworkStream(sock))
{
using (XmlReader reader = doc.CreateReader())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new UTF8Encoding(false, true);
using (XmlWriter writer = XmlWriter.Create(sockStream, settings))
{
while (reader.Read())
{
writer.WriteNode(reader, false);
}
}
}
}
}
For more information find following links useful.
File Transfer using Socket Application in C# .NET 2.0[^]
http://social.msdn.microsoft.com/Forums/en/ncl/thread/6994d38b-5caf-47ff-a425-969651d1a292[^]
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
I have an xml file that looks like this:
<root>
<element1 />
<element2 attr1="text" attr2="text">
<subelement21>
<subsubelement attr1="text" attr2="text" />
<subsubelement attr1="text" attr2="text" />
...
<subsubelement attr1="text" attr2="text" />
</subelement21>
</element2>
</root>
I am trying to read this file using a XmlReader. This is what I've tried but failed:
XmlTextReader reader = new XmlTextReader("file.xml");
while(reader.Read()) {
if (reader.NodeType == XmlNodeType.Element) {
switch (reader.Name) {
case "element1":
break;
case "element2":
reader.MoveToAttribute("attr1");
String att1 = reader.Value;
reader.MoveToAttribute("attr2");
String att2 = reader.Value;
XmlReader subreader = reader.ReadSubTree();
while(subreader.Read()) {
if(subreader.NodeType == XmlNodeType.Element) {
switch (reader.Name) {
case "subsubelement":
subreader.MoveToAttribute("attr1");
String a1 = reader.Value;
subreader.MoveToAttribute("attr2");
String a2 = reader.Value;
break;
}
}
break;
}
}
}
Here i get an exception saying that ReadSubTree() can't be called since reader is no longer at an element node, which makes sense. If I change the order and try to first read the sub tree and then the attributes of element2, i get the problem that reader is at the end element after reading the sub tree. This also makes sense, but i can't find a way to solve this.
Any ideas? I appreciate any suggestions.
Thanks
|
|
|
|
|
Read this[^] article, you will get your answer.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|