I have some questions in C#
-
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
-
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
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
-
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
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
-
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
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