pinvoke

Get uname release field from C# in .NET Core on Linux

▼魔方 西西 提交于 2020-01-25 09:24:17
问题 I'm trying to get the output of uname -r in C# in .NET Core 2.2 running on Ubuntu 18.04. I'm writing this with performance in mind, so have been trying to use a P/Invoke to achieve it. The uname(2) docs indicate I need to pass a struct in with the relevant sized fields. After playing with a lot of variations, I came up with: [StructLayout(LayoutKind.Sequential)] unsafe internal struct Utsname { public fixed byte sysname[65]; public fixed byte nodename[65]; public fixed byte release[65];

Pinvoking adwapi.dll - cryptDecrypt and cryptEncrypt functions, weird problem

旧街凉风 提交于 2020-01-25 07:23:06
问题 I am observing wierd behaviour of this function, the string that I want to encrypt contains 14 bytes, if I use the function to send lenght of buffer = 14, it fails ("an internal error" - very descriptive and most helpful error code), but it works when the buffer length (and the buffer itself) is 128 bytes large. I overcame this problem by making a size 128 byte array and I copied the 14 bytes from the plain text (that I wish to encrypt), When I decrypt those bytes, I must once again give the

Access Violation with unmanaged DLL

牧云@^-^@ 提交于 2020-01-25 04:48:04
问题 Currently, we use an unmanaged DLL from a vendor that allows us to access a particular instrument. The particular function of interest is specified in a header file as this: extern "C" short CCONV acq_get_board_count (); In my application, I have the pinvoke statement: public class bograms { [DllImport("bograms.dll", EntryPoint = "acq_get_board_count", CallingConvention = CallingConvention.StdCall)] public static extern short acq_get_board_count(); } Now, in my code I am attempting to handle

Access Violation with unmanaged DLL

扶醉桌前 提交于 2020-01-25 04:48:04
问题 Currently, we use an unmanaged DLL from a vendor that allows us to access a particular instrument. The particular function of interest is specified in a header file as this: extern "C" short CCONV acq_get_board_count (); In my application, I have the pinvoke statement: public class bograms { [DllImport("bograms.dll", EntryPoint = "acq_get_board_count", CallingConvention = CallingConvention.StdCall)] public static extern short acq_get_board_count(); } Now, in my code I am attempting to handle

Shell_NotifyIconA / Shell_NotifyIconW…whats the difference?

空扰寡人 提交于 2020-01-24 13:58:07
问题 I am porting some Win32 code to C#, and have come accross several functions which have the same names and use the same structures except that they end with A and W For example: [return: MarshalAs(UnmanagedType.Bool)] [DllImport("shell32.dll", CallingConvention = CallingConvention.StdCall)] public static extern bool Shell_NotifyIconA(uint dwMessage, ref NOTIFYICONDATAA lpData); [return: MarshalAs(UnmanagedType.Bool)] [DllImport("shell32.dll", CallingConvention = CallingConvention.StdCall)]

C# talking to C++ library - AAF SDK

…衆ロ難τιáo~ 提交于 2020-01-24 01:46:08
问题 I'm trying to read AAF files (that describe edited video and audio sequences) in c#. AAF is open source, and there's a C++ SDK available http://sourceforge.net/projects/aaf/. I'm a C# coder and while I understand some of the C++ coding paradigms, my C++ is basically non-existent. I presume the intereaction is possible using pinvoke which I've used before for interacting with Win32. With win32 I've pulled calling information from pinvoke.net, but I'm not entirely sure how I go about defining

FreeLibrary returns true indefinitely

别说谁变了你拦得住时间么 提交于 2020-01-24 00:40:17
问题 Is there any reason why FreeLibrary would repetitively return true? I'm trying to unload some native dll from my process, so I'm getting it's handle and then calling FreeLibrary until the ref count goes to zero and so FreeLibrary returns false... but it never does: IntPtr pDll = DllLoadingImports.LoadLibrary(dllTounLoad); //throw if pDll == IntPtr.Zero while(DllLoadingImports.FreeLibrary(pDll)); The code runs and never returns. Also the process explorer shows the dll still loaded. More

How to pass string parameters between C++ and C#?

Deadly 提交于 2020-01-23 17:55:07
问题 I have imported a C++ library in my C# project. I can get the answer of a C++ method that has no parameters. What I want to do is to send some string parameters to C++ and get the result of it. In C++: public String SomeMethod(String param1, String param2) { //Some code } In C#: [DllImport("Library Path")] public static extern string SomeMethod(string param1, string param2); How can I do this? 回答1: For strings that are input parameters passed from C# to C++, you could just use LPCWSTR (i.e.

Change program's volume on Win 7

对着背影说爱祢 提交于 2020-01-23 05:57:52
问题 I want to change the program's volume (and not master volume). I have the following code right now: DllImport("winmm.dll")] public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume); [DllImport("winmm.dll")] public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume); private void volumeBar_Scroll(object sender, EventArgs e) { // Calculate the volume that's being set int NewVolume = ((ushort.MaxValue / 10) * volumeBar.Value); // Set the same volume for both the left

Windows Security login form?

我们两清 提交于 2020-01-23 02:18:32
问题 Do you know the awesome looking form of Windows Live that asks you for your cerdentials? Gmail Notifier has it too, somehow. Is there any way I can invoke something like this in my application? BEHOLD! I wish to use this dialog for local authentication on a desktop app. 回答1: You could look into calling CredUIPromptForWindowsCredentials : From MSDN: The CredUIPromptForWindowsCredentials function creates and displays a configurable dialog box that allows users to supply credential information