You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to use CSWin32 to do some Pinvoke calls but my imports are throwing an error
using System;using System.Linq;using Microsoft.Windows.SDK <- this cannot be imported says windows does not exist innamespacemicrosoft;usingstatic ScoutLib.Utils.GlobalUtils;usingAddInUtilities;using System.Diagnostics;using System.Collections.Generic;using System.Threading;namespace ScoutLib.JobObjects
{publicpartialclassScoutModule{publicstaticvoidJobObjectHandlerFunc(JobObjectsConfigjobObjectsConfig){Dictionary<string,int>processIdsMapping=new();// Get the process Ids for the required processesforeach(var processName in jobObjectsConfig.BinariesWithCpuUsageCapped){varprocesses= Process.GetProcessesByName(processName);if(processes.Length ==0){
Log.Debug($"Could not find Process with Name : {processName}");}else{// Get the first running process by name
Log.Debug($" Found Process : {processName} with Id {processes[0].Id}");
processIdsMapping[processName]= processes[0].Id;}}// Try creating Job Object// Create a job objectvarjobObject= PInvoke.S_OK;}publicstaticvoidSpawnJobObjectThread(){
Log.Info("Trying to spawn a new thread for Job Objects");varjobObjectsConfigManager=newConfigManager<JobObjectsConfig>("JOB_OBJECTS_CONFIG");varjobObjectsConfig= jobObjectsConfigManager.ConfigValues;varjobObjectThread=new Thread(()=> JobObjectHandlerFunc(jobObjectsConfig));
jobObjectThread.Start();if(!jobObjectThread.IsAlive){
Log.Warn("Job Object thread could not be spawned .");// ToDo : What to do incase thread could not be spawned.}
Log.Info("Successfully spawned a new thread for job objects related handling");}}}
Expected behavior
Should be able to call Pinvoke
Repro steps
NativeMethods.txt content:
S_OK;
NativeMethods.json content (if present):
Any of your own code that should be shared?
Context
CsWin32 version: 0.3.18-beta
Win32Metadata version (if explicitly set by project):
Target Framework: net7.0
LangVersion (if explicitly set by project): [e.g. 9]
The text was updated successfully, but these errors were encountered:
using Microsoft.Windows.SDK <- this cannot be imported says windows does not exist in namespace microsoft ;
If that's the problem you're calling out, you're using the wrong namespace. The namespace we generate into is Windows.Win32.
When in doubt, try using Go To All (Ctrl-T) on the identifier you entered into NativeMethods.txt and C# will jump you to the code generated API so you can inspect its namespace.
Actual behavior
Trying to use CSWin32 to do some Pinvoke calls but my imports are throwing an error
Expected behavior
Should be able to call Pinvoke
Repro steps
NativeMethods.txt
content:NativeMethods.json
content (if present):Context
LangVersion
(if explicitly set by project): [e.g.9
]The text was updated successfully, but these errors were encountered: