Click here to Skip to main content
15,886,199 members
Home / Discussions / C#
   

C#

 
AnswerRe: sizeof Pin
TJoe5-Sep-07 8:50
TJoe5-Sep-07 8:50 
GeneralRe: sizeof Pin
Luc Pattyn5-Sep-07 10:02
sitebuilderLuc Pattyn5-Sep-07 10:02 
GeneralRe: sizeof Pin
TJoe5-Sep-07 10:19
TJoe5-Sep-07 10:19 
GeneralRe: sizeof Pin
dino20945-Sep-07 11:54
dino20945-Sep-07 11:54 
QuestionProblem passing data to an activeX Pin
Paolo Vernazza5-Sep-07 6:55
Paolo Vernazza5-Sep-07 6:55 
AnswerRe: Problem passing data to an activeX Pin
TJoe5-Sep-07 8:23
TJoe5-Sep-07 8:23 
GeneralRe: Problem passing data to an activeX Pin
Paolo Vernazza6-Sep-07 1:57
Paolo Vernazza6-Sep-07 1:57 
GeneralRe: Problem passing data to an activeX Pin
TJoe6-Sep-07 2:13
TJoe6-Sep-07 2:13 
Do you have access to the ActiveX source code? Or is it publicly available? If you have access, could you post examples of PutData and GetData. If it's publicly available, could you please provide a link.

If GetData is updating bptr2 so that it has the same value as bptr, then I would assume that PutData simply stored the long* that was passed in (instead of copying it). Then GetData is simply passing out the same long*. If this is the case then you do not need to allocate ptr2, because GetData does not required you to pass in a pre-allocated buffer.

This really depends on how the OCX methods are written and you would need a full understanding of how they work to properly use them. For example, if the PutData does in fact save the long* that was passed in, then the code below would cause access violations:

// Create buffer
Int32[] buffer = new Int32[10];
buffer[5] = 1;

// Allocate and copy to unmanaged memory
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32)) * 10);
Marshal.Copy(buffer, 0, ptr, 10);

// **** Need to add this, otherwise c# complains about not being able to convert IntPtr to int
int bptr = (int)ptr;
ocx.PutData(ref bptr, Marshal.SizeOf(typeof(Int32)) * 10);

// Change buffer, so we can see that the ptr has restored the
// old value
buffer[5] = 2;

// Free memory, or else we will leak it
Marshal.FreeHGlobal(ptr);

// ... Somewhere else in code


// **** Allocate another are to retrieve data
IntPtr ptr2 = IntPtr.Zero;
int bptr2 = (int)ptr2;

ocx.GetData(ref bptr2);

// Copy from unmanged memory back to array
Marshal.Copy(ptr2, buffer, 0, 10);


In the code above, the long* that was cached is freed and then is accessed later. If you are only using the OCX in a serial fashion like your example, then it would be fine.

Let me know if this makes sense.


Take care,
Tom

-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com

GeneralRe: Problem passing data to an activeX Pin
Paolo Vernazza6-Sep-07 4:33
Paolo Vernazza6-Sep-07 4:33 
GeneralRe: Problem passing data to an activeX Pin
TJoe6-Sep-07 5:08
TJoe6-Sep-07 5:08 
QuestionHow to limit maximum size of other windows? Pin
Trickster-SWE5-Sep-07 6:33
Trickster-SWE5-Sep-07 6:33 
AnswerRe: How to limit maximum size of other windows? Pin
TJoe5-Sep-07 8:06
TJoe5-Sep-07 8:06 
GeneralRe: How to limit maximum size of other windows? Pin
Trickster-SWE5-Sep-07 22:33
Trickster-SWE5-Sep-07 22:33 
QuestionRegex replace question Pin
Vodstok5-Sep-07 6:13
Vodstok5-Sep-07 6:13 
AnswerRe: Regex replace question Pin
TJoe5-Sep-07 8:00
TJoe5-Sep-07 8:00 
Questionrow doesn't get deleted Pin
gericooper5-Sep-07 5:27
gericooper5-Sep-07 5:27 
QuestionVisual Studio Menu Layout Pin
DanB19835-Sep-07 5:13
DanB19835-Sep-07 5:13 
AnswerRe: Visual Studio Menu Layout Pin
martin_hughes5-Sep-07 5:54
martin_hughes5-Sep-07 5:54 
QuestionForm problem Pin
sajid.salim.khan5-Sep-07 4:52
sajid.salim.khan5-Sep-07 4:52 
AnswerRe: Form problem Pin
Christian Graus5-Sep-07 5:07
protectorChristian Graus5-Sep-07 5:07 
GeneralRe: Form problem Pin
sajid.salim.khan5-Sep-07 5:53
sajid.salim.khan5-Sep-07 5:53 
GeneralRe: Form problem Pin
Christian Graus5-Sep-07 8:26
protectorChristian Graus5-Sep-07 8:26 
QuestionExcel Layout change Pin
ramdil5-Sep-07 4:34
ramdil5-Sep-07 4:34 
QuestionRead only row in Datagrid Pin
André Stroebel5-Sep-07 4:11
André Stroebel5-Sep-07 4:11 
AnswerRe: Read only row in Datagrid Pin
André Stroebel5-Sep-07 4:32
André Stroebel5-Sep-07 4:32 

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.