Hello, dear all,
I often see these two import usage in the code. Both are the interface
to use the Dll library. I think they are the same.
Normally P/Invoke means using the [DllImport ....] to import the
dll. But I have some confusion about them.
1. Is the "_declspec(dlli mport)" also one of the forms of P/Invoke?
2. From performance aspect, which way is more better?
3. What's the difference of them.
Thank you in advance! 2 3672
Ed wrote:
Hello, dear all,
I often see these two import usage in the code. Both are the interface
to use the Dll library. I think they are the same.
Normally P/Invoke means using the [DllImport ....] to import the
dll. But I have some confusion about them.
1. Is the "_declspec(dlli mport)" also one of the forms of P/Invoke?
No. __declspec(dlli mport) is a compiler directive that tells the compiler to
expect that the function so decorated will be satisfied by an import library
to be linked into the module. [DllImportAttrib ute] is a CLR attribute used
in managed (.NET) development that provides the mapping for P/Invoke to call
an external function. They're similar, it's true, but the first
(__declspec) has nothing to do with managed programming.
2. From performance aspect, which way is more better?
They're used for different purposes. If you have a choice (e.g. you're
writing managed C++), __declspec(dlli mport) will never give worse
performance.
3. What's the difference of them.
See above.
-cd
On Jul 30, 9:35 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remov e_this_and_nos. ..@mvps.org.nos pamwrote:
Ed wrote:
Hello, dear all,
I often see these two import usage in the code. Both are the interface
to use the Dll library. I think they are the same.
Normally P/Invoke means using the [DllImport ....] to import the
dll. But I have some confusion about them.
1. Is the "_declspec(dlli mport)" also one of the forms of P/Invoke?
No. __declspec(dlli mport) is a compiler directive that tells the compiler to
expect that the function so decorated will be satisfied by an import library
to be linked into the module. [DllImportAttrib ute] is a CLR attribute used
in managed (.NET) development that provides the mapping for P/Invoke to call
an external function. They're similar, it's true, but the first
(__declspec) has nothing to do with managed programming.
2. From performance aspect, which way is more better?
They're used for different purposes. If you have a choice (e.g. you're
writing managed C++), __declspec(dlli mport) will never give worse
performance.
3. What's the difference of them.
See above.
-cd
Thank you ! :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Felix I. Wyss |
last post by:
Good Afternoon,
I recently noticed that some very simple methods of a template declared and
used in a DLL library get inlined when used by the DLL itself, but not by
other DLLs and EXEs. After some investigating, I narrowed this down to a
very odd behavior (bug?) of the VC++.NET 2003 compiler: If a class that is
declared as __declspec(dllimport) derives from a template, that template's
methods are never inlined, even if declared with...
|
by: SpotNet |
last post by:
Hello NewsGroup,
More out of curiosity, now I'd love to know which is a better way, if one
can think in such terms in this context. If I implement the ChooseColor API
function, the documentation states (briefly);
BOOL ChooseColor(LPCHOOSECOLOR lpcc);
lpcc is defined as "... Pointer to a CHOOSECOLOR structure that..."
and you know or know where to read the rest of it.
|
by: pigeonrandle |
last post by:
Hi,
Please pity me, i am on a dial-up connection for the first time in 5
years :( !
Does anyone know how the resulting Graphics objects differ ...? What i
really mean is can someone explain it to me please?
A)
protected static extern IntPtr GetWindowDC
(IntPtr hWnd );
|
by: =?Utf-8?B?UHVjY2E=?= |
last post by:
Hi, I'm using vs2005, .net 2, C# for Windows application. I use DllImport so
I can call up a function written in C++ as unmanaged code and compiled as a
dll us vs2005. My application is able to call the function, EncodeAsnUser.
And it's returning OK but when I display the decoded data in another part of
my application it shows no data has been decoded, all fiedls are either null
or blanks. For some reason, I am not able to step through...
|
by: John Dinning |
last post by:
(Using VS2005 C# and compact Framework. Target device is running CE5).
I am creating a simple visual control (New Control Library project for smart
device Windows CE 5), derived from Label, with a couple of extra properties.
I need to call an external dll from this control, on a timer.
When I insert the declaration for the external dll function and build the
control project, strange things happen to any project that uses this
control.
| |
by: Seth Gecko |
last post by:
Hi
I am developing a complex VB.Net Windows application for an
engineering firm (don't ask me why they prefer VB.Net...). All the
engineering calculations are done in FORTRAN which is compiled to a
non COM type DLL (meaning you can't create an Interop for it). This is
called from within the .Net application using DllImport, just like
using a Windows API call. This works fine.
The problem arises when we create threads (using BeginInvoke)...
|
by: belion |
last post by:
Hi,
I am facing a strange problem ... a collegue of mine made two
projects. The first one is an unmanaged C++ dll , and the other is a
C# managed project that uses the previous dll. Both of them are
working on his machine, but not in mine. When I run the C# project, I
always get a DllNotFoundException, even it the path to the dll is well
set (I have checked it). I have also tried to copy the dll to C:
\WINDOWS\system32 , but the same...
|
by: Mohamed Mansour |
last post by:
Hey there, this will be somewhat a long post, but any response is
appreciated!
I have done many PInvoke in the past from C++ to C#, but I did PInvoke
within C# not C++/CLI.
Can someone explain more why C++/CLI would be better to PInvoke than doing
the PInvoke in
C#?
Because, usually in C# as you already know we use DLLImport and extern
|
by: =?Utf-8?B?VHJlY2l1cw==?= |
last post by:
Hello, Newsgroupians:
I have created an unmanaged DLL using Visual Studio 2005, which was created
in Visual C++. I have some functions in the DLL that I am trying to call.
When I "dumpbin -exports ManipLib.dll" I can see all of my exported
functions, which I have defined in my definition file. They are not name
mangled or decorated.
Now, when I call the function in my C# program, I have the following
definition...
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |