Click here to Skip to main content
14,767,499 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hai, in my application i am using Pinvoke method from c# wpf to C++ dll.i created the same structure in c# which was in c++ dll and i am calling the method with ref of my struct from c# and then there is no problem.for some dynamic purpose i am using callback delegate method at that time i cant able to pass the ref of struct so i sent the Intptr to get the address from c++ dll,now i am getting the address of mystruct but now i need to get the values from the pointer value is it possible to do like these or any other method please suggest me.

What I have tried:

i have tried,i pass the ref struct from c# to c++ without callback,facing problemm when i use call back method.
Posted
Updated 3 days ago
Comments
KarstenK 3 days ago
   
Creating a copy is solution which is providibf you less headaches.

   
Comments
Fazi_13 3 days ago
   
Thanks
C# uses garbage collection to compact the objects in the memory from time to time, so the address of objects may change. The address you saved might not be valid or pointing to the same object. Intptr pins the object during the pinvoke. After the intptr variable goes out of scope, the object is not pinned and may be moved during a GC. So instead of saving the address, you should save the index/position of that object in an array or List.
   
Comments
Fazi_13 3 days ago
   
Okey i will try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900