Hi Guys,
I’m wondering if an “all inclusive” library of PInvoke DLLImport statements exists somewhere. I would prefer them in VB.Net but I can convert C# to VB.Net 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.

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#?

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.

Any insight you can provide is appreciated

1 Spice up

Not to resurrect a dead thread but have you looked at the PInvoke website? If I recall they do offer an extension for Visual Studio.

Pinvoke website is dead

Well that’s a shame. I know the Microsoft has examples

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.

Thanks for your input
Shane

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.

Nonetheless, good luck!

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

This will most likely flag AVPs though. Primarily you’d use LoadLibrary, GetProcAddress and GetModuleHandle which is your main “loader” of DLLs. Then from there you can technically just load any DLL using said functions. Marshal.GetDelegateForFunctionPointer Method

UPDATE: found this that may be useful Question - GetProcAddress API | VB.NET Developer Community

Edit: added more links for assistance

I am not talking about execution I am talking about the DLLImport statements themselves. None of what you are talking about is relevant

To say what I’m suggesting isn’t relevant is actually false.
I’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 find the API you want to call and typically they provide you with the DLL statement.

With little to no explanation of what you’re trying to accomplish it’s hard to try to provide any insight.

As for your questions…

MarshalAs basically when you’re trying to convert a Managed and Unmanaged code. Converts the string to LPStr

Public Sub SendMessage(<MarshalAs(UnmanagedType.LPStr)> ByVal message As String)
    SendMessageAsString(hWnd, WM_SETTEXT, message, message.Length)
End Sub

Anyway… I’ll leave it here. Good luck.

I explained EXACTLY what I am trying to accomplish. I don’t want to hunt and peck around as you are suggesting. I want to create a complete library of Imports from various DLLs that are commonly used in WinAPI. If you are not going to directly answer my question then please scroll on. I get tired of people who want to contribute their two cents because they think their way is better than what I want to do. You do it your way if that’s what you want and stop trying to force it on me.

Sending you some positive energy your way. Good luck.

(post deleted by author)