By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

Com object using c++ related question.

P: n/a
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.

Apr 12 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
RKS wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 12 '06 #2

P: n/a
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...

Apr 13 '06 #3

P: n/a
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.

Apr 13 '06 #4

P: n/a
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));
}

Apr 14 '06 #5

P: n/a
RKS
Thanks a lot for the help. It works!!.

Apr 14 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.