|
If that is all, then MyArray will just contain 10 nulls.
|
|
|
|
|
Yes, it makes sense now.
Thankyou
|
|
|
|
|
I'm trying to obtain the path of the file(s) that o certain process reads from or writes to (similar to the way Performance Monitor does in Vista).
I couldn't find out any direct method neither using WMI (Win32_Process class), nor the Process class from
System.Diagnostics.
Thank you.
|
|
|
|
|
|
Thanks for the reply, Giorgi.
I've managed to find a way to obtain file handles for a process. Here is the code:
[DllImport("ntdll.dll", SetLastError = true)]
public static extern uint ZwQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, IntPtr SystemInformation, int SystemInformationLength, out int ReturnLength);
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_HANDLE_INFORMATION
{
public int ProcessId;
public byte ObjectTypeNumber;
public byte Flags;
public short Handle;
public int Object;
public int GrantedAccess;
}
public const uint STATUS_INFO_LENGTH_MISMATCH = 0xc0000004;
public static SYSTEM_HANDLE_INFORMATION[] EnumHandles()
{
int retLength = 0;
int handleCount = 0;
SYSTEM_HANDLE_INFORMATION[] returnHandles;
int allocLength = 0x1000;
IntPtr data = Marshal.AllocHGlobal(allocLength);
while (ZwQuerySystemInformation(SYSTEM_INFORMATION_CLASS.SystemHandleInformation, data,
allocLength, out retLength) == STATUS_INFO_LENGTH_MISMATCH)
{
data = Marshal.ReAllocHGlobal(data, new IntPtr(allocLength *= 2));
}
handleCount = Marshal.ReadInt32(data);
returnHandles = new SYSTEM_HANDLE_INFORMATION[handleCount];
for (int i = 0; i < handleCount; i++)
{
returnHandles[i] = (SYSTEM_HANDLE_INFORMATION)Marshal.PtrToStructure(
new IntPtr(data.ToInt32() + 4 + i * Marshal.SizeOf(typeof(SYSTEM_HANDLE_INFORMATION))),
typeof(SYSTEM_HANDLE_INFORMATION));
}
Marshal.FreeHGlobal(data);
return returnHandles;
}
Then I'd like to obtain the handles for a specific process:
SYSTEM_HANDLE_INFORMATION[] handles = EnumHandles();
var winampHandles = from handle in handles
where handle.ProcessId == 10004
select handle;
foreach (var winampHandle in winampHandles)
{
}
As we can see, each handle is an object of type SYSTEM_HANDLE_INFORMATION, which does not contain a field specifying the name of the handle. To obtain the name of the handle (e.g. the file path), I think I need to call some Win API.
MSDN has an example of how to to this: http://msdn.microsoft.com/en-us/library/aa366789(VS.85).aspx[^], but it is written in C, and I need it for C#.
Is there some other way around this thing? I've tryed using the FileStream class, and pass to it's ctor the handle:
FileStream fs = new FileStream(new IntPtr(winampHandle.Handle), FileAccess.ReadWrite, false); , which throws an IO Exception ("Invalid handle"). Passing a SafeFileHandle to the ctor didn't solve the problem.
Any ideas?
|
|
|
|
|
Hi, I am sorry for some earlier posts as i was bit confused on my design of application...
Ok..I have BillDetails,Products,Packing Table...
And on winform I have gridview...Now in gridview I want to display billdetails table..but somehow the first two columns need to be combobox..and these combobox should take data from Products Table together with Packing..
I have screen shot as what exist in those tables..Also below is a small code that i have done but i see only one dropdown list with nothing populated...
Please HELP..I will really appreciate as i am stuck in it for few days
:confused:void fillData()
{
OleDbConnection database = new OleDbConnection(connectionString);
database.Open();
OleDbDataAdapter adapter1 = new OleDbDataAdapter("SELECT BillDetails.ProductID, BillDetails.ProductName, BillDetails.InQty, BillDetails.InBns, BillDetails.InPrice, BillDetails.Dis1, Products.packing, BillDetails.Saletype, BillDetails.SBtype, Products.FactorC, Products.FactorB, BillDetails.Type FROM Products INNER JOIN BillDetails ON Products.ProdID = BillDetails.ProductID", database);
DataGridViewComboBoxColumn dgridcolumn = new DataGridViewComboBoxColumn();
dgridcolumn.Name = "Products";
this.dataGridView1.Columns.Add(dgridcolumn);
DataTable dt = new DataTable();
DataTable packDT = new DataTable();
adapter1.Fill(dt);
dataGridView1.DataSource = dt;
adapter1.Fill(packDT);
dgridcolumn.DataSource = packDT;
dgridcolumn.ValueMember = packDT.Columns[1].ColumnName.ToString();
dgridcolumn.DisplayMember = packDT.Columns[1].ColumnName.ToString();
}
|
|
|
|
|
Hello everyone,
I am stuck with the following problem.
I have given text "We are living in a <upcase>yellow submarine</upcase>.", I have to change the text inside <upcase>....</upcase> to a uppercase letters so the result will be
"We are living in a YELLOW SUBMARINE."
Ill appreciate any help and suggestions how this can be done.
Thanks in advance!!
Regards
Georgi Uzunov
modified on Saturday, March 21, 2009 10:08 AM
|
|
|
|
|
How do you know which part should be in upper case? If it's always the same text you might as well just output the right output..
|
|
|
|
|
My fault the text should be "We are living in a <upcase>yellow submarine</upcase>.
So I have to replace upcase ...... /upcase with the uppercase text.
Apologies.
|
|
|
|
|
Try this.
string openTag = "<upcase>", closeTag = "</upcase>";
string str = "We are living in a <upcase>yellow submarine</upcase>.";
int startIndex = str.IndexOf(openTag);
int endIndex = str.IndexOf(closeTag) + closeTag.Length;
string subStr = str.Substring(startIndex, (endIndex - startIndex));
subStr = subStr.Replace(openTag, "");
subStr = subStr.Replace(closeTag, "");
subStr = subStr.ToUpper();
str = str.Remove(startIndex, (endIndex - startIndex));
str = str.Insert(startIndex, subStr);
hmmm pie
|
|
|
|
|
Thank you very much sir. It work like a charm Now I have to see how to put this in a loop so I can check bigger strings with more tags.
One more time Thanks.
Greetings!
|
|
|
|
|
Funny you should mention that as I was going to edit thte above code for multiple tags.
private string upperCaseTags(string str, string openTag, string closeTag)
{
int startIndex;
while ((startIndex = str.IndexOf(openTag)) != -1)
{
int endIndex;
if ((endIndex = str.IndexOf(closeTag) + closeTag.Length) != -1)
{
string subStr = str.Substring(startIndex, (endIndex - startIndex));
subStr = subStr.Replace(openTag, "").Replace(closeTag, "").ToUpper();
str = str.Remove(startIndex, (endIndex - startIndex));
str = str.Insert(startIndex, subStr);
}
}
return str;
}
hmmm pie
|
|
|
|
|
One more time great job. You did it instead of me.
Thank you!
|
|
|
|
|
This can be improved by Regular Expression's Replace[^] method.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Can they be nested?
If they can't, search the string for "<uppercase>" and "</uppercase>" and turn all substrings starting at index[2*i] ending at index[2*1+1] to uppercase (won't work correctly for invalid inputs but the idea is easily extended to using 2 index arrays)
|
|
|
|
|
sounds to me perfect case for Regular Expression. See Replace method of RegEx[^]
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Ill check this method.
Thank you!!
Greetings
|
|
|
|
|
Regard with the strings may I ask one more question. I have to write a simple program to encode and decode string using encryption key.The encoding and decoding is performed by using XOR.
So Ive done encoding part
static void Main(string[] args)
{
string str= "19 5456 65";
string key = "546";
String encode = Encode(str, key);
String decode = Encode(encode, key);
Console.Write(str + "\n" + encode+"\n"+decode);
}
static string Encode(string str,string key)
{
char []keyChar = key.ToCharArray();
char[] strChar = str.ToCharArray(); int a = 0;
for (int i = 0; i < strChar.Length;i++ )
{
strChar[i] = (char)(strChar[i] | keyChar[a]);
a++;
if (a>keyChar.Length-1)
{
a = 0;
}
}
str = new string(strChar);
return str;
}
But when I try to decode those string its giving me the same encoded string.
Please if any one knows where I am wrong to help me.
Thanks!!!
|
|
|
|
|
How can I use DLL file in C#.NET ? I create dll in Borland C++ Compiler 5.5.1 and using C language.
Following code is not work.
My C Code;
-----------------------------------------------------
//hello.dll
#include <windows.h>
extern "C"
{
void __declspec (dllexport) function1()
{
MessageBox (NULL, "test message","test title",0);
}
}
BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID)
{
return TRUE;
}
My C# Code;
-----------------------------------------------------
[DllImport("C:\hello.dll")]
public static extern void function1();
private void button1_Click(object sender, EventArgs e)
{
function1();
}
|
|
|
|
|
Does it give an exception (if so, what kind?) or does it just silently fail?
|
|
|
|
|
Ok, I try this; But I get this error: Entry Point Not Found
C DLL CODE
-----------------------------------------------
#include <windows.h>
BOOL __stdcall DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) {
return TRUE;
}
__declspec(dllexport) void __stdcall Message(char* p_szMessage) {
MessageBox(NULL, p_szMessage, "Message from DLL", MB_OK);
}
C# DLL CODE
-----------------------------------------------
[DllImport("filename.dll")]
static extern void Message(string msg);
private void button1_Click(object sender, EventArgs e)
{
Message("Hello world");
}
|
|
|
|
|
Just put hello.dll in C:\WINDOWS\system32
and replace [DllImport("C:\hello.dll")] with [DllImport("hello.dll")]
IS that give any error or exception??
|
|
|
|
|
I get this error: Entry Point Not Found
|
|
|
|
|
|
following article may help
http://www.codeproject.com/KB/cs/dyninvok.aspx[^]
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|