473,320 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

String Array in Interop

Hi All,

I am trying to use COM DLL in my C#.
I have added this DLL in referance and all interface are working fine.

I have one issue in calling function decleared like:
void SetSharedDirs(String Arrary* DirPaths);

For this function, C# is having the interop like:
public abstract new void SetSharedDirs ( System.Object pDirPaths )

Now i need to call this function from my C# program.
Below is the snapshot of my code. It throws exception as "Type Mismatch".
Can somebody help me out?

string[] sDirs = new string[]{"C:\\Program Files\\myApp\\Downloads"};
object objDirs = sDirs;
Share.SetSharedDirs(ref objDirs);

In this Share is the interface from DLL. All other functions in that
interface are working. But none of other functions having string array as
parameter.

Any help will be greatly appreciated.

Thanks,
Sudha.
Nov 16 '05 #1
6 5875
I am not sure but should the call
Share.SetSharedDirs(ref objDirs); need [ref] key word there?

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com... Hi All,

I am trying to use COM DLL in my C#.
I have added this DLL in referance and all interface are working fine.

I have one issue in calling function decleared like:
void SetSharedDirs(String Arrary* DirPaths);

For this function, C# is having the interop like:
public abstract new void SetSharedDirs ( System.Object pDirPaths )

Now i need to call this function from my C# program.
Below is the snapshot of my code. It throws exception as "Type Mismatch".
Can somebody help me out?

string[] sDirs = new string[]{"C:\\Program Files\\myApp\\Downloads"};
object objDirs = sDirs;
Share.SetSharedDirs(ref objDirs);

In this Share is the interface from DLL. All other functions in that
interface are working. But none of other functions having string array as
parameter.

Any help will be greatly appreciated.

Thanks,
Sudha.

Nov 16 '05 #2
Hi Girish,

Thanks for your reply.

Yes. "ref" is needed.
Actually while typing in my post, i missed "ref".
C# is having the interop like:
public abstract new void SetSharedDirs ( ref System.Object pDirPaths )

I am kind of stuck with this problem.... It will be great if you can help me
out.

Thanks.

"Girish Bharadwaj" wrote:
I am not sure but should the call
Share.SetSharedDirs(ref objDirs);

need [ref] key word there?

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
Hi All,

I am trying to use COM DLL in my C#.
I have added this DLL in referance and all interface are working fine.

I have one issue in calling function decleared like:
void SetSharedDirs(String Arrary* DirPaths);

For this function, C# is having the interop like:
public abstract new void SetSharedDirs ( System.Object pDirPaths )

Now i need to call this function from my C# program.
Below is the snapshot of my code. It throws exception as "Type Mismatch".
Can somebody help me out?

string[] sDirs = new string[]{"C:\\Program Files\\myApp\\Downloads"};
object objDirs = sDirs;
Share.SetSharedDirs(ref objDirs);

In this Share is the interface from DLL. All other functions in that
interface are working. But none of other functions having string array as
parameter.

Any help will be greatly appreciated.

Thanks,
Sudha.


Nov 16 '05 #3
Can you check out
http://msdn.microsoft.com/library/de...gforarrays.asp
... It shows an array of strings (Safearray of strings to be exact) with the
following

HRESULT New([in] SAFEARRAY( BSTR ) ar);

to be having a managed signature of

void New( String [,] ar );

Do you think you can use a similar signature for your object?
--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
Hi Girish,

Thanks for your reply.

Yes. "ref" is needed.
Actually while typing in my post, i missed "ref".
C# is having the interop like:
public abstract new void SetSharedDirs ( ref System.Object pDirPaths )

I am kind of stuck with this problem.... It will be great if you can help me out.

Thanks.

"Girish Bharadwaj" wrote:
I am not sure but should the call
Share.SetSharedDirs(ref objDirs);

need [ref] key word there?

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
Hi All,

I am trying to use COM DLL in my C#.
I have added this DLL in referance and all interface are working fine.

I have one issue in calling function decleared like:
void SetSharedDirs(String Arrary* DirPaths);

For this function, C# is having the interop like:
public abstract new void SetSharedDirs ( System.Object pDirPaths )

Now i need to call this function from my C# program.
Below is the snapshot of my code. It throws exception as "Type Mismatch". Can somebody help me out?

string[] sDirs = new string[]{"C:\\Program Files\\myApp\\Downloads"};
object objDirs = sDirs;
Share.SetSharedDirs(ref objDirs);

