Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
  • Leaders
Posted
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?
[sIGPIC]e[/sIGPIC]
  • 4 weeks later...
Posted
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.
Posted

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...