Click here to Skip to main content
16,005,120 members
Home / Discussions / C#
   

C#

 
GeneralRe: Windows Service Question Pin
#realJSOP6-Mar-08 8:34
professional#realJSOP6-Mar-08 8:34 
GeneralRe: Windows Service Question Pin
PIEBALDconsult6-Mar-08 7:01
mvePIEBALDconsult6-Mar-08 7:01 
GeneralRe: Windows Service Question Pin
#realJSOP6-Mar-08 7:17
professional#realJSOP6-Mar-08 7:17 
GeneralRe: Windows Service Question Pin
PIEBALDconsult6-Mar-08 9:50
mvePIEBALDconsult6-Mar-08 9:50 
GeneralRe: Windows Service Question Pin
#realJSOP6-Mar-08 10:31
professional#realJSOP6-Mar-08 10:31 
GeneralRe: Windows Service Question Pin
PIEBALDconsult6-Mar-08 16:48
mvePIEBALDconsult6-Mar-08 16:48 
Generalreference a C++ dll in a C# program Pin
steve_rm6-Mar-08 5:42
steve_rm6-Mar-08 5:42 
GeneralRe: reference a C++ dll in a C# program [modified] Pin
Ernest Laurentin6-Mar-08 7:02
Ernest Laurentin6-Mar-08 7:02 
Try this: Simple Dll (Build this: cl /LD SimpleDll.cpp )

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
BOOL WINAPI DllMain(
    HINSTANCE hinstDLL,  // handle to DLL module
    DWORD fdwReason,     // reason for calling function
    LPVOID lpReserved )  // reserved
{
    // Perform actions based on the reason for calling.
    switch( fdwReason ) 
    { 
        case DLL_PROCESS_ATTACH:
         // Initialize once for each new process.
         // Return FALSE to fail DLL load.
            break;

        case DLL_THREAD_ATTACH:
         // Do thread-specific initialization.
            break;

        case DLL_THREAD_DETACH:
         // Do thread-specific cleanup.
            break;

        case DLL_PROCESS_DETACH:
         // Perform any necessary cleanup.
            break;
    }
    return TRUE;  // Successful DLL_PROCESS_ATTACH.
}

extern "C" __declspec(dllexport)
double Add(double a, double b)
{
  return a + b;
}

extern "C" __declspec(dllexport)
double Subtract(double a, double b)
{
  return a-b;
}

extern "C" __declspec(dllexport)
double Multiply(double a, double b)
{
  return a*b;
}

extern "C" __declspec(dllexport)
double Divide(double a, double b)
{
  if ( b != 0 )
    return a/b;
  return -999999999999999999999.0; //don't crash
}



Hello world application (build: csc /t:exe HelloWorld.cs)

using System;
using System.Runtime.InteropServices;
namespace HelloWorld
{
    class Hello 
    {
        [DllImport("SimpleDll.dll", EntryPoint="Add", CallingConvention=CallingConvention.Cdecl)]
        public static extern Double Add(Double a,Double b);

        [DllImport("SimpleDll.dll", EntryPoint="Subtract", CallingConvention=CallingConvention.Cdecl)]
        public static extern Double Subtract(Double a,Double b);

        [DllImport("SimpleDll.dll", EntryPoint="Multiply", CallingConvention=CallingConvention.Cdecl)]
        public static extern Double Multiply(Double a,Double b);

        [DllImport("SimpleDll.dll", EntryPoint="Divide", CallingConvention=CallingConvention.Cdecl)]
        public static extern Double Divide(Double a,Double b);

        static void Main() 
        {
            System.Console.WriteLine("Add:       {0}", Add(3,4));
            System.Console.WriteLine("Subtract:  {0}", Subtract(7,4));
            System.Console.WriteLine("Multiply:  {0}", Multiply(3,4));
            System.Console.WriteLine("Divide:    {0}", Divide(12,4));
        }
    }
}


God bless,
Ernest Laurentin

modified on Thursday, March 6, 2008 1:09 PM

GeneralRe: reference a C++ dll in a C# program Pin
PIEBALDconsult6-Mar-08 7:04
mvePIEBALDconsult6-Mar-08 7:04 
QuestionIn briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
hdv2126-Mar-08 4:42
hdv2126-Mar-08 4:42 
AnswerRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
Pete O'Hanlon6-Mar-08 4:45
mvePete O'Hanlon6-Mar-08 4:45 
GeneralRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
phannon866-Mar-08 5:02
professionalphannon866-Mar-08 5:02 
GeneralRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
Pete O'Hanlon6-Mar-08 5:17
mvePete O'Hanlon6-Mar-08 5:17 
GeneralRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
Colin Angus Mackay6-Mar-08 11:35
Colin Angus Mackay6-Mar-08 11:35 
GeneralRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
Pete O'Hanlon6-Mar-08 22:01
mvePete O'Hanlon6-Mar-08 22:01 
GeneralRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
Luc Pattyn6-Mar-08 6:41
sitebuilderLuc Pattyn6-Mar-08 6:41 
AnswerRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
#realJSOP6-Mar-08 5:57
professional#realJSOP6-Mar-08 5:57 
GeneralRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
Judah Gabriel Himango6-Mar-08 9:59
sponsorJudah Gabriel Himango6-Mar-08 9:59 
GeneralRe: In briefly, What's mean this sentence : (C# is strongly typed language) ? Pin
Colin Angus Mackay6-Mar-08 11:38
Colin Angus Mackay6-Mar-08 11:38 
QuestionOpenFileDialog with setting View mode to small icon Pin
arbrsoft6-Mar-08 4:27
arbrsoft6-Mar-08 4:27 
GeneralRe: OpenFileDialog with setting View mode to small icon Pin
Luc Pattyn6-Mar-08 4:33
sitebuilderLuc Pattyn6-Mar-08 4:33 
Generalauto update Pin
damianrda6-Mar-08 4:15
damianrda6-Mar-08 4:15 
GeneralRe: auto update Pin
led mike6-Mar-08 4:41
led mike6-Mar-08 4:41 
GeneralRe: auto update Pin
Judah Gabriel Himango6-Mar-08 4:49
sponsorJudah Gabriel Himango6-Mar-08 4:49 
GeneralRe: auto update Pin
damianrda6-Mar-08 5:03
damianrda6-Mar-08 5:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.