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

Unmanaged code

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?

Oct 31 '06 #1
5 1716
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
JHello
J>
JI've got a DLL from a 3rd party vendor and they wrote the DLL in C++
Jso I can't just easily add a reference to it. How do I add that dll,
Jto my C# application?
J>
JAny 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
Oct 31 '06 #2
Ok

I see the........

System.Runtime.InteropServices.DllImport("winmm.DL L", 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?

"Michael Nemtsev" <ne*****@msn.comwrote in message
news:17***************************@msnews.microsof t.com...
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
JHello
JJI've got a DLL from a 3rd party vendor and they wrote the DLL in C++
Jso I can't just easily add a reference to it. How do I add that dll,
Jto my C# application?
JJAny 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


Oct 31 '06 #3
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/quickst...ke_Simple.aspx

JOk
J>
JI see the........
J>
JSystem.Runtime.InteropServices.DllImport("winmm.D LL", EntryPoint =
J"PlaySound", SetLastError = true)]
Jprivate static extern bool PlaySound(string szSound,
JSystem.IntPtr
JhMod, PlaySoundFlags flags);
Jbut how do know or find out what the entry point of a 3rd party DLL
Jwould be?
J>
J"Michael Nemtsev" <ne*****@msn.comwrote in message
Jnews:17***************************@msnews.microso ft.com...
J>
>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
JHello
JJI've got a DLL from a 3rd party vendor and they wrote the DLL
in C++
Jso I can't just easily add a reference to it. How do I add that
dll,
Jto my C# application?
JJAny 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
---
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
Oct 31 '06 #4
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.

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz
Oct 31 '06 #5
"Jason" <so*****@microsoft.comwrote in message
news:OS*************@TK2MSFTNGP03.phx.gbl...
Ok

I see the........

System.Runtime.InteropServices.DllImport("winmm.DL L", 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?
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.

Oct 31 '06 #6

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

Similar topics

7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
2
by: Paul Kenny | last post by:
Hi, I am trying to expose the functionality of an unmanaged C++ class to the other languages available in the .NET Framework. I have decided to do this by wrapping the unmanaged C++ class in a...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
4
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...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
5
by: R. MacDonald | last post by:
Hello, all, I am currently working on a .Net (VB) application that invokes routines in unmanaged (Fortran) DLLs. The unmanaged routines then communicate with the .Net application by means of a...
6
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...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
2
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.