Le forum (ô combien francophone) des utilisateurs de Powerbuilder.
Est-ce que tu es sûr de la déclaration de la fonction externe dans les [local|global] externals ?
- il peut y avoir un problème de déclaration des paramètres (ex: long à la place d'un ulong) ou sur le nombre de paramètres
- il peut y avoir un problème sur les paramètres transmis (ex: on doit donner un buffer mais on n'a pas alloué l'espace nécessaire - le truc c'est d'allouer une chaîne avec space() et de la transmettre via un ref string)
- il peut y avoir un problème de chargement ou d'exécution du traitement dans la dll (mais c'est plutôt error calling.. que bad runtime function reference)
Dernière modification par seki (22-02-2013 14:01:49)
Hors ligne
Pour un peu plus de clarté, voici mon code :
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlTypes; using System.Data.SqlClient; using Microsoft.SqlServer.Server; using System.Net.Mail; using System.Net.Mime; using System.Runtime.InteropServices; namespace SendVcal { class Program { public static bool sendiCal(string[] args) { string calDateFormat = "yyyyMMddTHHmmssZ"; if (args.Length > 0) { // connect to smtpserver var client = new SmtpClient(args[11], int.Parse(args[12])); // create the email var mailMesage = new MailMessage(); mailMesage = CreateMeetingRequest(DateTime.ParseExact(args[0], calDateFormat, null), DateTime.ParseExact(args[1], calDateFormat, null), args[2], args[13], args[9], "Sender", "toto@toot.fr", args[4], args[3], args[7] ); client.Send(mailMesage); } return true; } public static MailMessage CreateMeetingRequest(DateTime start, DateTime end, string subject, string info_complementaires, string location, string organizerName, string organizerEmail, string attendeeName, string attendeeEmail, string num_om) { MailAddressCollection col = new MailAddressCollection(); col.Add(new MailAddress(attendeeEmail, attendeeName)); return CreateMeetingRequest(start, end, subject, info_complementaires, location, organizerName, organizerEmail, col, num_om); } public static MailMessage CreateMeetingRequest(DateTime start, DateTime end, string subject, string info_complementaires, string location, string organizerName, string organizerEmail, MailAddressCollection attendeeList, string num_om) { MailMessage msg = new MailMessage(); string calDateFormat = "yyyyMMddTHHmmssZ"; // Set up the different mime types contained in the message System.Net.Mime.ContentType textType = new System.Net.Mime.ContentType("text/plain"); System.Net.Mime.ContentType HTMLType = new System.Net.Mime.ContentType("text/html"); System.Net.Mime.ContentType calendarType = new System.Net.Mime.ContentType("text/calendar"); // Add parameters to the calendar header calendarType.Parameters.Add("method", "REQUEST"); calendarType.Parameters.Add("name", "meeting.ics"); // Create message body parts // create the Body in text format /*string bodyText = "Type:Single Meeting\r\nOrganizer: {0}\r\nStart Time:{1}\r\nEnd Time:{2}\r\nTime Zone:{3}\r\nLocation: {4}\r\n\r\n*~*~*~*~*~*~*~*~*~*\r\n\r\n{5}"; bodyText = string.Format(bodyText, organizerName, start.ToLongDateString() + " " + start.ToLongTimeString(), end.ToLongDateString() + " " + end.ToLongTimeString(), System.TimeZone.CurrentTimeZone.StandardName, location, summary);*/ string bodyText = "Numero de l'OM : {0}\r\nObjet de la mission : {1}\r\nLieu de la mission : {2}\r\nPeriode de la mission : du {3} au {4}\r\n\r\nInformations complementaires : {5}\r\n\r\n"; bodyText = string.Format(bodyText, num_om, subject, location, start.ToUniversalTime().ToString(calDateFormat), end.ToUniversalTime().ToString(calDateFormat), info_complementaires); AlternateView textView = AlternateView.CreateAlternateViewFromString(bodyText, textType); msg.AlternateViews.Add(textView); //create the Body in HTML format string bodyHTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\r\n<HTML>\r\n<HEAD>\r\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\r\n<META NAME=\"Generator\" CONTENT=\"MS Exchange Server version 6.5.7652.24\">\r\n<TITLE>{0}</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<!-- Converted from text/plain format -->\r\n<P>{1}\r\n</P>\r\n\r\n</BODY>\r\n</HTML>"; bodyHTML = string.Format(bodyHTML, subject, bodyText); AlternateView HTMLView = AlternateView.CreateAlternateViewFromString(bodyHTML, HTMLType); msg.AlternateViews.Add(HTMLView); //create the Body in VCALENDAR format string bodyCalendar = "BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft CDO for Microsoft Exchange\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:(GMT-06.00) Central Time (US & Canada)\r\nX-MICROSOFT-CDO-TZID:11\r\nBEGIN:STANDARD\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0600\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0600\r\nTZOFFSETTO:-0500\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:{8}\r\nDTSTART:{0}\r\nSUMMARY:{7}\r\nUID:{5}\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"{9}\":MAILTO:{9}\r\nACTION;RSVP=TRUE;CN=\"{4}\":MAILTO:{4}\r\nORGANIZER;CN=\"{3}\":mailto:{4}\r\nLOCATION:{2}\r\nDTEND:{1}\r\nDESCRIPTION:{7}\\N\r\nSEQUENCE:1\r\nPRIORITY:5\r\nCLASS:\r\nCREATED:{8}\r\nLAST-MODIFIED:{8}\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nX-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-OWNERAPPTID:-1\r\nX-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:{8}\r\nX-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:{8}\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT00H15M00S\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; bodyCalendar = string.Format(bodyCalendar, start.ToUniversalTime().ToString(calDateFormat), end.ToUniversalTime().ToString(calDateFormat), location, organizerName, organizerEmail, Guid.NewGuid().ToString("B"), bodyText, subject, DateTime.Now.ToUniversalTime().ToString(calDateFormat), attendeeList.ToString()); AlternateView calendarView = AlternateView.CreateAlternateViewFromString(bodyCalendar, calendarType); calendarView.TransferEncoding = TransferEncoding.SevenBit; msg.AlternateViews.Add(calendarView); // Adress the message msg.From = new MailAddress(organizerEmail); foreach (MailAddress attendee in attendeeList) { msg.To.Add(attendee); } msg.Subject = subject; return msg; } } }
Dans Global External Functions
Function boolean SendiCalVS(string as_args[]) Library "SendVcal.dll" Alias For "sendiCal"
Dans ma fonction gf_envoi_mail_dll
lb_return = SendiCalVS( ls_args)
Hors ligne
Intéressant
En discutant avec xlat, on pense qu'il y a un problème sur la convention d'appel qui est utilisée par .Net et qui n'est pas la convention standard pour les appels dans les langages non .Net (C, VB, etc) qui est le plus souvent stdcall ou cdecl (dépend de la façon dont la pile est nettoyée après un appel, par l'appelant (cdecl) ou par la fonction appelée (stdcall)).
Le problème est abordé par xlat sur son blog.
En résumé , essaye de préfixer le prototype de ta fonction avec [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
(Bon j'ai quand même un doute sur le support direct du passage d'un string[]...)
Hors ligne
Merci pour l'info... Je me bats depuis ce matin avec tout ça mais impossible de faire tourner mon appli... que ce soit en passant par l'exe (runtime error) ou en passant par la publication via APPEON (aucune erreur mais rien ne se passe).
Tu évoquais vb dans ton post... si je crée la même style de DLL mais en VB6, cela peut passer ???
PS : pour tester avec plus de fiabilité et retirer un max d'erreurs potentielles... je ne passe plus de string[] dans mon appel
Hors ligne