I am lookibg for the DLLImport API signature for deleting a registry value.
PInvoke only has the definition for mobile devices.
I am looking for the normal Definition for windows in VB.Net.
I know I can also delete a registry value by using System.Win32.Registry but nevertheless I am looking for the API signature.
Can someone help me out?;)^
Nevermind got it:
Sounds like you are looking for the DllImport signature of RegDeleteKeyValue function. If so this is it
<DllImport("advapi32.dll")> _
Private Shared Function RegDeleteKeyValue( _
ByVal handle As IntPtr, _
ByVal keyName As String, _
ByVal valueName As String)
End Function
Related
Most of us just 'assume' that a file ending in '.docx' is a Word Document.
If I right-click on the file and show properties, then the properties window shows
Microsoft Word Document (.docx)
I want to know whether I can get that information programmatically.
IE, there's a way to declare
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As Long
and use that to find what program is associated with the file.
If there is, WHAT is the call I need to make Windows give me the file type?
I have two dlls with the same API accessing different hardware devices (built be me). I want to select one of them at run-time based on which hardware is detected in the computer.
I found that I can use the windows function LoadLibrary to load one of the two libraries before I call any function from the DLL, and VB will use the loaded library - but this works only if the file name matches what's in the function Declare (or Dllimport), i.e. both dll versions have to have the same file name. And this means that the dlls cannot be located in the same directory (such as in the System32 directory).
Can I have two dlls with two different filenames that provide the same API to the VB.NET selectable at run-time?
You can't really do conditional imports other than with compilation constants. However you could import both the dlls and make a method which calls either one depending on your condition.
Something like:
<DllImport("firstversion.dll", EntryPoint:="GetDevice")> _
Public Shared Function GetDevice_v1(ByVal arg1 As IntPtr, ByVal arg2 As String) As IntPtr
End Function
<DllImport("secondversion.dll", EntryPoint:="GetDevice")> _
Public Shared Function GetDevice_v2(ByVal arg1 As IntPtr, ByVal arg2 As String) As IntPtr
End Function
Public Shared Function GetDevice(ByVal arg1 As IntPtr, ByVal arg2 As String) As IntPtr
If condition Then
Return GetDevice_v1(arg1, arg2)
Else
Return GetDevice_v2(arg1, arg2)
End If
End Function
If I'm using Visual Basic to run an executable using the Shell() command, how would I run that executable as an administrator? My method works, at least in practice, but one executable won't run properly and I think that's the issue.
Here's an example of the command I'm trying to run.
Shell("%temp%\ninite.exe")
Edit: Sorry, this is VB.net, not VBA. I put a bad tag on there.
To stay strictly in VBA with no .NET dependencies, you should be able to use the ShellExecute Win32 function.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal lpOperation As String,
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
You can pass "runas" to lpOperation instead of the more usual "open" (commonly called the verb). Note that this may cause a dialog box to come up prompting the user for credentials.
A better way might be to use the CreateProcess or CreateProcessAsUser function which is probably the most powerful way to launch anything in Windows, but that is certainly more complex and I cannot tell you the details of how to get it to work right.
I'm trying to use a function from a Fortran library. The function is supposed to return a string. If I use this
Friend Declare Ansi Sub LaA_LabelGet Lib "V3Mat.dll" (ByRef hLaA As IntPtr, ByVal iRegion As Integer, ByVal cLabel As String, ByVal intLabelLen As Integer)
statement it works fine, if I use
<DllImport("V3Mat.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)>
Friend Sub LaA_LabelGet(ByRef hLaA As IntPtr, ByVal iRegion As Integer, ByVal cLabel As String, ByVal intLabelLen As Integer)
End Sub
the cLabel is always blank.
Can anyone please point out the difference between the two. I'd rather use the second definition as it allows me to set the library to use by using a constant.
The Declare statement is legacy syntax that was adopted in VB.NET to work the way it did back in the VB6 days. The one thing it does that matters in your case is that it allows native code to write into the string. Like it was possible back in VB6. Which is entirely invalid in .NET, strings are immutable.
The exact equivalent in the <DllImport> declaration would be <MarshalAs(UnmanagedType.VBByRefStr)> ByRef cLabel As String
The better solution is to declare the argument as ByVal cLabel As StringBuilder and pass a properly initialized StringBuilder object with a sufficient Capacity. And use its ToString() method afterwards to obtain the returned string.
The answer to my question may already be out there, but I am having no success synthesizing the data into a coherent solution. Your advice is appreciated.
I am writing a "User Control" application using Visual Basic (.NET 3.5) and Visual Studio 2012. I have been given a DLL file which contains functionality that I must access. Additionally, I have been given corresponding .LIB and .H files, which I am told will be necessary to properly make use of the DLL. I believe the DLL was written in C.
I have also been provided with some older VB code which is said to make use of the DLL's functions one that DLL is "included" (or something) in the project. As you can probably tell, my grasp on this is tenuous at best. Here is the VB code:
Private Declare Function SF_AddToCommandQueue Lib "SFrmUt80.dll" Alias "_SF_AddToCommandQueue#8" _
(ByVal CmdCode As Integer, ByVal strParam As String) As Boolean
Private Declare Function SF_FlushCommandQueue Lib "SFrmUt80.dll" Alias "_SF_FlushCommandQueue#4" _
(ByVal strWindowTitle As String) As Boolean
Private Declare Function SF_GetUserName Lib "SFrmUt80.dll" Alias "_SF_GetUserName#8" _
(ByVal strBuffer As String, ByVal BufferSize As Integer) As Integer
Private Declare Function SF_GetUserID Lib "SFrmUt80.dll" Alias "_SF_GetUserID#0" _
() As Integer
Private Declare Function SF_GetCmdType Lib "SFrmUt80.dll" Alias "_SF_GetCmdType#0" _
() As Integer
Private Declare Function SF_GetCmdFilename Lib "SFrmUt80.dll" Alias "_SF_GetCmdFilename#8" _
(ByVal strBuffer As String, ByVal BufferSize As Integer) As Integer
Private Declare Function SF_GetRegisteredMsg Lib "SFrmUt80.dll" Alias "_SF_GetRegisteredMsg#0" _
() As Integer
Hoping this is not too vague, I am wondering how I go about integrating this DLL file into my solution, so that I may make use of its functionality in VB .NET.
Your wisdom is very much appreciated. Thank you!
The .H-files won't be of much use to you, as you don't use them in the managed environment. You would actually just include the DLLs into your solution (i.e. add them to the project in the Solution-Explorer).
VS does the rest for you, all you need to do is, as you already did, declare the functions from the library in your source-code and call the functions.
On MSDN there is an article on this.