unmanaged

I want to call a C# delegate from C++ unmanaged code. A parameterless delegate works fine , but a delegate with parameters crashed my program

若如初见. 提交于 2019-12-06 05:43:30
问题 The Following is code of a function from a unmanged dll. It takes in a function pointer as argument and simply returns value returned by the called function. extern __declspec(dllexport) int _stdcall callDelegate(int (*pt2Func)()); extern __declspec(dllexport) int _stdcall callDelegate(int (*pt2Func)()) { int r = pt2Func(); return r; } In managed C# code I call the umanged function above with a delegate. unsafe public delegate int mydelegate( ); unsafe public int delFunc() { return 12; }

Difference between Marshal.SizeOf and sizeof, I just don't get it

一个人想着一个人 提交于 2019-12-06 04:44:39
问题 Until now I have just taken for granted that Marshal.SizeOf is the right way to compute the memory size of a blittable struct on the unmanaged heap (which seems to be the consensus here on SO and almost everywhere else on the web). But after having read some cautions against Marshal.SizeOf (this article after "But there's a problem...") I tried it out and now I am completely confused: public struct TestStruct { public char x; public char y; } class Program { public static unsafe void Main

Pass string from unmanaged code to managed

北战南征 提交于 2019-12-06 04:32:30
问题 I have a problems with passing string from unmanaged code to managed. In my unmanaged class ( unmanagedClass.cpp ) I have a pointer to function from managed code: TESTCALLBACK_FUNCTION testCbFunc; TESTCALLBACK_FUNCTION takes one string and returns nothing: typedef void (*TESTCALLBACK_FUNCTION )(char* msg); Unmanaged class inherites from ITest interface which has only one method: STDMETHOD(put_TestCallBack) (THIS_ LPVOID FnAddress ) PURE; In managedClass.cs I write this code: public class

How to import and use a unmanaged C++ class from C#?

孤街醉人 提交于 2019-12-06 04:30:22
I have an native C++ dll, some header files and the import library. Is there a way how to instantiate an object within C# that is defined in the dll? The two ways I'm aware of are: to wrap the C++ code into COM to use DLLImport and external C functions C++/CLI is your friend for this. You'll run into one problem though: it is not possible to store standard C++ objects inside C++/CLI ref or value classes (the ones for .NET). So you'll have to resort to the following class (that you can modify) that I use in production code: #pragma once #include <boost/shared_ptr.hpp> template <typename T> ref

Passing Unmanaged pointers in C++/CLI

别等时光非礼了梦想. 提交于 2019-12-06 03:52:34
问题 I'm creating a C++/CLI wrapper DLL that depends on numerous C++ static libraries. Some of the function calls expect unmanaged pointers to be passed in. How do i pass them properly? Also, other functions expect a "this pointer" to be passed in as a void*. What's the right way to pass "this"? Here's my class definition... public ref class RTPClient { public: RTPClient(); ~RTPClient(); bool Connect(); void Disconnect(); private: CIsmaClient* mClient; }; Here's my usage where the pointers in

Is this .tlh file correct, and if not, then how do I generate the correct one?

点点圈 提交于 2019-12-06 03:35:17
I am trying to call a .NET 4.0 dll from unmanaged C++ code. I followed the instructions in this Code Project article by Atul Mani. I built the .NET dll, and followed all the steps up to and including registering it with regasm. Next, I created an unmanaged C++ project and added this line at the start of the .cpp file: #import "D:\PathToMyCSharpProject\bin\Debug\com.DeviceServices.tlb" rename ("EOF","adoEOF") no_namespace named_guids raw_interfaces_only When I built the C++ project, a .tlh file was created in D:\MyCPlusPlusProject\Debug. Next, I added the code suggested by the CodeProject

Marshaling pointer to an array of strings

泪湿孤枕 提交于 2019-12-06 01:39:13
问题 I am having some trouble marshaling a pointer to an array of strings. It looks harmless like this: typedef struct { char* listOfStrings[100]; } UnmanagedStruct; This is actually embedded inside another structure like this: typedef struct { UnmanagedStruct umgdStruct; } Outerstruct; Unmanaged code calls back into managed code and returns Outerstruct as an IntPtr with memory allocated and values filled in. Managed world: [StructLayout(LayoutKind.Sequential)] public struct UnmanagedStruct {

Stack overflow in unmanaged: IP: 0x26eb76, fault addr: 0xbf808ffc

匆匆过客 提交于 2019-12-05 18:48:57
问题 My Mono application crashes on Mac with this message (Full log): $ mono --debug bin/Debug/SparkleShare.app/Contents/MonoBundle/SparkleShare.exe [...] Stack overflow in unmanaged: IP: 0x26eb76, fault addr: 0xbf808ffc [...] "in unmanaged" implies that the stack overflow is not in my code (I only have managed code) but rather in a library I embed (SQLite, DotCmis, NewtonSoft.Json) or in Mono's code. Even though I compile and run in Debug mode, all I get is these two hexadecimals. QUESTION: How

Why does my multithreaded C++ .NET application only crash when executed outside of visual studios?

会有一股神秘感。 提交于 2019-12-05 18:34:58
I have created a very simple C++ .NET application using both managed and unmanaged code to replicate my problem. When the user clicks a button a new thread should spawn and do some time-consuming tasks while calling back to my main thread with status updates. This code compiles and successfully executes from within side of Visual Studios Express 2010. That is, when I click the "play" button, my project builds and executes without crashing. However, if I go to the Release folder where the executable lives and run it the application crashes once the button is clicked. I am compiling with /clr

C++: Getting the c3859 error code while compiling in a mix of C++/CLI and C++

徘徊边缘 提交于 2019-12-05 15:44:38
问题 After I have done as suggested by Hans Passant in C++: Getting the "error C2065: 'pst' : undeclared identifier" while using pstsdk? (which works), my code now looks like this: private: System::Void readPstFileButton_Click(System::Object^ sender, System::EventArgs^ e) { pstsdk::pst myfile(marshal_as<std::wstring>(fileNameTextBox->Text)); } And I now get the following errors: error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm111' or greater