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

Using a C Library in a managed DLL

I have a .LIB file, built an compiled in C that I need to use in
my .NET application.

If I build a C++.Net Console application and activate the exposed
functions directly the library works perfectly.

If I try to compile the .LIB file into a managed DLL for use in either
my VB.Net GUI or my managed C++.Net Console application I get a Null
Reference Exception when the LIB makes a MALLOC call.

Is there some command or option that I need to set to allow my managed
DLL to be able to run MALLOC?

Thanks!

Mar 30 '07 #1
4 2022

"Kidan" <ss********@gmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
>I have a .LIB file, built an compiled in C that I need to use in
my .NET application.

If I build a C++.Net Console application and activate the exposed
functions directly the library works perfectly.

If I try to compile the .LIB file into a managed DLL for use in either
my VB.Net GUI or my managed C++.Net Console application I get a Null
Reference Exception when the LIB makes a MALLOC call.
What you can't do is call malloc in the DLL and free in the C++ console
application. Otherwise what you describe should work. Double-check the
argument to malloc and make sure it's reasonable, perhaps you are trying to
allocate sizeof(int) * -1 or something.
>
Is there some command or option that I need to set to allow my managed
DLL to be able to run MALLOC?
No, not really. Although operator new is preferred over malloc for C++
programs.
>
Thanks!

Mar 30 '07 #2
>
What you can't do is call malloc in the DLL and free in the C++ console
application. Otherwise what you describe should work. Double-check the
argument to malloc and make sure it's reasonable, perhaps you are trying to
allocate sizeof(int) * -1 or something.
The malloc call is within the precompiled .LIB file so I don't have
access to it's calls/arguments.

No, not really. Although operator new is preferred over malloc for C++
programs.
Yeah, I prefer new, but unfortunately the precompiled library is in C.

Mar 30 '07 #3

"Kidan" <ss********@gmail.comwrote in message
news:11**********************@p15g2000hsd.googlegr oups.com...
>
>>
What you can't do is call malloc in the DLL and free in the C++ console
application. Otherwise what you describe should work. Double-check the
argument to malloc and make sure it's reasonable, perhaps you are trying
to
allocate sizeof(int) * -1 or something.
The malloc call is within the precompiled .LIB file so I don't have
access to it's calls/arguments.
Then how do you know that malloc is failing?

You could also provide your own malloc/free implementations as a thin
wrapper around HeapAlloc, with some extra logging.
Mar 30 '07 #4
>
The malloc call is within the precompiled .LIB file so I don't have
access to it's calls/arguments.

Then how do you know that malloc is failing?

You could also provide your own malloc/free implementations as a thin
wrapper around HeapAlloc, with some extra logging.
Because when I get the null reference exception, the C++ debugger
takes me to a malloc call (the VB.Net debugger just took me to
the .LIB call).

Apr 4 '07 #5

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

Similar topics

3
by: Michael Howes | last post by:
I have some old C code that uses MFC and some C Run Time Library. I need to be able to call this from C# I thought i'd be able to create a Managed C++ DLL, tell the project it was using MFC, ...
12
by: Wayne | last post by:
We have some old win32 apps and I still need to support these applications. I'd like to do new and future enhancements in C#, if at all possible. Is there a way to use a .net assembly in a normal...
47
by: Bonj | last post by:
I downloaded the gzlib library from zlib in order to do compression. (http://www.gzip.org/zlib) The prototype of the compression function seems to be int compress (Bytef *dest, uLongf *destLen,...
8
by: Mas L via DotNetMonster.com | last post by:
Hi, I have a c++ source code which I can compile to be a DLL (in VS.NET 2003). And I need to use it in a C# program. After I compiled/build the C++ code to a DLL, I add it as a Reference in my...
3
by: mirek | last post by:
Hi, I've got problem building managed class library to wrap unmanaged code. I created managed class library using standard patten: #include "../Unmanaged/Class1.h" //Class1 unmanaged ...
7
by: rCs | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
1
by: pikulsky | last post by:
There is a managed C++ class (ManagedClass) defined in one library (TestMCpp.dll), it has a method (funcTemplate) with template native type (NativeTemplate<int>). This library is built without any...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
4
by: colin | last post by:
Hi, Is there an easy way to do 3d drawing using drect3d8 devices in c# ? please dont suggest using directx9 unless there is a way to use directx9 on devices with only direct3d8 support. the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.