Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Problem with C++ DLL returning bool

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thorsten Dittmar - 20 Mar 2008 13:36 GMT
Hi there,

we have this C++ DLL we wrote some time ago to do some Win32 native
stuff for us.

The function we're calling in the DLL returns a boolean value (type
bool) indicating success of the operation.

We declare the import in C# like follows:

DllImport("xyz.dll")]
private static extern bool DoSomething(...);

We call the function like this:

bool result = DoSomething(...);

Now: we're using this in Visual Studio 2008. When we set the target
framework version to 2.0 everything works fine - the function returns
false, the result-variable has the value false.

As soon as we switch the target framework version to 3.5 (no other
changes to the project), the C++ function still returns false, but the
result-variable is set to true!

How could that be?

As a workaround we've change the result type from bool to int, returning
defined values for success or failure, but this is not very satisfactory...

Any advice?

Thanks
Thorsten
Willy Denoyette [MVP] - 20 Mar 2008 13:47 GMT
> Hi there,
>
[quoted text clipped - 31 lines]
> Thanks
> Thorsten

If you are sure that the C function returns a bool, and not a BOOL, then it
should work, else you should marshal the return value using:

[return: MarshalAs(UnmanagedType.Bool)]

Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.