Click here to Skip to main content
15,904,823 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: What's the workspace coordinates in WINDOWS ? Pin
Charles Oppermann5-Aug-11 4:24
Charles Oppermann5-Aug-11 4:24 
GeneralRe: What's the workspace coordinates in WINDOWS ? Pin
Cold_Fearing_Bird5-Aug-11 4:37
Cold_Fearing_Bird5-Aug-11 4:37 
GeneralRe: What's the workspace coordinates in WINDOWS ? Pin
Charles Oppermann5-Aug-11 6:23
Charles Oppermann5-Aug-11 6:23 
QuestionFlickering problem in list control Pin
MKC0025-Aug-11 0:46
MKC0025-Aug-11 0:46 
AnswerRe: Flickering problem in list control Pin
Chris Meech5-Aug-11 2:15
Chris Meech5-Aug-11 2:15 
AnswerRe: Flickering problem in list control Pin
Richard MacCutchan5-Aug-11 3:38
mveRichard MacCutchan5-Aug-11 3:38 
AnswerRe: Flickering problem in list control Pin
Rolf Kristensen9-Aug-11 10:34
Rolf Kristensen9-Aug-11 10:34 
QuestionWDM kernel driver: ZwClose in timed procedure causes bluescreen Pin
J. Ruffing4-Aug-11 22:49
J. Ruffing4-Aug-11 22:49 
AnswerRe: WDM kernel driver: ZwClose in timed procedure causes bluescreen Pin
Ahmed Charfeddine8-Aug-11 0:24
Ahmed Charfeddine8-Aug-11 0:24 
QuestionWhat's the real difference between POPUP window and OVERLAPPED window Pin
Cold_Fearing_Bird3-Aug-11 23:50
Cold_Fearing_Bird3-Aug-11 23:50 
AnswerRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Richard MacCutchan4-Aug-11 1:27
mveRichard MacCutchan4-Aug-11 1:27 
GeneralRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Albert Holguin4-Aug-11 17:40
professionalAlbert Holguin4-Aug-11 17:40 
GeneralRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Cold_Fearing_Bird4-Aug-11 21:42
Cold_Fearing_Bird4-Aug-11 21:42 
GeneralRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Richard MacCutchan4-Aug-11 23:01
mveRichard MacCutchan4-Aug-11 23:01 
GeneralRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Albert Holguin5-Aug-11 4:24
professionalAlbert Holguin5-Aug-11 4:24 
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 

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.