Com object using c++ related question.

R

RKS

I am new to Com programming using C++. Can pointers be passed through
interface functions. I would like to pass multi dimensional arrays to
functions defined in the com interface. Any help is greatly
appreciated.
Thanks
P.S It this topic is completely unrelated to this news group, I am
sorry.
 
V

Victor Bazarov

RKS said:
I am new to Com programming using C++.

....and COM is not topical in this newsgroup, you know that, right?
Can pointers be passed through
interface functions. I would like to pass multi dimensional arrays to
functions defined in the com interface. Any help is greatly
appreciated.
Thanks
P.S It this topic is completely unrelated to this news group, I am
sorry.

Try some forum in the 'microsoft.public.*' hierarchy.

V
 
A

admin

I am a COM programmer utilizing MSVC++ 5&6. The answer to your question
is yes you can pass a multi dimensional array pointer as a function
parameter. The trick is to make sure the pointer is of the right type
and defined correctly. With array pointers the pointer declared will
point to the address of the first array element.

char string[10], *pStr;
pStr=string;

The array pointer pStr will point to the address of the first element
in the array thus when passing thru functions the same rule applies.
By passing the address of the first element you have the entire array
available to the function.

Address Assignments:
*pStr ->string[0]

*(pStr+1)->string[1]
*(pStr+2)->string[2]

Function passing array pointer parameter:

void pfchararray(char *string[]) // Simple but effective method
{
int x;

for(int x=0; x<10; x++)
printf("%c",*string[x]);

}

Data type matching is important when passing array pointers to
functions...
 
A

admin

Sorry I used a one dimensional array in the previous example...

When using multidimensional arrays use a double pointer to the type
representing an additional element group.
 
A

admin

Some basic code to handle a pointer to a mutidimentional integer array
:

#include <stdio.h>

#define rows 2
#define cols 3


void wr(int *ptr); // Write the pointer contents

int main(void)
{
// Create and initalize the integer array
int array[rows][cols]={1,2,3,4,5,6};

// int pointer to 1st array element.
int *ptr=&array[0][0];

wr(ptr); // Print the array passing a int pointer



return 0;
}

/* Function to write the elements by reference [address] */
void wr(int *ptr)
{
// Print the array elements
for(int i=0; i<6; i++)
printf("%d",*(ptr+i));
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top