Build any cpu = 32 != 64

Sunt tot felul de diferente intre 32 si 64 de biti. Iar “Any CPU” , teoretic, ar trebui sa te ajute – insa  citeodata te incurca

Exemplu:

Sa zicem ca avem un programel care listeaza toate procesele

            var p1 = Process.GetProcesses();
            foreach (var process1 in p1)
            {
                Console.WriteLine(process1.MainModule.FileName);
            }
   

 

 

 

Compilat pe AnyCPU si pornit cu drepturi de admin, eroarea este

Unhandled Exception: System.ComponentModel.Win32Exception: A 32 bit processes cannot access modules of a 64 bit process.
   at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId)
at System.Diagnostics.Process.get_MainModule()
at TestCPU.Program.Main(String[] args) in C:\eu\TestCPU\TestCPU\Program.cs:line 18

 

Compilat pe 64 si pornit cu drepturi de admin , da, nu poate accesa citeva procese –insa pe celelalte da

Acum, cum faceti daca aveti dll de x32 compilate in C ( declspec dllinvoke ) si vreti sa le accesati din x64?
Microsoft zice ca nu se poate incarca x32 in x64 cu LoadLibrary ( https://support.microsoft.com/en-us/kb/282423) )

Alternativa 1:
Faceti consola x32 care sa comunice cu X64 prin command line si cu dll prin nativ API
Alternativa 2:
Utilizati https://github.com/CodefoundryDE/LegacyWrapper
Alternativa 3:
De mina dupa https://blog.mattmags.com/2007/06/30/accessing-32-bit-dlls-from-64-bit-code/

Leave a Reply

Your email address will not be published. Required fields are marked *