Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot discover the namespace APIs are emitted into #1023

Closed
Aaswin1996 opened this issue Aug 17, 2023 · 2 comments
Closed

Cannot discover the namespace APIs are emitted into #1023

Aaswin1996 opened this issue Aug 17, 2023 · 2 comments
Labels
question Further information is requested

Comments

@Aaswin1996
Copy link

Aaswin1996 commented Aug 17, 2023

Actual behavior

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 in namespace microsoft ;
using static ScoutLib.Utils.GlobalUtils;
using AddInUtilities;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;

namespace ScoutLib.JobObjects
{
    public partial class ScoutModule
    {
        public static void JobObjectHandlerFunc(JobObjectsConfig jobObjectsConfig)
        {
            Dictionary<string, int> processIdsMapping = new();

            // Get the process Ids for the required processes
            foreach (var processName in jobObjectsConfig.BinariesWithCpuUsageCapped)
            {
                var processes = 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 object
            var jobObject = PInvoke.S_OK;


        }

        public static void SpawnJobObjectThread()
        {
            Log.Info("Trying to spawn a new thread for Job Objects");
            var jobObjectsConfigManager = new ConfigManager<JobObjectsConfig>("JOB_OBJECTS_CONFIG");
            var jobObjectsConfig = jobObjectsConfigManager.ConfigValues;

            var jobObjectThread = 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

  1. NativeMethods.txt content:
S_OK;
  1. NativeMethods.json content (if present):
  1. 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]
@Aaswin1996 Aaswin1996 added the bug Something isn't working label Aug 17, 2023
@AArnott
Copy link
Member

AArnott commented Aug 17, 2023

tip: use 3 backticks with a cs after them, on their own line, to delineate c# code blocks for better formatting in github.

@AArnott
Copy link
Member

AArnott commented Aug 17, 2023

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.

@AArnott AArnott added question Further information is requested and removed bug Something isn't working labels Aug 17, 2023
@AArnott AArnott changed the title Unable to use CSWin32 in my Project ... Cannot discover the namespace APIs are emitted into Aug 17, 2023
@AArnott AArnott closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants