469,928 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

Passing Array from C# manged code to unmanged code

Hi,
I m facing a problem in re-writing a code from VB to C #. We are using
a third party DLL to develop a application of Fax. The current
application is already written in VB and we have to convert it into
C#. In VB we are using a function from the DLL whose signature is like
:

Declare Function RFVB_SendFiles1 Lib "RF2VB.DLL" (ByVal hServer As
Long, _
ByVal lFI10Object As
Long, _
ByVal lNI10Object As
Long, _
ByVal fSendWithCover
As Boolean, _
sCoverSheetModel As
String, _
aFiles() As String,
_
hNewFax As Long) As
Long

Now in C# , we are having problems in converting the signature of this
function. We tried the following , but it didn't work. It doesn't give
any error at compile time but at run time this function doesn't work.
I m suspecting that passing a array has some problem

[DLLImport("RF2VB.dll")]
public static extern int RFVB_SendFiles1(int hServer, int lFI10Object
, int lNI10Object, bool fSendWithCover,ref string sCoverSheetModel,
[MarshalAs(UnmanagedType.SafeArray,SafeArraySubType =
VarEnum.VT_BSTR)] ref string [] aFiles ,ref int hNewFax);

Does anybody has any idea of declaring this properly.

Thanks,
Manish
Nov 15 '05 #1
2 2855
Manish,

I see two problems with this declaration. The first is with the array.
You can not pass the array the way that you are passing it (by ref). You
should marshal the array as is, without the ref modifier.

Also, in VB, a boolean is 16 bits, so you will have to pass it as a
short in .NET. Your declaration should look like this:

[DLLImport("RF2VB.dll")]
public static extern int RFVB_SendFiles1(
int hServer,
int lFI10Object,
int lNI10Object,
short fSendWithCover,
string sCoverSheetModel,
string[] aFiles ,
ref int hNewFax);

Do you have the declaration of the function in a C++ header file? It is
possible that the declarations of the parameters were tailored for VB, but
without it, it is hard to tell.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Manish" <mm*******@filenet.com> wrote in message
news:4d*************************@posting.google.co m...
Hi,
I m facing a problem in re-writing a code from VB to C #. We are using
a third party DLL to develop a application of Fax. The current
application is already written in VB and we have to convert it into
C#. In VB we are using a function from the DLL whose signature is like
:

Declare Function RFVB_SendFiles1 Lib "RF2VB.DLL" (ByVal hServer As
Long, _
ByVal lFI10Object As
Long, _
ByVal lNI10Object As
Long, _
ByVal fSendWithCover
As Boolean, _
sCoverSheetModel As
String, _
aFiles() As String,
_
hNewFax As Long) As
Long

Now in C# , we are having problems in converting the signature of this
function. We tried the following , but it didn't work. It doesn't give
any error at compile time but at run time this function doesn't work.
I m suspecting that passing a array has some problem

[DLLImport("RF2VB.dll")]
public static extern int RFVB_SendFiles1(int hServer, int lFI10Object
, int lNI10Object, bool fSendWithCover,ref string sCoverSheetModel,
[MarshalAs(UnmanagedType.SafeArray,SafeArraySubType =
VarEnum.VT_BSTR)] ref string [] aFiles ,ref int hNewFax);

Does anybody has any idea of declaring this properly.

Thanks,
Manish

Nov 15 '05 #2
Nicholas,

I tried with what you suggested but it didn't work too. I got an Invalid
Parameter Passed error froim the API. Unfortunatelty I don't have the
C++ header file , All I have is the dll.

Thanks,
Manish

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by codymanix | last post: by
6 posts views Thread by brian_harris | last post: by
3 posts views Thread by brian_harris | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.