473,545 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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, _
sCoverSheetMode l 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("RF2V B.dll")]
public static extern int RFVB_SendFiles1 (int hServer, int lFI10Object
, int lNI10Object, bool fSendWithCover, ref string sCoverSheetMode l,
[MarshalAs(Unman agedType.SafeAr ray,SafeArraySu bType =
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 3013
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("RF2V B.dll")]
public static extern int RFVB_SendFiles1 (
int hServer,
int lFI10Object,
int lNI10Object,
short fSendWithCover,
string sCoverSheetMode l,
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.co m

"Manish" <mm*******@file net.com> wrote in message
news:4d******** *************** **@posting.goog le.com...
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, _
sCoverSheetMode l 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("RF2V B.dll")]
public static extern int RFVB_SendFiles1 (int hServer, int lFI10Object
, int lNI10Object, bool fSendWithCover, ref string sCoverSheetMode l,
[MarshalAs(Unman agedType.SafeAr ray,SafeArraySu bType =
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1840
by: codymanix | last post by:
i want to pass a struct by reference to a function in a c++ dll. the problem is that the call causes an ArgumentException in the calling c# code. i already tried to use "out" instead of "ref" there was no exception generated but i saw in the unmanaged code all fields of the struct were uninitialized! this is my c# code:
1
3509
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to this method and have it set the instance to hold the right data. >From what I've read it seems I should be able to pass C# objects to managed C++...
3
1460
by: Germic | last post by:
Hi, I want to create an Hashtable in C# and pass an pointer to the hashtable to a C code. Later, the C code could reference the hashtable by passing the pointer to the hashtable as a ref parameter. what is the correct way to do this? Thanks,
2
4669
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to this method and have it set the instance to hold the right data. >From what I've read it seems I should be able to pass C# objects to managed C++...
0
242
by: P Reddy | last post by:
Hi All, Greetings!!! I have a question. Please respond.... I am trying to write a C# component that need to inherit some of the the interfaces from unmanged code(VC). I think one way to resolve this is to port unmanged interfaces and header files in to manage C++ as Visual Studio allows porting and compiling all this
6
1491
by: brian_harris | last post by:
I have a function that passes a string class pointer to a function, this function is then suppose to fill it and the outer function uses it. But I believe that I am running into problem due to manged memory. Because it has value in inner function, but does not have the assigned value in outher function. So I need to know how to declare this...
3
1816
by: brian_harris | last post by:
I am tring to start a thread where I am passing info into thread. According to MS documentation I must do this by creating a class for that thread. I have done this but am getting a compiler error. The error is: c:\T02010_NET_ora9\cgi-bin\programs\TimeReader\TimeReaderWinService.cpp(104): error C2475: 'ThreadWithState::readerThread' :...
0
1856
by: ElysianEagle | last post by:
Hi, I have a DLL written in C that creates a structure as a local variable, populates it, and then calls a function in managed c#. here is what im talking about: //-----unmanged code's header file typedef struct M { int a; int b;
3
4413
by: cskarp | last post by:
I have create a .Net component which exposes an interface with two methods. The first method takes an array of structs as a parameter the other method returns an array of (the same tyoes of) structs. When I get the array structures from my second method in unmanaged c++, I cannot regonize any of the parameters in the structures. But if I pass...
0
7490
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7682
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6009
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.