473,738 Members | 3,658 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 3018
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
1849
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
3546
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++ methods and it should just work; however, when I try it, my C# instance comes out null. If I step...
3
1469
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
4681
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++ methods and it should just work; however, when I try it, my C# instance comes out null. If I step...
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
1506
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 variable and make assignments correctly so that it will have value when it is back in outher...
3
1822
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' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name...
0
1867
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
4423
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 the same pointer to the first method in my interface and look at the values in .net then thay are...
0
8968
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8208
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.