From 97157c42fca559eecbcbef5dd566abc0f68caab1 Mon Sep 17 00:00:00 2001 From: Michael Giagnocavo Date: Thu, 23 Oct 2008 04:29:13 +0000 Subject: [PATCH] cdecl'd calling conventions git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10125 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../languages/mod_managed/freeswitch_managed.h | 15 +++------------ src/mod/languages/mod_managed/managed/Loader.cs | 6 +++++- .../mod_managed/managed/ManagedSession.cs | 7 +++++-- src/mod/languages/mod_managed/mod_managed.cpp | 8 ++++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/mod/languages/mod_managed/freeswitch_managed.h b/src/mod/languages/mod_managed/freeswitch_managed.h index 31d36ef721..c69b662f92 100644 --- a/src/mod/languages/mod_managed/freeswitch_managed.h +++ b/src/mod/languages/mod_managed/freeswitch_managed.h @@ -37,18 +37,9 @@ SWITCH_BEGIN_EXTERN_C #include #include - -/* calling conventions for Windows */ -#ifndef MANAGED_STDCALL -#ifdef WIN32 -# define MANAGED_STDCALL __stdcall -# else -# define MANAGED_STDCALL -# endif -#endif - -typedef void (MANAGED_STDCALL *hangupFunction)(void); -typedef char* (MANAGED_STDCALL *inputFunction)(void*, switch_input_type_t); + +typedef void (*hangupFunction)(void); +typedef char* (*inputFunction)(void*, switch_input_type_t); #ifndef _MANAGED diff --git a/src/mod/languages/mod_managed/managed/Loader.cs b/src/mod/languages/mod_managed/managed/Loader.cs index af21f398d3..1670fd4439 100644 --- a/src/mod/languages/mod_managed/managed/Loader.cs +++ b/src/mod/languages/mod_managed/managed/Loader.cs @@ -94,16 +94,20 @@ namespace FreeSWITCH } } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ExecuteDelegate(string cmd, IntPtr streamH, IntPtr eventH); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ExecuteBackgroundDelegate(string cmd); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool RunDelegate(string cmd, IntPtr session); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool LoadAssemblyDelegate(string filename); static readonly ExecuteDelegate _execute = Execute; static readonly ExecuteBackgroundDelegate _executeBackground = ExecuteBackground; static readonly RunDelegate _run = Run; static readonly LoadAssemblyDelegate _loadAssembly = LoadAssembly; //SWITCH_MOD_DECLARE(void) InitManagedDelegates(runFunction run, executeFunction execute, executeBackgroundFunction executeBackground, loadAssemblyFunction loadAssembly) - [DllImport("mod_managed", CharSet = CharSet.Ansi)] + [DllImport("mod_managed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] static extern void InitManagedDelegates(RunDelegate run, ExecuteDelegate execute, ExecuteBackgroundDelegate executeBackground, LoadAssemblyDelegate loadAssembly); // Be rather lenient in finding the Load and Unload methods diff --git a/src/mod/languages/mod_managed/managed/ManagedSession.cs b/src/mod/languages/mod_managed/managed/ManagedSession.cs index 57064f9ce4..fadbd6bd3f 100644 --- a/src/mod/languages/mod_managed/managed/ManagedSession.cs +++ b/src/mod/languages/mod_managed/managed/ManagedSession.cs @@ -38,12 +38,15 @@ namespace FreeSWITCH.Native { // switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype) // But, process_callback_result is used to turn a string into a switch_status_t - //using DtmfCallback = Func; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate string DtmfCallback(IntPtr input, Native.switch_input_type_t itype); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void CdeclAction(); + public partial class ManagedSession { // SWITCH_DECLARE(void) InitManagedSession(ManagedSession *session, MonoObject *dtmfDelegate, MonoObject *hangupDelegate) - [DllImport("mod_managed.dll", CharSet = CharSet.Ansi)] + [DllImport("mod_managed.dll", CharSet = CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)] static extern void InitManagedSession(IntPtr sessionPtr, DtmfCallback dtmfDelegate, Action hangupDelegate); /// Initializes the native ManagedSession. Must be called after Originate. diff --git a/src/mod/languages/mod_managed/mod_managed.cpp b/src/mod/languages/mod_managed/mod_managed.cpp index 7f2d366e53..b2ad33c016 100644 --- a/src/mod/languages/mod_managed/mod_managed.cpp +++ b/src/mod/languages/mod_managed/mod_managed.cpp @@ -68,10 +68,10 @@ SWITCH_STANDARD_API(managed_loadassembly); /* Load assembly */ mod_managed_globals globals = { 0 }; // Global delegates to call managed functions -typedef int (MANAGED_STDCALL *runFunction)(const char *data, void *sessionPtr); -typedef int (MANAGED_STDCALL *executeFunction)(const char *cmd, void *stream, void *Event); -typedef int (MANAGED_STDCALL *executeBackgroundFunction)(const char* cmd); -typedef int (MANAGED_STDCALL *loadAssemblyFunction)(const char* filename); +typedef int (*runFunction)(const char *data, void *sessionPtr); +typedef int (*executeFunction)(const char *cmd, void *stream, void *Event); +typedef int (*executeBackgroundFunction)(const char* cmd); +typedef int (*loadAssemblyFunction)(const char* filename); static runFunction runDelegate; static executeFunction executeDelegate; static executeBackgroundFunction executeBackgroundDelegate;