unmanaged

Free unmanaged memory allocation from managed code

故事扮演 提交于 2020-01-01 09:34:06
问题 A .NET application calls C dll. The C code allocates memory for a char array and returns this array as result. The .NET applications gets this result as a string. The C code: extern "C" __declspec(dllexport) char* __cdecl Run() { char* result = (char*)malloc(100 * sizeof(char)); // fill the array with data return result; } The C# code: [DllImport("Unmanaged.dll")] private static extern string Run(); ... string result = Run(); // do something useful with the result and than leave it out of

What's the equivalent of WORD in C#?

我怕爱的太早我们不能终老 提交于 2020-01-01 04:15:09
问题 I'm trying to access an unmanaged library and am lucky to have access to a comprehensive guide to the API. Unfortunately, I've no idea what the C# equivalent of C++'s WORD type is. Similarly, I've no idea what DWORD would be. 回答1: You're probably looking for ushort for WORD and uint for DWORD. 来源: https://stackoverflow.com/questions/5490428/whats-the-equivalent-of-word-in-c

Which one to use: Managed vs. NonManaged hashing algorithms

和自甴很熟 提交于 2019-12-30 03:50:08
问题 In a regular C# application which class to use for hashing: xxxManaged or xxx (i.e SHA1Managed vs SHA1 ) and why? 回答1: The Non-managed hashes which end in ***Cng , ie SHA256Cng, will also have platform restrictions. They are quite a bit faster than the managed alternatives, but will fail at runtime on Windows XP, for example. If you know your program will always be run on Windows 7, Vista SP1, or 2008, however, they will generally perform quite a bit better than the managed versions, even

Swift (iOS 8 SDK) Convert Unmanaged<ABMultiValueRef> to ABMultiValueRef

泄露秘密 提交于 2019-12-29 18:48:34
问题 I need to convert the return value of this function from the AddressBook framework: ABRecordCopyValue(nil, kABPersonPhoneProperty) to a value of type ABMultiValueRef This function is currently marked as this: func ABRecordCopyValue(record: ABRecordRef!, property: ABPropertyID) -> Unmanaged<AnyObject>! So I can convert it to Unmanaged like so: ABRecordCopyValue(person, kABPersonPhoneProperty) as Unmanaged<ABMultiValueRef> But then how can I get it as an ABMultiValueRef so that I can pass it to

How to run unmanaged executable from memory rather than disc

核能气质少年 提交于 2019-12-29 05:25:09
问题 I want to embed a command-line utility in my C# application, so that I can grab its bytes as an array and run the executable without ever saving it to disk as a separate file (avoids storing executable as separate file and avoids needing ability to write temporary files anywhere). I cannot find a method to run an executable from just its byte stream. Does windows require it to be on a disk, or is there a way to run it from memory? If windows requires it to be on disk, is there an easy way in

Howto call an unmanaged C++ function with a std::vector as parameter from C#?

女生的网名这么多〃 提交于 2019-12-29 01:48:08
问题 I have a C# front end and a C++ backend for performance reasons. Now I would like to call a C++ function like for example: void findNeighbors(Point p, std::vector<Point> &neighbors, double maxDist); What I'd like to have is a C# wrapper function like: List<Point> FindNeigbors(Point p, double maxDist); I could pass a flat array like Point[] to the unmanaged C++ dll, but the problem is, that I don't know how much memory to allocate, because I don't know the number of elements the function will

What is the difference in managed and unmanaged code, memory and size?

让人想犯罪 __ 提交于 2019-12-28 07:36:12
问题 After seeing and listening a lot regarding managed and unmanaged code, and knowing the only difference is that managed is about CLR and un-managed is outside of the CLR, it makes me really curious to know it in detail. What is it all about, managed and unmanaged code, memory and size? How can code I write in C# be unmanaged while this is C# code and how does a memory of size becomes unmanaged. An example and a little insight would be helpful. 回答1: Short answer: Managed code is .NET code (VB

Events not firing from COM component when in Unit (Integration) Test

有些话、适合烂在心里 提交于 2019-12-25 09:14:28
问题 I have an unmanaged DLL which I'm trying to create a .NET wrapper library for but am getting different behavior when I try and run a NUnit(v3) test over it compared to if it is just run from a button click off a WinForm app. Background: During startup of the DLL I call its Connect() method, which ultimately causes the DLL to make a TCP connection. When the TCP connection is established I then get notified by wiring up a handler to its "Connected" event. Once connected I then call other

What's wrong with this unmanaged code in C#?

拟墨画扇 提交于 2019-12-25 08:36:56
问题 I was trying to get text from each control in hierarchy. The following code runs fine if I use the unsafe method. However, using the unmanaged version seems to break hWnd , which in result hWnd = GetAncestor(hWnd, GetAncestorFlags.GA_PARENT) complains: System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' I have checked hWnd was not changed after returning from GetWindowTextRaw function, and if I comment out

How to call NetUserModalsGet() from C#.NET?

末鹿安然 提交于 2019-12-25 04:37:17
问题 EDIT: followup at NetUserModalsGet() returns strings incorrectly for C#.NET I'm struggling with the DLL declarations for this function: NET_API_STATUS NetUserModalsGet( __in LPCWSTR servername, __in DWORD level, __out LPBYTE *bufptr ); (Reference: http://msdn.microsoft.com/en-us/library/aa370656%28VS.85%29.aspx) I tried this: private string BArrayToString(byte[] myArray) { string retVal = ""; if (myArray == null) retVal = "Null"; else { foreach (byte myByte in myArray) { retVal += myByte