Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I have some questions in C#

I have some questions in C#

Scheduled Pinned Locked Moved C#
helpcsharpcomsysadminwindows-admin
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Flysocket
    wrote on last edited by
    #1

    using System; using System.Text; using System.Runtime.InteropServices; namespace AEXMLAdapterTester { internal sealed class NativeMethods { private NativeMethods() {} [DllImport("AEXMLAdapter.dll", EntryPoint="GetAllSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint GetAllSettings(StringBuilder lpBuffer, ref uint lpnSize); [DllImport("AEXMLAdapter.dll", EntryPoint= "SetAllSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint SetAllSettings(string lpBuffer); [DllImport("AEXMLAdapter.dll", EntryPoint= "ReloadSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint ReloadSettings(); }; /// /// Summary description for XmlAdapterInterop. /// /// internal sealed class XmlAdapterInterop { private XmlAdapterInterop() {} public static string GetAllSettings() { uint retVal; StringBuilder buffer = null; uint size = 0; retVal = NativeMethods.GetAllSettings(null, ref size); if (retVal == 122) { buffer = new StringBuilder((int)size); retVal = NativeMethods.GetAllSettings(buffer, ref size); } if (retVal != 0) throw new ApplicationException("Interop Error calling GetAllSettings"); return buffer.ToString(); } public static void SetAllSettings(string buffer) { uint retVal; retVal = NativeMethods.SetAllSettings(buffer); if (retVal != 0) throw new ApplicationException("Interop Error calling SetAllSettings - retVal = " + retVal); } public static void ReloadSettings() { uint retVal; retVal = NativeMethods.ReloadSettings(); if (retVal != 0) throw new ApplicationException("Interop Error calling SetNothing - retVal = " + retVal); } } } These code running correctly in Windows 2003 server 32Bit but when use in Windows Server 64Bit when i invoke XmlAdapterInterop.GetAllSettings() an exception occured "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)" Any one can help me, i will thank you a lot

    I want to make some friends here

    L N F 3 Replies Last reply
    0
    • F Flysocket

      using System; using System.Text; using System.Runtime.InteropServices; namespace AEXMLAdapterTester { internal sealed class NativeMethods { private NativeMethods() {} [DllImport("AEXMLAdapter.dll", EntryPoint="GetAllSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint GetAllSettings(StringBuilder lpBuffer, ref uint lpnSize); [DllImport("AEXMLAdapter.dll", EntryPoint= "SetAllSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint SetAllSettings(string lpBuffer); [DllImport("AEXMLAdapter.dll", EntryPoint= "ReloadSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint ReloadSettings(); }; /// /// Summary description for XmlAdapterInterop. /// /// internal sealed class XmlAdapterInterop { private XmlAdapterInterop() {} public static string GetAllSettings() { uint retVal; StringBuilder buffer = null; uint size = 0; retVal = NativeMethods.GetAllSettings(null, ref size); if (retVal == 122) { buffer = new StringBuilder((int)size); retVal = NativeMethods.GetAllSettings(buffer, ref size); } if (retVal != 0) throw new ApplicationException("Interop Error calling GetAllSettings"); return buffer.ToString(); } public static void SetAllSettings(string buffer) { uint retVal; retVal = NativeMethods.SetAllSettings(buffer); if (retVal != 0) throw new ApplicationException("Interop Error calling SetAllSettings - retVal = " + retVal); } public static void ReloadSettings() { uint retVal; retVal = NativeMethods.ReloadSettings(); if (retVal != 0) throw new ApplicationException("Interop Error calling SetNothing - retVal = " + retVal); } } } These code running correctly in Windows 2003 server 32Bit but when use in Windows Server 64Bit when i invoke XmlAdapterInterop.GetAllSettings() an exception occured "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)" Any one can help me, i will thank you a lot

      I want to make some friends here

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      I have no experience with Win64, but I expect some problems; in your case "ref size" now becomes a 64-bit pointer, and both parties should agree on that. I googled "pinvoke 64bit" and found several hits, one says "If you rely on 32-bit libraries you should make sure your app runs with the 32-bit framework" ... :)

      Luc Pattyn

      1 Reply Last reply
      0
      • F Flysocket

        using System; using System.Text; using System.Runtime.InteropServices; namespace AEXMLAdapterTester { internal sealed class NativeMethods { private NativeMethods() {} [DllImport("AEXMLAdapter.dll", EntryPoint="GetAllSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint GetAllSettings(StringBuilder lpBuffer, ref uint lpnSize); [DllImport("AEXMLAdapter.dll", EntryPoint= "SetAllSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint SetAllSettings(string lpBuffer); [DllImport("AEXMLAdapter.dll", EntryPoint= "ReloadSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint ReloadSettings(); }; /// /// Summary description for XmlAdapterInterop. /// /// internal sealed class XmlAdapterInterop { private XmlAdapterInterop() {} public static string GetAllSettings() { uint retVal; StringBuilder buffer = null; uint size = 0; retVal = NativeMethods.GetAllSettings(null, ref size); if (retVal == 122) { buffer = new StringBuilder((int)size); retVal = NativeMethods.GetAllSettings(buffer, ref size); } if (retVal != 0) throw new ApplicationException("Interop Error calling GetAllSettings"); return buffer.ToString(); } public static void SetAllSettings(string buffer) { uint retVal; retVal = NativeMethods.SetAllSettings(buffer); if (retVal != 0) throw new ApplicationException("Interop Error calling SetAllSettings - retVal = " + retVal); } public static void ReloadSettings() { uint retVal; retVal = NativeMethods.ReloadSettings(); if (retVal != 0) throw new ApplicationException("Interop Error calling SetNothing - retVal = " + retVal); } } } These code running correctly in Windows 2003 server 32Bit but when use in Windows Server 64Bit when i invoke XmlAdapterInterop.GetAllSettings() an exception occured "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)" Any one can help me, i will thank you a lot

        I want to make some friends here

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        I have experienced this exception before. I would say the most likely cause is that AEXMLAdapter.dll, or some other library you are using, is not compiled in 64bit mode.


        only two letters away from being an asset

        1 Reply Last reply
        0
        • F Flysocket

          using System; using System.Text; using System.Runtime.InteropServices; namespace AEXMLAdapterTester { internal sealed class NativeMethods { private NativeMethods() {} [DllImport("AEXMLAdapter.dll", EntryPoint="GetAllSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint GetAllSettings(StringBuilder lpBuffer, ref uint lpnSize); [DllImport("AEXMLAdapter.dll", EntryPoint= "SetAllSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint SetAllSettings(string lpBuffer); [DllImport("AEXMLAdapter.dll", EntryPoint= "ReloadSettings", SetLastError=true, CharSet=CharSet.Unicode)] public static extern uint ReloadSettings(); }; /// /// Summary description for XmlAdapterInterop. /// /// internal sealed class XmlAdapterInterop { private XmlAdapterInterop() {} public static string GetAllSettings() { uint retVal; StringBuilder buffer = null; uint size = 0; retVal = NativeMethods.GetAllSettings(null, ref size); if (retVal == 122) { buffer = new StringBuilder((int)size); retVal = NativeMethods.GetAllSettings(buffer, ref size); } if (retVal != 0) throw new ApplicationException("Interop Error calling GetAllSettings"); return buffer.ToString(); } public static void SetAllSettings(string buffer) { uint retVal; retVal = NativeMethods.SetAllSettings(buffer); if (retVal != 0) throw new ApplicationException("Interop Error calling SetAllSettings - retVal = " + retVal); } public static void ReloadSettings() { uint retVal; retVal = NativeMethods.ReloadSettings(); if (retVal != 0) throw new ApplicationException("Interop Error calling SetNothing - retVal = " + retVal); } } } These code running correctly in Windows 2003 server 32Bit but when use in Windows Server 64Bit when i invoke XmlAdapterInterop.GetAllSettings() an exception occured "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)" Any one can help me, i will thank you a lot

          I want to make some friends here

          F Offline
          F Offline
          Flysocket
          wrote on last edited by
          #4

          I have get some informations from you guys and i select platform target X86 in build tag then run again, it is ok. if the AEXMLAdapter.dll build in x86 machine so the project must build in x86 mode? As the program is a unit test assembly, when i try to build in x86 mode, the Nunit cannnot open the assembly. Any body has some experience in this issue?

          I want to make some friends here

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups