Chargement de la DLL native (32 bits) dans le fournisseur de wmi in-process (32 bits) sur 64 bits OS

StackOverflow https://stackoverflow.com/questions/5342890

  •  27-10-2019
  •  | 
  •  

Question

Je travaille sur un processus en fournisseur de wmi qui charge une bibliothèque tierce partie native de l'aide [DllImport]. Les emplacements dll est fixé à c: \ mydllpath. Avant de charger le dll que je mets le répertoire courant à la loaction dll, dans la méthode bind () du fournisseur.

Environment.CurrentDirectory = Environment.ExpandEnvironmentVariables ( "% SystemDrive%") + "\ mydllpath";

Fournisseur est construit pour 'Any CPU', installé à l'aide gacutil et installexe.

gacutil.exe / if myprovider.dll

installutil.exe myprovider.dll

Il fonctionne très bien dans tous les 32 bits plates-formes Windows. Mais dans 64 plate-forme de bits (essayé avec Windows 7 64 bits), il ne fonctionne pas quand je test à partir WMIC. Mais quand je l'ai testé avec WMI code créateur, il faisait beau travail.

Après le débogage je l'ai trouvé est de lancer l'erreur suivante.

System.BadImageFormatException Informations complémentaires: Tentative de chargement d'un programme avec un format incorrect. (Exception de HRESULT: 0x8007000B)

Après avoir cherché l'aide d'Internet, il a été suggéré de construire le fournisseur pour x86. Mais fournisseur construit avec x86 donne une autre erreur comme ...

ERREUR: Code = 0x80041013 Description = défaut de charge du fournisseur Facility = WMI

J'ai essayé aussi de charger les dll indigènes (en fait 2 dll, et un fichier sys) en utilisant / linkref commutateur de ligne de commande, mais a échoué en raison de ne pas possible de charger le fichier sys en utilisant / linkref.

J'ai écrit un test C # application client et garder tous les fichiers ina même chemin, il fonctionnait très bien. J'espère que je manque quelques configurations pour l'installation 64 bits.

Toute aide serait vraiment appréciée et très merci à l'avance!

Était-ce utile?

La solution

Do you need the code to be 64 bit? You can tell Visual Studio to compile your c# code to a 32 bit executable, then use the 32 bit native DLL's. This will work fine on a 64 bit OS.

.NET by default compiles .net IL to whatever the native instruction set is. In the project settings on the build tab, if the build target is set for "Any CPU" then it will compile to 64 bit on 64 bit platforms, and 32 bit on 32 bit platforms.

If you change this and force 32 bit compilation (set it to x86), then it will compile to 32 bit even on 64 bit platforms, allowing you to use your 32 bit DLL's.

UPDATE: Upon re-reading your question, you state you're building an in-process WMI provider. This would indicate that the provider might need to be 64 bit on 64 bit platforms (I don't know if that's the case). If so, then yeah.. you're out of luck.

UPDATE2: This article seems to indicate that WMI providers need not be 64 bit on 64 bit OS's except in "rare circumstances", so maybe you can get away with a 32 bit provider.

Autres conseils

sorry pal, out of luck here. If your process (the main process, everything started) is running 64 bit you can not load 32 bit native dlls.

here is an article describing some of the difficulties

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top