Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2006

Tip: Looking for answers? Try searching our database.

Unmanaged code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason - 31 Oct 2006 20:01 GMT
Hello

I've got a DLL from a 3rd party vendor and they wrote the DLL in C++ so I
can't just easily add a reference to it.  How do I add that dll, to my C#
application?

Any idea, examples?
Michael Nemtsev - 31 Oct 2006 20:09 GMT
Hello Jason,

Using platform invoke
Read there http://msdn2.microsoft.com/en-gb/library/ms173184.aspx and see
sample http://msdn2.microsoft.com/en-gb/library/ms173187.aspx of calling
WinAPI

J> Hello
J>
J> I've got a DLL from a 3rd party vendor and they wrote the DLL in C++
J> so I can't just easily add a reference to it.  How do I add that dll,
J> to my C# application?
J>
J> Any idea, examples?
J>
---
WBR,
Michael  Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jason - 31 Oct 2006 21:51 GMT
Ok

I see the........

System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint =
"PlaySound", SetLastError = true)]
       private static extern bool PlaySound(string szSound, System.IntPtr
hMod, PlaySoundFlags flags);

but how do know or find out what the entry point of a 3rd party DLL would
be?

> Hello Jason,
>
[quoted text clipped - 14 lines]
> "At times one remains faithful to a cause only because its opponents do
> not cease to be insipid." (c) Friedrich Nietzsche
Michael Nemtsev - 31 Oct 2006 22:07 GMT
Hello Jason,

Obviously from the your dll manuals. They should provide u the list of functions
they export
btw, read a bit there http://samples.gotdotnet.com/quickstart/howto/doc/Interop/PInvoke_Simple.aspx

J> Ok
J>
J> I see the........
J>
J> System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint =
J> "PlaySound", SetLastError = true)]
J> private static extern bool PlaySound(string szSound,
J> System.IntPtr
J> hMod, PlaySoundFlags flags);
J> but how do know or find out what the entry point of a 3rd party DLL
J> would be?
J>
J> "Michael Nemtsev" <nemtsev@msn.com> wrote in message
J> news:1799a79b3b9d8e8c8cb504f2d47d4@msnews.microsoft.com...
J>
>> Hello Jason,
>>
[quoted text clipped - 16 lines]
>> "At times one remains faithful to a cause only because its opponents
>> do not cease to be insipid." (c) Friedrich Nietzsche

---
WBR,
Michael  Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Willy Denoyette [MVP] - 31 Oct 2006 22:13 GMT
> Ok
>
[quoted text clipped - 6 lines]
>
> but how do know or find out what the entry point of a 3rd party DLL would be?

Are you sure the DLL is exporting C style functions, that is, is the DLL meant to be used
from clients using "C style" bindings? C# and PInvoke cannot call exported C++ class
members. Another thing you need to know is the calling convention used for the exports. You
can try to get at the exports using tools like depends.exe and dumpbin.exe from the platform
SDK, but what you really need is the documentation that describes the exported functions
their argument types ,calling convention and semantics .

Willy.
Wilfried Mestdagh - 31 Oct 2006 22:13 GMT
Hi Jason,

You only need the EntryPoint if you choose a different name. For example
this is a part of code to access a DLL of me:

  [DllImport(Tools.dllName, EntryPoint = "Initialize")]
  public static extern void InitializeApi();
  [DllImport(Tools.dllName)]
  public static extern void Disconnect();

The first one, 'Initialize' is an error in C# because it is already
existant, so I renamed it to InitializeApi. The second one 'Disconnect'
I did not rename, so no EntryPoint needed.

hope this helps.

Signature

rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.