Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionproblem in writing a binary file using _tfopen_s function Pin
VCProgrammer3-Aug-11 20:48
VCProgrammer3-Aug-11 20:48 
AnswerRe: problem in writing a binary file using _tfopen_s function Pin
Code-o-mat3-Aug-11 21:04
Code-o-mat3-Aug-11 21:04 
RantRe: problem in writing a binary file using _tfopen_s function Pin
«_Superman_»4-Aug-11 3:41
professional«_Superman_»4-Aug-11 3:41 
Questionhandle fullscreen child view in c++ 2010? Pin
fracker_23213-Aug-11 20:46
fracker_23213-Aug-11 20:46 
AnswerRe: handle fullscreen child view in c++ 2010? Pin
Richard MacCutchan3-Aug-11 22:55
mveRichard MacCutchan3-Aug-11 22:55 
GeneralRe: handle fullscreen child view in c++ 2010? Pin
fracker_23214-Aug-11 1:28
fracker_23214-Aug-11 1:28 
AnswerRe: handle fullscreen child view in c++ 2010? Pin
Rolf Kristensen4-Aug-11 12:06
Rolf Kristensen4-Aug-11 12:06 
Questionpin_ptr on value struct is needed? [modified] Pin
Dusan Paulovic3-Aug-11 6:16
Dusan Paulovic3-Aug-11 6:16 
Hi all, I am working on class to wrapp unmanaged pointer. I am just confused, whether pinning of value struct is needed in C++/CLI, i.e. whether if I will not do it, it can cause some problems.

In C#, I am not able to fix structs:
C#
Point pntA = new Point(10, 25);
Point pntB = new Point();

unsafe
{
  // Error	4	
  // You cannot use the fixed statement to take 
  // the address of an already fixed expression	
  fixed (Point* ptrA = &pntA, ptrB = &pntB)
  {
    ptrB->X = ptrA->X;
    ptrB->Y = ptrA->Y;
  }
}


but, I can simply use address-of operator:
C#
Point pntA = new Point(10, 25);
Point pntB = new Point();

unsafe
{
  // Correct
  Point* ptrA = &pntA, ptrB = &pntB;
  ptrB->X = ptrA->X;
  ptrB->Y = ptrA->Y;
}


What is confusing me is that pin_ptr lets me pin structures as well as use address-of operator:

C++
// /clr
generic <typename T> where T : value struct
T GetValueA(void* ptr)
{
  T val = Activator::CreateInstance<T>();

  pin_ptr<T> valPtr = &val;
  memcpy(valPtr, ptr, sizeof(T));
  return val;
}

generic <typename T> where T : value struct
T GetValueB(void* ptr)
{
  T val = Activator::CreateInstance<T>();

  memcpy(&val, ptr, sizeof(T));
  return val;
}


My questions are:

Is pinning needed in C++/CLI functions to fix value struct
before using its pointer in unmanaged function?

Are value structs allocated in the unmanaged heap?

Thanks all,
Dusan

modified on Wednesday, August 3, 2011 12:22 PM

AnswerRe: pin_ptr on value struct is needed? Pin
Code-o-mat3-Aug-11 6:34
Code-o-mat3-Aug-11 6:34 
GeneralRe: pin_ptr on value struct is needed? Pin
Dusan Paulovic3-Aug-11 6:53
Dusan Paulovic3-Aug-11 6:53 
GeneralRe: pin_ptr on value struct is needed? Pin
Code-o-mat3-Aug-11 8:28
Code-o-mat3-Aug-11 8:28 
QuestionHow to get msn status Pin
Lighter Joul2-Aug-11 22:41
Lighter Joul2-Aug-11 22:41 
AnswerRe: How to get msn status Pin
Richard MacCutchan2-Aug-11 22:49
mveRichard MacCutchan2-Aug-11 22:49 
GeneralRe: How to get msn status Pin
Lighter Joul2-Aug-11 23:08
Lighter Joul2-Aug-11 23:08 
GeneralRe: How to get msn status Pin
Richard MacCutchan2-Aug-11 23:34
mveRichard MacCutchan2-Aug-11 23:34 
AnswerRe: How to get msn status Pin
Code-o-mat3-Aug-11 1:40
Code-o-mat3-Aug-11 1:40 
AnswerRe: How to get msn status Pin
jschell3-Aug-11 9:53
jschell3-Aug-11 9:53 
QuestionHow to increase transfer speed? Pin
yu-jian2-Aug-11 21:24
yu-jian2-Aug-11 21:24 
AnswerRe: How to increase transfer speed? Pin
Alan Balkany4-Aug-11 4:43
Alan Balkany4-Aug-11 4:43 
QuestionHow to make member functions of an application accessible by a DLL? Pin
Arris742-Aug-11 10:00
Arris742-Aug-11 10:00 
AnswerRe: How to make member functions of an application accessible by a DLL? Pin
Chris Losinger2-Aug-11 10:15
professionalChris Losinger2-Aug-11 10:15 
GeneralRe: How to make member functions of an application accessible by a DLL? Pin
Stephen Hewitt2-Aug-11 21:24
Stephen Hewitt2-Aug-11 21:24 
GeneralRe: How to make member functions of an application accessible by a DLL? Pin
Chris Losinger3-Aug-11 0:50
professionalChris Losinger3-Aug-11 0:50 
AnswerRe: How to make member functions of an application accessible by a DLL? Pin
Albert Holguin2-Aug-11 12:15
professionalAlbert Holguin2-Aug-11 12:15 
GeneralRe: How to make member functions of an application accessible by a DLL? Pin
Arris742-Aug-11 20:36
Arris742-Aug-11 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.