473,322 Members | 1,690 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,322 software developers and data experts.

Interop: failure returning a value from unmanaged dll

part 1: there is a NON - COM unmanaged dll in VC++ 6.0
BOOL function(char * name, int nOption)

part 2: there is a C# web service that has to consume the above DLL
used DLLImport to call the Non-COM Dll.
[DllImport("Dllname.dll", EntryPoint = "function",

used "Debug Unmanaged Code" to step into DLL.

the DLL gets the right values, processes the steps properly.

however when the value is returned to the C# Webservice
no matter if the return from the unmanaged DLL is TRUE (1) or FALSE
(0), the bool in the C# webservice is always 0/false

the DLL DOES return BOOL which is a 4 byte int , hence im led to
believe that it should be marshalled properly into a C# 'bool'

as alternatives have done the following.

- tried casting the BOOL to an int using Convert.ToInt32()

trying to convert the ENTIRE unmanaged DLL into a COM application is
not something i am able to do ....

suggestions ??

TIA

May 3 '06 #1
7 1696
ConfNoob,

You haven't shown the declaration of the function in C#. Can you
provide that?

Also, are you sure that the calling convention is correct?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ConfNoob" <Ro*********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
part 1: there is a NON - COM unmanaged dll in VC++ 6.0
BOOL function(char * name, int nOption)

part 2: there is a C# web service that has to consume the above DLL
used DLLImport to call the Non-COM Dll.
[DllImport("Dllname.dll", EntryPoint = "function",

used "Debug Unmanaged Code" to step into DLL.

the DLL gets the right values, processes the steps properly.

however when the value is returned to the C# Webservice
no matter if the return from the unmanaged DLL is TRUE (1) or FALSE
(0), the bool in the C# webservice is always 0/false

the DLL DOES return BOOL which is a 4 byte int , hence im led to
believe that it should be marshalled properly into a C# 'bool'

as alternatives have done the following.

- tried casting the BOOL to an int using Convert.ToInt32()

trying to convert the ENTIRE unmanaged DLL into a COM application is
not something i am able to do ....

suggestions ??

TIA

May 3 '06 #2
public static extern bool function(string name,int nOption);

is how its declared in C#

"CallingConvention = CallingConvention.StdCall"

is what i've specified in the DllImport()

thanks again

May 4 '06 #3

"ConfNoob" <Ro*********@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
| public static extern bool function(string name,int nOption);
|
| is how its declared in C#
|
| "CallingConvention = CallingConvention.StdCall"
|
| is what i've specified in the DllImport()
|
| thanks again
|

Oh, and who guarantees that the function uses the stdcall convention?

Willy.
May 4 '06 #4

"ConfNoob" <Ro*********@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
| public static extern bool function(string name,int nOption);
|
| is how its declared in C#
|
| "CallingConvention = CallingConvention.StdCall"
|
| is what i've specified in the DllImport()
|
| thanks again
|

Try this: declare the function to return an int and check for the value 0 or
!= 0.

public static extern int function(string name,int nOption);

....

if(function(string name,int nOption) != 0)
// function returned non 0 (TRUE) value
else
// function returned 0 (FALSE)

If this works, the bool version should work also.

Willy.

May 4 '06 #5
thanks Willy for the replies.

will try those.

May 5 '06 #6
hi Willy,

do you suggest that i make the change in the VC++ DLL to return an int
?

thanks again.

May 8 '06 #7
No, I just need to be sure the return type is a BOOL (which is typedef'd as
an int), so I like to see the value 0 for FALSE and !=0 for TRUE returned.
If this is true, the signature bool function(...) is correct and bool should
be true or false depending on the value of the int, however, if the C return
type is a bool (a byte), then the value of bool will always be fase as the
interop layer expects an int returned from C.

Willy.

"ConfNoob" <Ro*********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
| hi Willy,
|
| do you suggest that i make the change in the VC++ DLL to return an int
| ?
|
| thanks again.
|
May 8 '06 #8

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

Similar topics

4
by: breathwell | last post by:
Consider a C# function that logs an error string and returns a new Exception object: System.Exception LogError(string msg) { ... return new Exception(msg); }
0
by: Boris | last post by:
The .NET documentation talks about blittable and non-blittable types. While objects of type System::Object* are non-blittable it doesn't say anything about objects of user-defined classes. All the...
4
by: DotNetJunkies User | last post by:
I am calling a VB6 dll from a vb.net windows application that returns an array of strings. My issue is it seems to truncate after a NULL character. For Example VB 6 is returning a string with the...
7
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
0
by: R Reyes | last post by:
ISSUE (reposted) =========================== Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? For many people, they say they add the...
1
by: R Reyes | last post by:
ISSUE (reposted) =========================== Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? For many people, they say they add the...
1
by: Zach | last post by:
I have both an unmanaged DLL written in C++, and a Windows Forms application from which I'm trying to use the services of the unmanaged DLL. I seem to have everything set up correctly, but I'd...
5
by: Yoavo | last post by:
Hi, In my application I have to use som external COM dll's. In the code: using MyDll when I build the project, I get (in addition to the .exe file) a Dll called Interop.MyDll.dll I want to...
0
by: user2008 | last post by:
Hi everybody, I'm working on exposing a .Net (C#) COM Server. Manage Code is exposting an interface with two methods. These methods take an IN/OUT Struct as parameter. Requirement is that the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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

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.