| |
|
Interoperability in C#
|
| |
|
|
| |
|
Programming has been around for some time and we haven't always had the .Net
Framework to make our lives as programmers and support engineers so easy.
When we program within the confines of the .Net Framework, we are building
managed code. Managed code is compiled in Bytecode. Prior to the .Net
Framework we programmed in unmanaged code. Meaning we compiled it directly
into a native operating system binary. In most cases, it became a .dll or
COM (Component Object Model). Since many systems we create today (managed code)
will need to use some of the older code (unmanaged code) there needs to be an
interface between to 2 types of code. This interface is called PInvoke
(Platform Invoke) which utilizes the DllImport attribute.
|
| |
|
Before the nice SMTP .net libraries, there was a popular email program called BLAT.
BLAT is coded in unmanaged code. Below is an example of using BLAT with C#,
which is managed code.
|
| |
using System.Runtime.InteropServices;
[DllImport("blat.dll", CharSet = CharSet.Ansi)]
public static extern int Blat(int argc, string[] argv);
[DllImport("blat.dll", CharSet = CharSet.Ansi)]
public static extern short Send(string cmd);
string BlatCmd = "- -to to@noplace.dom " +
"-from from@nowhere.dom " +
"-subject Test Email " +
"-body Hello from nowhere " +
"-server IP.IP.IP.IP";
short returnCode = Send(BlatCmd);
|
| |
|
When the Send method is called it uses the Win32 API within the
blatt.dll to send the email.
|
| |
|
There are many such examples in the real world so I recommend
testing out this area of programming at some point, early in your career.
|
| |
|
|
| |
|
|
| |
|
|
| |
| |
| Posts: 113 |
| Comments:
86 |
| Fundamentals:
16 |
| |
 |
| |
| |
|
| |
 |
| |
 |
| |
 |
| |
|
| 2011 December (2) |
| 2011 November (6) |
| 2011 October (7) |
| 2011 September (7) |
| 2011 August (9) |
| 2011 July (9) |
| 2011 June (8) |
| 2011 May (9) |
| 2011 April (7) |
| 2011 March (9) |
| 2011 February (8) |
| 2011 January (8) |
| 2010 December (7) |
| 2010 November (8) |
| 2010 October (4) |
| |
| |
|
| |
|
|
| |
| |
|
The sample code on this website is provided to illustrate a concept and should not be used in
applications or Web sites without proper professional consultation, as it may not illustrate
the safest coding practices. I assume no liability for incidental or consequential damages
should the sample code be used for purposes other than as intended.
|
| |
|
| | | |