Dll fonctionant sur 32bits et non sur 64bits(System.BadImageFormatException:)

meilop Messages postés 10 Date d'inscription mardi 17 décembre 2002 Statut Membre Dernière intervention 28 octobre 2011 - 4 nov. 2010 à 12:27
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 - 4 nov. 2010 à 19:52
Bonjour,
System.BadImageFormatException
j'ai une dll écrite en C et je l'utilise avec du C#.
Sur les machines windows à 32 bits je n'ai aucune erreur,quand j'essaie de l'Executer sur une machine windows 7 j'ai une exception du type:
Tentativo di caricare un programma con un formato non corretto. (Eccezione da HRESULT: 0x8007000B)\par
in BRDTOMAP.DLL.Lnn32_Dll_1_Connect(Int64& errcod, Int32 mode, String host, Int32 port, String cnu, String user, String pw)\par
in BRDTOMAP.BRDTOMAP.ElencaOperazioni()\par
in BRDTOMAP.BRDTOMAP.timer1_Tick(Object sender, EventArgs e)\par
System.BadImageFormatException: in System.Windows.Forms.Timer.OnTick(EventArgs e)\par
in System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)\par
in System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Je vous montre les conversions de type éffectuées.
Fonctions C:
TLExtTypes et TLPortTypes sont des types enum que j'ai converti en entier en C#!!!(Int32 mode et Int32 port) Le trouvez vous correct?
int __stdcall Lnn32_Dll_1_Connect(int*errcod,TLExtTypes mode,char*host,TLPortTypes port,
char*cnu,char*user,char*pw)

int __clrcall Lnn32_Dll_1_ShwLaunch(int*errcod,char*show,char*parms,char**area,System::Data::DataSet^%myDataSet)

int __stdcall Lnn32_Dll_1_Disconnect(int*errcod)
code C#
const string _dllLocation = "Lnn32_Dll_1.dll";
[DllImport(_dllLocation)]
public static extern int Lnn32_Dll_1_Connect(ref long errcod, int mode, string host, int port, string cnu, string user, string pw);
[DllImport(_dllLocation)]
public static extern int Lnn32_Dll_1_ShwLaunch(ref long errcod, string show, string pmt, ref string area, ref System.Data.DataSet ds);
[DllImport(_dllLocation)]
public static extern int Lnn32_Dll_1_Disconnect(ref long errcod);

Je repete que sur les machines a 32bits tout fonctionne correctement mais sur les machines à 64bits je plante dès que j'appelle la première fonction de ma dll?
merci de votre aide..

philippe meilo

1 réponse

cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
4 nov. 2010 à 19:52
Bonjour,

Si la librairie native est x86 et n'est pas disponible en x64, ou qu'un des assembly entre elle et l'application l'hébergeant est compilé en cible x86 et non pas AnyCPU, alors l'application qui l'héberge doit s'arranger pour explicitement démarrer sous la CLR 32bit et pas 64bit.
Pour une application autonome (Console, WinForm, WPF, ...) celà se fait en spécifiant une cible x86 dans les paramètres du/des projet(s) ou carrément sur la solution.
Pour une application hébergée par un serveur d'application (IIS & co), voir la configuration de l'hôte.
Sous IIS ça se règle au niveau des pool d'application.


/*
coq
CoqBlog
*/
0
Rejoignez-nous