In this Share is the interface from DLL. All other functions in that
interface are working. But none of other functions having string array as parameter.

Any help will be greatly appreciated.

Thanks,
Sudha.


Nov 16 '05 #4
Hi Girish,

I am new to C# and Interop. The COM DLL i am using is 3rd parties DLL.
Please correct me if i am wronge:
I have added that DLL in my C# project under "Referance".
It generats some interop files.

The link you gave explains how to marshall the paraments etc..
Do i need to marshall the interface and all of its functions?
How can i marshall only one function from one interface.

This COM dll is having lot of interfaces. And Each interface is having many
functions.

I am bit confused.

I appreciate your time.

Thanks.
"Girish bharadwaj" wrote:
Can you check out
http://msdn.microsoft.com/library/de...gforarrays.asp
... It shows an array of strings (Safearray of strings to be exact) with the
following

HRESULT New([in] SAFEARRAY( BSTR ) ar);

to be having a managed signature of

void New( String [,] ar );

Do you think you can use a similar signature for your object?
--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
Hi Girish,

Thanks for your reply.

Yes. "ref" is needed.
Actually while typing in my post, i missed "ref".
C# is having the interop like:
public abstract new void SetSharedDirs ( ref System.Object pDirPaths )

I am kind of stuck with this problem.... It will be great if you can help

me
out.

Thanks.

"Girish Bharadwaj" wrote:
I am not sure but should the call
> Share.SetSharedDirs(ref objDirs);
need [ref] key word there?

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
> Hi All,
>
> I am trying to use COM DLL in my C#.
> I have added this DLL in referance and all interface are working fine.
>
> I have one issue in calling function decleared like:
> void SetSharedDirs(String Arrary* DirPaths);
>
> For this function, C# is having the interop like:
> public abstract new void SetSharedDirs ( System.Object pDirPaths )
>
> Now i need to call this function from my C# program.
> Below is the snapshot of my code. It throws exception as "Type Mismatch". > Can somebody help me out?
>
> string[] sDirs = new string[]{"C:\\Program Files\\myApp\\Downloads"};
> object objDirs = sDirs;
> Share.SetSharedDirs(ref objDirs);
>
> In this Share is the interface from DLL. All other functions in that
> interface are working. But none of other functions having string array as > parameter.
>
> Any help will be greatly appreciated.
>
> Thanks,
> Sudha.
>
>


Nov 16 '05 #5
Did i ask anything silly??
"Sudha" wrote:
Hi Girish,

I am new to C# and Interop. The COM DLL i am using is 3rd parties DLL.
Please correct me if i am wronge:
I have added that DLL in my C# project under "Referance".
It generats some interop files.

The link you gave explains how to marshall the paraments etc..
Do i need to marshall the interface and all of its functions?
How can i marshall only one function from one interface.

This COM dll is having lot of interfaces. And Each interface is having many
functions.

I am bit confused.

I appreciate your time.

Thanks.
"Girish bharadwaj" wrote:
Can you check out
http://msdn.microsoft.com/library/de...gforarrays.asp
... It shows an array of strings (Safearray of strings to be exact) with the
following

HRESULT New([in] SAFEARRAY( BSTR ) ar);

to be having a managed signature of

void New( String [,] ar );

Do you think you can use a similar signature for your object?
--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
Hi Girish,

Thanks for your reply.

Yes. "ref" is needed.
Actually while typing in my post, i missed "ref".
C# is having the interop like:
public abstract new void SetSharedDirs ( ref System.Object pDirPaths )

I am kind of stuck with this problem.... It will be great if you can help

me
out.

Thanks.

"Girish Bharadwaj" wrote:

> I am not sure but should the call
> > Share.SetSharedDirs(ref objDirs);
> need [ref] key word there?
>
> --
> Girish Bharadwaj
> http://msmvps.com/gbvb
> "Sudha" <Su***@discussions.microsoft.com> wrote in message
> news:A1**********************************@microsof t.com...
> > Hi All,
> >
> > I am trying to use COM DLL in my C#.
> > I have added this DLL in referance and all interface are working fine.
> >
> > I have one issue in calling function decleared like:
> > void SetSharedDirs(String Arrary* DirPaths);
> >
> > For this function, C# is having the interop like:
> > public abstract new void SetSharedDirs ( System.Object pDirPaths )
> >
> > Now i need to call this function from my C# program.
> > Below is the snapshot of my code. It throws exception as "Type

