pinvoke

Send CTRL_C/SIGINT to a process from C#

我只是一个虾纸丫 提交于 2019-12-24 03:43:32
问题 I would like to interrupt a command running through cmd.exe. In the code below, I am using ping www.stackoverflow.com -t as an example. public void Run() { System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo("cmd.exe"); si.RedirectStandardInput = true; si.RedirectStandardOutput = true; si.RedirectStandardError = true; si.UseShellExecute = false; si.CreateNoWindow = false; //si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; System.Diagnostics.Process

How to update the change time of a file from c#?

谁都会走 提交于 2019-12-24 03:39:17
问题 Files can have a change date. This date is not the same as the last modified date or the last access date. Change date is not visible through the UI or .NET API. There a two Win32 functions GetFileInformationByHandleEx for reading and SetFileInformationByHandle for writing file information. I want to read out the change date, add some hours to it, and write the new date back as the change date of the file. For now I have following code: class Program { static void Main(string[] args) { using

How to marshal an array of structure In C#?

余生长醉 提交于 2019-12-24 03:17:02
问题 I have to call a C++ dll in C#. And the header of the dll is as following(simplified): //Header of C++ struct vector { float x; float y; vector() {} vector(float x0, float y0) { x = x0; y = y0; } }; struct unmanaged_struct { int int_var; float float_var; char* chars_var; vector vector_var; unmanaged_struct(int i, float f, char* ch, float vec_x, float vec_y) { int_var = i; float_var = f; chars_var = ch; vector_var = vector(vec_x, vec_y); } }; // this function is used to output all the variable

Can you use .net 3.5 Action or Func as Marshalled unmanaged delegates?

こ雲淡風輕ζ 提交于 2019-12-24 03:03:58
问题 After reading Dynamically calling unmanaged dlls in .net I've been trying to modify the code to my liking. I made a class that implements idisposable to wrap load calls in and free them when needed. However I can't seem to figure out the syntax if it is possible to use anonymous delegates with it. var loaded=DynamicLibraryLoader.TryLoad("User32.dll"); var beeper=loaded.GetProcAddress("MessageBeep"); var type=typeof(Action<UInt32>); Action<UInt32> beepAction2=(Action<UInt32>) Marshal

Any implementation of an Unrolled Linked List in C#?

情到浓时终转凉″ 提交于 2019-12-24 01:08:39
问题 I'm interested in using an "unrolled linked list" in my C# application. Is anyone aware of a stable implementation, especially one that will allow me to configure how much padding to allocate per array? 回答1: According to the 2nd comment in your own link, such a list should be implemented in BigList in the PowerCollections library. It's open source, so you could have a look at the code and see if it allows for your scenario, or if it can be adapted to fit your needs easily. Other than that, I

How to get owner of process running on remote machine without WMI

一世执手 提交于 2019-12-23 23:24:30
问题 I'm creating remote task manager app and I'm trying to figure out how to get process owner of process running on remote machine without WMI. With WMI it's really easy, but it's too slow. I'm tried to use WTSQuerySessionInformation, but it only worked for local machine. For closer specification, my remote task manager app will run on workstations and will connect against another workstations and also against servers in the same network. User, which will run the app, wil be administrator on

C#: marshall strings to utf8 char* [duplicate]

点点圈 提交于 2019-12-23 22:54:55
问题 This question already has answers here : PInvoke struct with array of unspecified length (2 answers) Closed 6 years ago . Background I am trying to write a high level libspotify wrapper based on a modified libspotify.net (http://libspotifydotnet.codeplex.com/). As libspotify.net is just a thin (and completely bugged ... ) pinvoke layer, it does not handle the utf8 encoding libspotify uses. My idea was to convert the string to a byte[] and change the signatures appropriately. I have this

DevExpress ASP.Net Component on Mono

橙三吉。 提交于 2019-12-23 20:52:38
问题 I'm a happy user of DevExpress components, though currently I'm still on a linux web host. In another thread I've spoken about my plans to move to a Windows environment so that I can use DevExpress's ASP.Net components. For some time now DevExpress's stand has been that their components is not likely to work on Mono, due to heavy usage of P/Invoke. Having no prior experience with their ASP.Net components, my question is, has anyone successfully used their ASP.Net controls under Mono? I've

Access violation where there wasn't one before

a 夏天 提交于 2019-12-23 20:49:05
问题 I'm P/Invoking out to Graphviz as shown here. When I wrote that blog entry, the code worked just fine. Now, I'm putting together an HttpModule that renders Graphviz graphs using that code, but I get an AccessViolationException at agmemread . // Native signature Agraph_t agmemread(char *); // P/Invoke Signature [DllImport(LIB_GRAPH)] private static extern IntPtr agmemread(string data); // Usage IntPtr g = agmemread(data); Like I said, this worked perfectly before. But now, I can't get my code

Calling C++ code from C# error using references in c++ ref in c#

只谈情不闲聊 提交于 2019-12-23 20:32:52
问题 So in my c++.dll file i got the following function: DLL void GetUserPass(char* &userName, char* &passWord) { userName = "ceva"; passWord = "altceva"; } Now I want to call this from c# but it gives me an error: [DllImport("myDLL.dll")] private static extern void GetUserPass(ref string userName, ref string passWord); static void f() { string userName =""; string passWord =""; GetUserPass(ref userName, ref passWord); } And the error is: A call to PInvoke function 'Download FTP Archive!Download