Hi Guys, There is a project on GitHub that appears to be quite extensive, the problem is that 1) the definitions are in C and 2) they are stored in text files. Is there a way to read and convert these text files to .cs files and then convert the C to C#?<\/p>\n
Also, I would like some clarification on the use of In/Out, ReliabilityContract, and MarshalsAs. Are these necessary in the DLLImport Statement? I find them distracting. However, when I remove them it breaks my code even though the statement is still correct.<\/p>\n Any insight you can provide is appreciated<\/p>","upvoteCount":1,"answerCount":13,"datePublished":"2025-03-23T04:09:31.896Z","author":{"@type":"Person","name":"vincentshanecurtis","url":"https://community.spiceworks.com/u/vincentshanecurtis"},"suggestedAnswer":[{"@type":"Answer","text":" Hi Guys, There is a project on GitHub that appears to be quite extensive, the problem is that 1) the definitions are in C and 2) they are stored in text files. Is there a way to read and convert these text files to .cs files and then convert the C to C#?<\/p>\n Also, I would like some clarification on the use of In/Out, ReliabilityContract, and MarshalsAs. Are these necessary in the DLLImport Statement? I find them distracting. However, when I remove them it breaks my code even though the statement is still correct.<\/p>\n Any insight you can provide is appreciated<\/p>","upvoteCount":1,"datePublished":"2025-03-23T04:09:31.953Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/1","author":{"@type":"Person","name":"vincentshanecurtis","url":"https://community.spiceworks.com/u/vincentshanecurtis"}},{"@type":"Answer","text":" Not to resurrect a dead thread but have you looked at the PInvoke<\/a> website? If I recall they do offer an extension for Visual Studio.<\/p>","upvoteCount":0,"datePublished":"2025-04-09T17:21:11.683Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/2","author":{"@type":"Person","name":"fallen-it","url":"https://community.spiceworks.com/u/fallen-it"}},{"@type":"Answer","text":" Pinvoke website is dead<\/p>","upvoteCount":0,"datePublished":"2025-04-09T17:53:21.044Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/3","author":{"@type":"Person","name":"vincentshanecurtis","url":"https://community.spiceworks.com/u/vincentshanecurtis"}},{"@type":"Answer","text":" Well that’s a shame. I know the Microsoft has examples<\/a><\/p>","upvoteCount":0,"datePublished":"2025-04-09T18:01:22.071Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/4","author":{"@type":"Person","name":"fallen-it","url":"https://community.spiceworks.com/u/fallen-it"}},{"@type":"Answer","text":" I’m still trying to get csWin32 working but so far, nadda. I did find some stuff on GitHub but I have to sit down and mess with it. I’ve got too much stuff going on, but it’s all kinda connected.<\/p>\n Thanks for your input I suppose it really depends on what you’re trying to achieve. AVP will most likely trigger a false positive if you load all the libraries. If you can provide a little more detail of what you’re trying to do.<\/p>\n Nonetheless, good luck!<\/p>","upvoteCount":0,"datePublished":"2025-04-10T12:39:00.864Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/6","author":{"@type":"Person","name":"fallen-it","url":"https://community.spiceworks.com/u/fallen-it"}},{"@type":"Answer","text":" I am trying to use csWin32 to generate a library of DLLImports from all the most common DLLs so they are all coming from a single source for consistency, instead of copy/paste from different sources and then trying to match them up<\/p>","upvoteCount":0,"datePublished":"2025-04-10T19:31:24.003Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/7","author":{"@type":"Person","name":"vincentshanecurtis","url":"https://community.spiceworks.com/u/vincentshanecurtis"}},{"@type":"Answer","text":" This will most likely flag AVPs though. Primarily you’d use UPDATE: found this that may be useful Question - GetProcAddress API | VB.NET Developer Community<\/a><\/p>\n Edit: added more links for assistance<\/em><\/p>","upvoteCount":0,"datePublished":"2025-04-10T19:51:48.420Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/8","author":{"@type":"Person","name":"fallen-it","url":"https://community.spiceworks.com/u/fallen-it"}},{"@type":"Answer","text":" I am not talking about execution I am talking about the DLLImport statements themselves. None of what you are talking about is relevant<\/p>","upvoteCount":0,"datePublished":"2025-04-10T23:02:10.711Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/9","author":{"@type":"Person","name":"vincentshanecurtis","url":"https://community.spiceworks.com/u/vincentshanecurtis"}},{"@type":"Answer","text":" To say what I’m suggesting isn’t relevant is actually false. With little to no explanation of what you’re trying to accomplish it’s hard to try to provide any insight.<\/p>\n As for your questions…<\/p>\n
\nI’m wondering if an “all inclusive” library of PInvoke DLLImport statements exists somewhere. I would prefer them in VB.Net<\/a> but I can convert C# to VB.Net<\/a> with the tool available in Marketplace. And yes, I know all inclusive is a stretch. I’ll settle for as complete as possible. I used to have a tool that I used back in my VB Classic days that allowed me to lookup a function and copy and paste the declare into my code.<\/p>\n
\nI’m wondering if an “all inclusive” library of PInvoke DLLImport statements exists somewhere. I would prefer them in VB.Net<\/a> but I can convert C# to VB.Net<\/a> with the tool available in Marketplace. And yes, I know all inclusive is a stretch. I’ll settle for as complete as possible. I used to have a tool that I used back in my VB Classic days that allowed me to lookup a function and copy and paste the declare into my code.<\/p>\n
\nShane<\/p>","upvoteCount":0,"datePublished":"2025-04-09T21:18:51.310Z","url":"https://community.spiceworks.com/t/pinvoke-library-net-tool/1188437/5","author":{"@type":"Person","name":"vincentshanecurtis","url":"https://community.spiceworks.com/u/vincentshanecurtis"}},{"@type":"Answer","text":"LoadLibrary<\/code>,
GetProcAddress<\/code> and
GetModuleHandle<\/code> which is your main “loader<\/em>” of DLLs. Then from there you can technically just load any DLL using said functions. Marshal.GetDelegateForFunctionPointer Method<\/a><\/p>\n
\nI’ve provided a shortcut to load DLL and function calls at run time rather than have an AVP go ape while compiling due having every import accessible… DLL Import statements aren’t difficult to call. You head to the MSDN<\/a> find the API you want to call and typically they provide you with the DLL statement.<\/p>\n