Mismatch".
> > Can somebody help me out?
> >
> > string[] sDirs = new string[]{"C:\\Program Files\\myApp\\Downloads"};
> > object objDirs = sDirs;
> > Share.SetSharedDirs(ref objDirs);
> >
> > In this Share is the interface from DLL. All other functions in that
> > interface are working. But none of other functions having string array

as
> > parameter.
> >
> > Any help will be greatly appreciated.
> >
> > Thanks,
> > Sudha.
> >
> >
>
>
>


Nov 16 '05 #6
Look into this thread that went on in interop group. Your problem seems to
be very similar to what he ran into. He managed to solve it with
VariantWrapper.

http://groups.google.com/groups?q=Je...phx.gbl&rnum=1

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
Hi Girish,

I am new to C# and Interop. The COM DLL i am using is 3rd parties DLL.
Please correct me if i am wronge:
I have added that DLL in my C# project under "Referance".
It generats some interop files.

The link you gave explains how to marshall the paraments etc..
Do i need to marshall the interface and all of its functions?
How can i marshall only one function from one interface.

This COM dll is having lot of interfaces. And Each interface is having many functions.

I am bit confused.

I appreciate your time.

Thanks.
"Girish bharadwaj" wrote:
Can you check out
http://msdn.microsoft.com/library/de...gforarrays.asp ... It shows an array of strings (Safearray of strings to be exact) with the following

HRESULT New([in] SAFEARRAY( BSTR ) ar);

to be having a managed signature of

void New( String [,] ar );

Do you think you can use a similar signature for your object?
--
Girish Bharadwaj
http://msmvps.com/gbvb
"Sudha" <Su***@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
Hi Girish,

Thanks for your reply.

Yes. "ref" is needed.
Actually while typing in my post, i missed "ref".
C# is having the interop like:
public abstract new void SetSharedDirs ( ref System.Object pDirPaths )
I am kind of stuck with this problem.... It will be great if you can help
me
out.

Thanks.

"Girish Bharadwaj" wrote:

> I am not sure but should the call
> > Share.SetSharedDirs(ref objDirs);
> need [ref] key word there?
>
> --
> Girish Bharadwaj
> http://msmvps.com/gbvb
> "Sudha" <Su***@discussions.microsoft.com> wrote in message
> news:A1**********************************@microsof t.com...
> > Hi All,
> >
> > I am trying to use COM DLL in my C#.
> > I have added this DLL in referance and all interface are working
fine. > >
> > I have one issue in calling function decleared like:
> > void SetSharedDirs(String Arrary* DirPaths);
> >
> > For this function, C# is having the interop like:
> > public abstract new void SetSharedDirs ( System.Object pDirPaths )
> >
> > Now i need to call this function from my C# program.
> > Below is the snapshot of my code. It throws exception as "Type

Mismatch".
> > Can somebody help me out?
> >
> > string[] sDirs = new string[]{"C:\\Program Files\\myApp\\Downloads"}; > > object objDirs = sDirs;
> > Share.SetSharedDirs(ref objDirs);
> >
> > In this Share is the interface from DLL. All other functions in that > > interface are working. But none of other functions having string

array as
> > parameter.
> >
> > Any help will be greatly appreciated.
> >
> > Thanks,
> > Sudha.
> >
> >
>
>
>


Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rob Mayo | last post by:
How can I create a pointer to a string array from VB.Net? I want to take a string array of variable size and pass it as a wParam on a message to a custom subclassed window. I've tried wrapping the...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
10
by: Dennis Myrén | last post by:
Hi. I have an array of struct. My question is, if i do: STRUCT a = new STRUCT ; STRUCT s = new STRUCT(); a = s; since STRUCT is a value type, when assigning element 0 of the STRUCT array...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
5
by: Lonewolf | last post by:
Hi, I'm not sure if this has been asked before so please pardon me if this is a repeated question. Basically I have some performance critical directshow codes which is implemented in native,...
9
by: mupe | last post by:
Hi, i have a problem with a Type Library, which is written in C++. I am developing an application in C#.NET and have to use functions from this COM-Type Library. When I use these functions in...
6
by: Boni | last post by:
Dear all, I have written a C++ COM object: STDMETHOD(myfunc)(INT* array) Now I need to pass an array from c# to COM. I generated a COM interop and the signature of the function is ...
6
by: Arnshea | last post by:
(apologies for the crosspost) I'm working with an MFC based COM object. From C# I'd like to be able to call a method on the COM object that takes a string array and modifies the contents. Is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.