[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Yawen Chan

10/18/2002 6:01:00 AM

I'm using PInvoke to call a function in a DLL. But now I have 2 functions
from the DLL that I want to call. When I declare the C function prototype,
I do:

[DllImport("SampleDLL")]
private static extern void functionA();
private static extern void functionB();

Then when I run it, I got an System.TypeLoadException.

However I found that if I do:

[DllImport("SampleDLL")]
private static extern void functionA();
[DllImport("SampleDLL")]
private static extern void functionB();

My application runs just fine.

So now I'm concerning about the performance of my application. If I call
DllImport twice, does it mean that the DLL is loaded twice? If so, how can
I just load the DLL once in this case?

Thanks very much.

Yawen




3 Answers

(Zane Thomas [.NET MVP])

10/18/2002 6:11:00 AM

0

On Fri, 18 Oct 2002 13:01:24 +0800, "Yawen Chan" <y3chan@engmail.uwaterloo.ca>
wrote:

>If I call DllImport twice

DllImport is an _attribute_ it is not a method invocation.



--
*--------={ Fine Art for .NET }=--------*
| The Best Internet Components for .NET |
| Turn on, tune in, download. |
| @ |
| www.abderaware.com |
*---------------------------------------*
zane a@t abderaware.com

Mattias Sjögren

10/18/2002 9:55:00 AM

0

Yawen,

>If I call DllImport twice, does it mean that the DLL is loaded twice?

No



Mattias

===
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.n...
Please reply only to the newsgroup.

Nicholas Paldino [.NET MVP]

10/18/2002 2:32:00 PM

0

Yawen,

If you make two calls into the DLL, the DLL should only be loaded once
into memory.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- nicholas.paldino@exisconsulting.com

"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:OsiQ7MmdCHA.2008@tkmsftngp08...
> I'm using PInvoke to call a function in a DLL. But now I have 2 functions
> from the DLL that I want to call. When I declare the C function
prototype,
> I do:
>
> [DllImport("SampleDLL")]
> private static extern void functionA();
> private static extern void functionB();
>
> Then when I run it, I got an System.TypeLoadException.
>
> However I found that if I do:
>
> [DllImport("SampleDLL")]
> private static extern void functionA();
> [DllImport("SampleDLL")]
> private static extern void functionB();
>
> My application runs just fine.
>
> So now I'm concerning about the performance of my application. If I call
> DllImport twice, does it mean that the DLL is loaded twice? If so, how
can
> I just load the DLL once in this case?
>
> Thanks very much.
>
> Yawen
>
>
>
>