473,396 Members | 2,009 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,396 software developers and data experts.

utilizing unmanaged C++ library

Hi-

I know this is common topic, but I don't intend to ask you guys "how" but
rather "Where can I find samples or tutorials that actually compile??" ;)

I have been attempting to educate myself on this topic for awhile and 3
attempts to download source code and compile have yielded nothing. My most
recent problem is "System.DllNotFound" exception. The DLL is located in the
same directory as my .cs code. I tried to add a reference but recieved an
error that it wasn't a valid type.

I would just really like to see a working example of using an unmanaged code
in C#. Anyone know a good place to read more?

Thanks-
Steve
Nov 16 '05 #1
3 1118
Hi, SteveK.
You can't reference to a unmanaged DLL. You can, however, use
DllImportAttribute to call a unmanaged function in a Dll. See
http://www.codeguru.com/Csharp/Cshar...cle.php/c4217/ for a
simple example.
On the other hand, if the DLL exposes C++ classes, you may have to convert
it into a COM module or build a wrapper with Managed C++.

Regards
Ming Chen

"SteveK" <as***@asdfasdfsd.com> wrote in message
news:eo*************@TK2MSFTNGP14.phx.gbl...
Hi-

I know this is common topic, but I don't intend to ask you guys "how" but
rather "Where can I find samples or tutorials that actually compile??" ;)

I have been attempting to educate myself on this topic for awhile and 3
attempts to download source code and compile have yielded nothing. My most recent problem is "System.DllNotFound" exception. The DLL is located in the same directory as my .cs code. I tried to add a reference but recieved an
error that it wasn't a valid type.

I would just really like to see a working example of using an unmanaged code in C#. Anyone know a good place to read more?

Thanks-
Steve

Nov 16 '05 #2
Thanks for the quick answer, Ming,

I have added my call to DllImport and when I build the project, VS.NET
crashes SUPER fast, if I comment out the DllImport line, it's fine.
Isn't that nice? ;(
-Steve
"Ming Chen" <qq******@yahoo.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Hi, SteveK.
You can't reference to a unmanaged DLL. You can, however, use
DllImportAttribute to call a unmanaged function in a Dll. See
http://www.codeguru.com/Csharp/Cshar...cle.php/c4217/ for a
simple example.
On the other hand, if the DLL exposes C++ classes, you may have to convert it into a COM module or build a wrapper with Managed C++.

Regards
Ming Chen

"SteveK" <as***@asdfasdfsd.com> wrote in message
news:eo*************@TK2MSFTNGP14.phx.gbl...
Hi-

I know this is common topic, but I don't intend to ask you guys "how" but rather "Where can I find samples or tutorials that actually compile??" ;)
I have been attempting to educate myself on this topic for awhile and 3
attempts to download source code and compile have yielded nothing. My

most
recent problem is "System.DllNotFound" exception. The DLL is located in

the
same directory as my .cs code. I tried to add a reference but recieved an error that it wasn't a valid type.

I would just really like to see a working example of using an unmanaged

code
in C#. Anyone know a good place to read more?

Thanks-
Steve


Nov 16 '05 #3
Hi Steve,

What I had as a problem once is name mangling. Be sure to export your
entries from the C++ library as follows.

extern "C"
{
/* your exports */
}

Other than that, you should have no problem using the DllImportAttribute. A
small sample that works for me :

[ DllImport( "my_lib.dll", EntryPoint = "my_exported_function" ) ]
public static extern int MyExportedFunction (
[ MarshalAs( UnmanagedType.LPStr ) ] string fileName,
[ MarshalAs( UnmanagedType.U4 ) ] uint timeoutMs
);

// ...
int i = MyExportedFunction( "file.xml", 10000 );

If you still have problems using the dll, you could post a code-fragment
illustrating the problem...

HTH,
Tom T.

"SteveK" wrote:
Thanks for the quick answer, Ming,

I have added my call to DllImport and when I build the project, VS.NET
crashes SUPER fast, if I comment out the DllImport line, it's fine.
Isn't that nice? ;(
-Steve
"Ming Chen" <qq******@yahoo.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Hi, SteveK.
You can't reference to a unmanaged DLL. You can, however, use
DllImportAttribute to call a unmanaged function in a Dll. See
http://www.codeguru.com/Csharp/Cshar...cle.php/c4217/ for a
simple example.
On the other hand, if the DLL exposes C++ classes, you may have to

convert
it into a COM module or build a wrapper with Managed C++.

Regards
Ming Chen

"SteveK" <as***@asdfasdfsd.com> wrote in message
news:eo*************@TK2MSFTNGP14.phx.gbl...
Hi-

I know this is common topic, but I don't intend to ask you guys "how" but rather "Where can I find samples or tutorials that actually compile??" ;)
I have been attempting to educate myself on this topic for awhile and 3
attempts to download source code and compile have yielded nothing. My

most
recent problem is "System.DllNotFound" exception. The DLL is located in

the
same directory as my .cs code. I tried to add a reference but recieved an error that it wasn't a valid type.

I would just really like to see a working example of using an unmanaged

code
in C#. Anyone know a good place to read more?

Thanks-
Steve



Nov 16 '05 #4

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

Similar topics

3
by: Mart Rogers | last post by:
We have been trying to avoid switches to unmanaged code in our development, but have recently folded in a call to CDO by using System.Web.Mail as a quick way to send email. Yes this is a call to...
3
by: New World Order Pigs | last post by:
Sorry if this is the wrong group, but it seems like a good place to start. I have a control, creating a dll written in c#/.net and some unmanaged code in c++ using embedded c++ V3. Yes, it is for...
1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
2
by: Dave Griffin | last post by:
This is a followup to my question in doing unmanaged DLLs in .NET. I was able to create the DLL and the application was able to see it. So far so good. Now I need to make that unmanaged DLL read an...
0
by: david chang via DotNetMonster.com | last post by:
Hi, guys I am trapped into a big trouble on how to use unmanaged class library code in a C# web application. Now, I am working on a project to develop a web interface for SPlus, a statistical...
1
by: Adam Clauss | last post by:
I have an unmanaged C++ library that I need to use through C#. I created a Managed C++ class library and through it wrote a wrapper class to call what I need. However, one of the methods (an...
2
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking afterwards with ILDASM at what is visible in those assemblies from a...
5
by: Anthony Evans | last post by:
Greetings I'm using VC++.NET to create a class library. The class library contains managed classes that wrap legacy unmanaged classes by the same name. I use regasm to register the DLL for...
6
by: marek | last post by:
Hello All, we are doing a quite a big project that contains at the lowest level an unmenaged c++ classes. Above it there are managed wrappers and at the top there are ASP.NET pages. Can anyone...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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
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...
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...

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.