c++-cli

unmanaged var as member of managed class c++

僤鯓⒐⒋嵵緔 提交于 2019-11-29 14:14:10
I'm novice in .net c++ and trying to create class looking like: public ref class Klient { public: Klient(){} // zmienne static DWORD klienty[41][2]; static int i = 1; static DWORD* pid; static HANDLE* handle; //funkcje }; but MSV says that: error C4368: cannot define 'klienty' as a member of managed 'Klient': mixed types are not supported What's wrong with this code? You can have .NET basic data types as members of your managed class (static int i), or pointers to anything unmanaged (DWORD* pid, HANDLE* handle), but you're not allowed to have an unmanaged object directly, and the array of

Boost Threads with CLR

隐身守侯 提交于 2019-11-29 13:26:50
问题 Using Visual Studio 2008 and Boost Libraries 1.46.1 I want to compile and link the following with the /CLR flag: #include <boost/thread/thread.hpp> void run() {} int main(int argc, char *argv[]) { boost::thread t(run); } The first error is about a forward-declared dummy-struct in boost::thread. This post works around this by declaring: namespace boost { struct thread::dummy {}; } Sure, I now can compile, but then I get the linker warning Warning 1 warning LNK4248: unresolved typeref token

How do I pass the address of a c++ method in win32 app to a c# method with Action delegate parameter method

Deadly 提交于 2019-11-29 13:03:52
I have a win32 application using a C# library . The C# library has a method where the Action<T> delegate is a parameter as shown: public NetSocket(Action<int, int, string> action) I have a ref class in the win32 application with a method that matches the Action delegates signature. How exactly do I pass this method as the Action parameter in the NetSocket method listed above? Ben your solution seem to work but there was a compile error on matching the System:Sting ^ input parameter of the action delegate method in the win32 application to the String input parameter of Action delegate in the C#

VC2008, how to turn CLR flag off for individual files in C++/CLI project

浪尽此生 提交于 2019-11-29 12:38:53
This post says that it is possible to turn off the CLR flag for an individual .cpp file. From the post: You can set /CLR on or off in each .cpp file individually. Turn it on for the whole project,. as you have done, then turn it off for the files containing only native (unmanaged) code. When you have the VC++ procject properties dialog open, you can still click on files/projects in the solution explorer to change the scope that you're working on. Click on the unmanaged .cpp file to set options for just that file. Is this true? I can't figure out how to do it through the property pages for my C

C++ and C# interoperability : P/Invoke vs C++/CLI

◇◆丶佛笑我妖孽 提交于 2019-11-29 12:19:38
问题 In the course of finding a way to interoperate between C# and C++ I found this article that explains about P/Invoke. And I read a lot of articles claiming that C++/CLI is not exact C++ and requires some effort to modify from original C++ code. I want to ask what would be the optimal way when I have some C++ objects (code/data) that I want to use from C# objects. It looks like that in order to use P/Invoke, I should provide C style API. Is it true? I mean, is there a way to export C++ object

Copy from const char* to a byte array C++/c# interop Marshal::Copy

血红的双手。 提交于 2019-11-29 12:03:02
I'm trying to send an image from C++ to C# with an interop (marshaling) of C++ managed. image->getStream() return a const char* from a string. I'm having exception with my Marshal::Copy function. An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Am I doing the right thing for the copy from a const char* to a byte array ? My dll is compiled with ASCII char set in VS2010. array<System::Byte>^ OsgViewer::getLastImage() { array< Byte

SQL Server: “CREATE ASSEMBLY for assembly 'Test' failed because assembly 'Test' is malformed or not a pure .NET assembly.”

余生长醉 提交于 2019-11-29 11:47:15
I get this error when I attempt to load a mixed mode C++/CLI assembly into SQL Server 2012: CREATE ASSEMBLY [Test] AUTHORIZATION [dbo] from 'H:\test.dll' WITH PERMISSION_SET = SAFE Msg 6544, Level 16, State 1, Line 1 CREATE ASSEMBLY for assembly 'Test' failed because assembly 'Test.dll' is malformed or not a pure .NET assembly. Unverifiable PE Header/native stub. Solomon Rutzky Mixed-mode Assemblies are not allowed in SQLCLR Assemblies; only pure MSIL Assemblies are allowed. This is implied in the MSDN documentation for CREATE ASSEMBLY in the Remarks section: Assembly Validation SQL Server

Proper way of raising events from C++/CLI?

本小妞迷上赌 提交于 2019-11-29 11:44:57
问题 I was wondering what's the proper way of raising events from C++/CLI. In C# one should first make a copy of the handler, check if it's not null, and then call it. Is there a similar practice for C++/CLI? 回答1: C++/CLI allows you to override raise in custom event handlers so you don't have to test for null or copy when raising the event. Of course, inside your custom raise you still have to do this. Example, adapted from the MSDN for correctness: public delegate void f(int); public ref struct E

Pass a function pointer from C++ to be called by C# - Arguments of functions include a wide char string (LPCWSTR)

谁都会走 提交于 2019-11-29 11:37:07
I am writing a C# library to be used by native C++ application. I am using C++/CLI as the Interoperability mechanisim. I require to pass a callback function from C++ to C# (using C++/CLI as the intermediate layer). C# library needs to call the C++ function with a zero terminated string of wide characters; i.e. the prototype of the callback function is Func(LPCWSTR pszString); There are other parameters but they are immaterial for this discussion. I searched net and found Marshal.GetDelegateForFunctionPointer Method wich I can use. The problem with this is that it converts System.String from C#

How do I specify a fixed-size buffer in C++/CLI?

一个人想着一个人 提交于 2019-11-29 11:17:32
In C#, I can specify a fixed sized buffer using the fixed keyword, like so: public unsafe struct StructWithFixedBuffer { public fixed char FixedBuffer[128]; } how would I express the same thing in C++/CLI? One of the C++/CLI developer blogs had code for a template solution to this, I'll try to find a link. Ahh, found it. It's called inline_array . The C# syntax was added as a way to express the C++ syntax you've know forever. :) public: wchar_t FixedBuffer[128]; Quote: size of the 128 element char array is 256 bytes. Fixed size char buffers always take two bytes per character, regardless of