473,770 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

consuming unmanaged dlls in VC++

Hello everybody!

I've this problem:

I'm working on a download meter, based on wpcap. As wpcap code is
unmanaged, I decided to create the needed functions in a unmanaged
project (one for opening an an adapter and capturing the packets (and
thus counting the data downloaded), one for getting the byte-count and
one for stopping the packet capturing), and place them in a dll, which
exports functions
void capture(),
void stopping(),
long getbytes().
And now I want to import these functions into a managed C++
application.
So I created a class pcapImport, and inside it I've tried to somehow
import those functions.
I've tried this:
[DllImport("pcap DLL.dll")] extern "C" long getbytes (); but I couldn't
even compile that thing, i got an error: C2059, syntax error,
then I tried this
[DllImport("pcap DLL.dll")] extern long getbytes ();
and got an error: C2720, 'extern' storage-class specifier illegal on
members
and finally tried this:
[DllImport("pcap DLL.dll")] static long getbytes ();
In this case no compilation error occurred, but the pcapDLL.dll hadn't
been loaded (not listed among the modules) and although it doesn't
throws an exception (something like function does not exist) it just
doesn't do anything.

Well, I've Googled a lot, but hadn't find anything what's working.

I'd appreciate any help.
Thanks,
Matyi

May 23 '06 #1
1 1777
Why not create a mixed model project in VC++?
the only two things you need to do in order to mix MFC and Managed
Extensions is to set the Use Managed Extensions project property (which
equates to the /clr compiler switch) and add the appropriate #using and
using directives to your code.

"Matyi" <ma**********@g mail.com> wrote in message
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
Hello everybody!

I've this problem:

I'm working on a download meter, based on wpcap. As wpcap code is
unmanaged, I decided to create the needed functions in a unmanaged
project (one for opening an an adapter and capturing the packets (and
thus counting the data downloaded), one for getting the byte-count and
one for stopping the packet capturing), and place them in a dll, which
exports functions
void capture(),
void stopping(),
long getbytes().
And now I want to import these functions into a managed C++
application.
So I created a class pcapImport, and inside it I've tried to somehow
import those functions.
I've tried this:
[DllImport("pcap DLL.dll")] extern "C" long getbytes (); but I couldn't
even compile that thing, i got an error: C2059, syntax error,
then I tried this
[DllImport("pcap DLL.dll")] extern long getbytes ();
and got an error: C2720, 'extern' storage-class specifier illegal on
members
and finally tried this:
[DllImport("pcap DLL.dll")] static long getbytes ();
In this case no compilation error occurred, but the pcapDLL.dll hadn't
been loaded (not listed among the modules) and although it doesn't
throws an exception (something like function does not exist) it just
doesn't do anything.

Well, I've Googled a lot, but hadn't find anything what's working.

I'd appreciate any help.
Thanks,
Matyi

May 24 '06 #2

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

Similar topics

2
5937
by: Thomas W. Brown | last post by:
I have setup Console redirection within my Console app (via Console.SetOut and Console.SetErrror) to route console WriteLine calls to a logfile. This works just fine with one exception... I use PInvoke to call into several unmanaged DLLs which write diagnostic information out to stdout (and possibly stderr). When I run in a "standalone" mode with no redirection, these DLLs do generate output to the console window. But I want to run in...
0
2062
by: Frank Lopez | last post by:
My program structure is: 1. 2. 3. => manually does the crt-init and crt-terminate calls 4. -- this is accessed by the unmanaged C++ classes in (3) using LoadLibrary and FreeLibrary
4
7182
by: repstat | last post by:
Hi I have a project which is going to be doing some string manipulation which needs to be pretty fast. The user interface is going to be written in C#. I am going to write the string handling functions in a C++ DLL. My first question is, if I insert a C++ project into my C# solution, how will VS.NET know that I want it to be unmanaged code? I intend to be calling the DLLs functions using DllImport. I've heard that you can have unmanaged...
4
1036
by: gmclean | last post by:
I have VC++ project that is unmanaged. I would like to build components like user interface dialog boxes in VB .net and call them from the unmanaged VC++ application. Is this possible? Before .net I would have done this with an activex object or com object. Any suggestions would be appreciated. George McLean
3
1341
by: Dave | last post by:
I've seen at least one article on this: How to access classes, etc. managed-to-unmanaged. I can't find it. Any tricks or pointers? I guess the class name won't get munged but I'm not clear about necessary class declarations.
3
2717
by: gopal | last post by:
I am developing an application in CSharp - windows forms based, which copies the DLLs both unmanaged and managed DLLs from a shared folder and will overwrite the existing versions of managed & unmanaged DLLs into folder where some .NET application and a VB application has been installed. To be more clear, i will make some chnages to DLLs and using this tool(developed in CSharp) i will overwrite the existing version of DLLs - unmanaged...
6
4128
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including memory management and connection pooling constructs) as static variables which were intended to scoped to the process. 2. Managed C++ assemblies (.NET 1.1) that wrap the unmanaged DLLs as nice neat classes with managed interfaces.
6
8653
by: Volodia | last post by:
Hi, I have a problem to find information how to add unmanaged dll build in VC++ 2005 to the asp.net web site What I have tried: 1. use DllImport("MyDll.dll") to declare function in mypage.aspx.cs 2. put MyDll.dll into Bin folder for ASP.Net web site But unfortunately an exception has been thrown
13
3653
by: =?Utf-8?B?d3BjbWFtZQ==?= | last post by:
I have a small C++/CLI application which calls an unmanaged lib. It seems like I can't use /clr:pure and link with the unmanaged lib (LNK1313 error). The problem I have is that compiling with /clr adds a dependency on several msvc*.dll:s which adds some unwanted complexity to the installation. Is it possible to avoid the msvc*.dll dependency without explicit p/invoke?
0
9602
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...
1
10017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8905
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...
0
6690
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();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
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.