grip003 Posted September 11, 2006 Posted September 11, 2006 This might be a dumb question, but I don't even have DllImport in my System.Runtime.InteropServices. How do I use DllImport if it is not even listed? I'm trying to set the affinity of my program before/as the application is started. If there is another way other than using the kernel32.dll with DllImport, then I would love to know how to do this. Thanks. Quote
techmanbd Posted September 11, 2006 Posted September 11, 2006 This might be a dumb question, but I don't even have DllImport in my System.Runtime.InteropServices. How do I use DllImport if it is not even listed? I'm trying to set the affinity of my program before/as the application is started. If there is another way other than using the kernel32.dll with DllImport, then I would love to know how to do this. Thanks. At the top you do this Imports System.Runtime.InteropServices Then to use it you do something like this. In my example "Haft4K" is the name of the dll. <DllImport("Haft4k", EntryPoint:="SetUserPS", CharSet:=CharSet.Ansi, SetLastError:=True)> _ Public Shared Function SetUserPS(ByVal nChannel As Integer, ByVal lState As Integer) As Integer End Function Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Leaders snarfblam Posted September 11, 2006 Leaders Posted September 11, 2006 DllImport should definitely be there. Perhaps it is hidden because it is an advanced member? (Are you using VB?) What happens if you type it in manually and try to compile? Quote [sIGPIC]e[/sIGPIC]
grip003 Posted October 10, 2006 Author Posted October 10, 2006 Sorry it took me so long to get back to this, I just moved offices and had such a mess. Anyway, I have the DllImport ability now (don't know what was happening) but I don't know how to use it in C#. I need to import kernel32.dll to set the affinity of my application. Quote
grip003 Posted October 13, 2006 Author Posted October 13, 2006 All set Well, it turns out that setting the affinity for the application is quite simple. Here is the code: System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess(); process.ProcessorAffinity = new IntPtr(1); Hope this helps anyone else who ran into the affinity problem. Quote
Recommended Posts