Questions tagged [pin-ptr]

17 questions
3
votes
1 answer

Access violation when using pin_ptr?

When I use pin_ptr to pass an array in native c code, I get access violation. The code is as bellow: array^ LogLikelihoodScore(array^>^ modelsBuffer , array^ featuresArray, int numberOfFrames) { int i, j,…
2
votes
1 answer

Is it necessary to release pin_ptr or is it done automatically?

I read the microsoft documentation about pin_ptr and it is not clear to me if it is release automatically or not. Can anyone shed some light?
Lion King
  • 495
  • 5
  • 14
2
votes
1 answer

C++/CLI pin_ptr's usage in proper way

I am newbie of C++/CLI. I already know that the pin_ptr's functionality is making GC not to learn to specified object. now let me show you msdn's example. https://msdn.microsoft.com/en-us//library/1dz8byfh.aspx // pin_ptr_1.cpp // compile with:…
nolleh
  • 107
  • 2
  • 10
2
votes
1 answer

C++/CLI method calls native method to modify int - need pin_ptr?

I have a C++/CLI method, ManagedMethod, with one output argument that will be modified by a native method as such: // file: test.cpp #pragma unmanaged void NativeMethod(int& n) { n = 123; } #pragma managed void…
Whitney Kew
  • 215
  • 3
  • 13
2
votes
1 answer

Do I need a pin_ptr to pass a literal string?

From a managed c++ function I want to invoke an unmanaged function that expects a 'const char *' as an argument. Are a) and b) below correct? For b), do I need to pin_ptr 'hello'? What about a)? Thanks. a) myFunction( "hello" ); b) char hello[10]…
Martín
  • 45
  • 2
2
votes
0 answers

cli::array as member in mixed class

I want to have a managed buffer as a member in mixed class: class A { cli::array m_managedBuffer; } This results in: error C3265: cannot declare a managed 'm_managedBuffer' in an unmanaged 'A' So I tried using auto_gcroot: class A { …
solyd
  • 782
  • 2
  • 8
  • 18
1
vote
1 answer

pin_ptr a native void* help

The Setup I have a PDF API which has a native function that is defined below. typdef void* PDF_DOCUMENT; unsigned long PDF_GetMetaText(PDF_DOCUMENT document, const char tag, void* buffer,…
Tom Fobear
  • 6,729
  • 7
  • 42
  • 74
1
vote
2 answers

Using the memory allocated by a CLI array as storage for an unmanaged class

I have an unmanaged class that accepts a pointer to memory as its storage space. e.g. class MemBlock { void* mpMemoryBlock; // Various other variables that manipulate the memory block goes here. public: MemBlock( void* pMemoryBlock ) : …
Goz
  • 61,365
  • 24
  • 124
  • 204
1
vote
2 answers

How can I save a object, so that it won't get collected by the GC in C++/CX

This is the code that I have for the constructor: LmiVideoCapturer* LmiVideoCapturerConstruct_(LmiVideoCapturer* x, const void* implementation) { std::vector &deviceList =…
rosu alin
  • 5,674
  • 11
  • 69
  • 150
1
vote
1 answer

how to put a pin_ptr into a generic list?

I've got a managed C++ method that takes as a parameter a list of String^ the method needs to populate an unmanaged structure with pointers to the memory in the String^ extracting the WCHAR* is simple enough with PtrToStringChars however I dont know…
stuck
  • 2,264
  • 2
  • 28
  • 62
1
vote
1 answer

pin_ptr & PtrToStringChars vs. StringToHGlobalAnsi: Why does PtrToStringChars var loose its value?

I am using C++/CLI and I want to call the function WNetAddConnection2 from Windows Networking. First, I know that C++/CLI is not the language of choice for my work, but I have no possibility to change that right now and e.g. use C# instead. The…
Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45
0
votes
2 answers

pin_ptr and interior_ptr in vc++

I am working on a project that was written(a HID inteface for STM32) by a person who worked before in visual c++ 2008. So to imitate the line that is causing problem, I created a sample winform application in VC++ 2008. Here is the click event with…
Vikyboss
  • 940
  • 2
  • 11
  • 23
0
votes
1 answer

Managed to native value class conversion: is it safe to cast pointer?

I have a C# project which uses C++ classes from a library. C# classes are actually wrappers for C++ classes, they expose C++ functionality to C# client code. In many places C++ value classes are converted to C# wrappers and backwards. During code…
0
votes
0 answers

Convert C++/CLI User Defined Object (%) to Native C++ object (&)

How can I convert a user defined object passed by (%) to a native object (&). For example void managed_func(user_defined_managed_obj% m_obj_) { // i need this obj_ptr->unmanaged_func(&m_obj_); } Thus, in the above example I would like to…
0
votes
2 answers

pin_ptr performance relative to native (VC) heap objects

In a C# to native lib CLI/C++ wrapper, I have a choice: Store native pointer in a managed class (native object is created using native "new") or Store native object as a data blob in a managed class' field, and use pin_ptr to pin it before each…
Yuri Astrakhan
  • 8,808
  • 6
  • 63
  • 97
1
2