In VB6, when the project is saved, the case of the declaration of OCX control change in the .FRM so the source control report some changes that are not in fact :
-Object = "{FDFCEE46-937A-11D4-B73C-00104BAFEBDD}#1.0#0"; "OmniTBox.ocx"
+Object = "{FDFCEE46-937A-11D4-B73C-00104BAFEBDD}#1.0#0"; "omniTBox.ocx"
-Object = "{253FB3DC-6581-4D7E-ADA0-0C93062AB59C}#3.0#0"; "GPBUTTONSH.ocx"
+Object = "{253FB3DC-6581-4D7E-ADA0-0C93062AB59C}#3.0#0"; "gpbuttonsh.ocx"
Is there a way to avoid that ?
This is because of the case in the registry.
For example search the value :
"253FB3DC-6581-4D7E-ADA0-0C93062AB59C" (or "gpbuttonsh.ocx")
in your registry and change the case to GPBUTTONSH.ocx everywhere (but it should be enough with the HKCU\Software\Classes\TypeLib one) then VB6 will write it like that in the project.
Related
I am looking for a way to have VB6 edit a controls' propertybag right before or while the Form is being saved..
We're using an activeX control (AxisMediaControl) that seemingly uses Spaces in it's propertybag names which throws an error when trying to save the form the control is on.
System Error &H80070057 (-2147024809)
The same problem is described here:
Source of a similar problem, but i don't have *.h files ()
but since we use the compiled ActiveX i can't edit the way it handles writing properties, and we don't have access to the source of the ActiveX..
I've managed to create a workaround loading the control at runtime,as an Array of objects, but this way i wont have them indexed to capture events by index.
Dim Axis(1) As AxisMediaControl
For i% = 0 To 1
Set Axis(i%) = Controls.Add("AxisMediaControl.AxisMediaControl.1", "AMC" & i%)
Axis(i%).Tag = "CAM" + Format$(i%)
Next i%
' Play Video
With Axis(0)
.Top = 600
.Left = 240
.Width = 9135
.Height = 5535
.Visible = True
.StretchToFit = True
.MaintainAspectRatio = True
.EnableContextMenu = True
.MediaFile = VideoFile$
.play
End With
' Play Stream
With Axis(1)
.Top = 6840
.Left = 240
.Width = 9135
.Height = 5535
.Visible = True
.StretchToFit = True
.MaintainAspectRatio = True
.EnableContextMenu = True
.MediaFile = VideoStream$
.play
End With
The ActiveX is working fine with younger versions of Visual Basic like express 2005 or vb.net and only occurs under vb6.
Are there ways to 'edit' the way the properties are saved to the propertybag?
Can i edit the dll or ocx to behave differently and have a working up-to-date version of an ActiveX that was previously incompatible? I've tried using Resource Hacker on the dll files but to no avail since my knowledge there is limited..
Since you mentioned the control works in dotnet versions of VB, a workaround could be to write a wrapper in VB.NET, and then use that wrapper from VB6. This wrapper would provide a standard "ActiveX" (COM) interface and internally just call the original control. You would only need to expose the bare minimum of functionality in the wrapper, just to minimize the effort involved.
(Note - while this might work technically it may not be the best overall solution. For instance, if upgrading to a more modern control is possible that might be a better investment of time.)
Edit 1: A wrapper would impose some additional overhead, that is certain. But this overhead might not be important at all. If you only have to make a few calls for instance the runtime effect is probably irrelevant. OTOH if you have to call this thing within the innermost loop of some algorithm (doubtful for a UI control but...) that could be more of a problem.
Edit 2: If you don't already have any dotnet components in your app it might not be worth adding that dependency just for this issue. Or maybe it would be, if this truly is a showstopper; but that could be an additional consideration to think through carefully.
I know that OXS bind special keys on option key, such as option+y=¥,option+t=þ... But now, I want to cancel all these bindings, and use option+character as the shortcuts in JetBrains IDEs and other apps.
I have searched for hours and still haven't found a useful way.Can anyone share a tool or the correct way?I used the way to add Library/KeyBindings/DefaultKeyBinding.dict file, but it only canceled some key-bindings, not work for all.
It is my DefaultKeyBinding.dict file below :
{
"~d" = "deleteWordForward:";
"^w" = "deleteWordBackward:";
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~u" = "pageUp:";
}
Now ,option+f/b can used as my jetbrains IDEs shortcut,but option+u still print special character.
I have found a way: if I select Unicode Hex Input as my input source from System preferences->keyBoard->Input Sources, all bindings now disappeared!
I am currently trying you learn VB6 and came across this issue.
I wanted to loop through a for loop and adding a number to a control name.
Dim I As Integer
For I = 1 To 5
S = CStr(I)
If TextS.Text = "" Then
LabelS.ForeColor = &HFF&
Else
LabelS.ForeColor = &H80000012
End If
Next I
This S needs to be added to Text and Label so the colour will be changed without needing to use 5 If Else statements
I hope you can help me with this.
From your comment below:
What i mean is this: If Text1.text = "" Then I need this 1 to be replaced with the variable I, so the for loop can loop through my 5 textboxes and the same for my Labels.
You can't do that (look up a variable using an expression to create its name) in VB6. (Edit: While that statement is true, it's not true that you can't look up form controls using a name from an expression. See "alternative" below.)
What you can do is make an array of your textboxes, and then index into that array. The dev env even helps you do that: Open your form in the dev env and click the first textbox. Change its name to the name you want the array to have (perhaps TextBoxes). Then click the next textbox and change its name to the same thing (TextBoxes). The dev env will ask you:
(Don't ask me why I have a VM lying around with VB6 on it...)
Click Yes, and then you can rename your other textboxes TextBoxes to add them to the array. Then do the same for your labels.
Then your code should look like this:
For I = TextBoxes.LBound To TextBoxes.UBound
If TextBoxes(I).Text = "" Then
Labels(I).ForeColor = &HFF&
Else
Labels(I).ForeColor = &H80000012
End If
Next
LBound is the lowest index of the control array, UBound is the highest. (You can't use the standard LBound and Ubound that take the array as an argument, because control arrays aren't quite normal arrays.) Note also that there's no need to put I on the Next line, that hasn't been required since VB4 or VB5. You can, though, if you like being explicit.
Just make sure that you have exactly the same number of TextBoxes as Labels. Alternately, you could create a user control that consisted of a label and a textbox, and then have a control array of your user control.
Alternative: : You can use the Controls array to look up a control using a name resulting from an expression, like this:
For I = 1 To 5
If Me.Controls("Text" & I).Text = "" Then
Me.Controls("Label" & I).ForeColor = &HFF&
Else
Me.Controls("Label" & I).ForeColor = &H80000012
End If
Next
This has the advantage of mapping over to a very similar construct in VB.Net, should you migrate at some point.
Side note:
I am currently trying you learn VB6...
(tl;dr - I'd recommend learning something else instead, VB6 is outdated and the dev env hasn't been supported in years.)
VB6's development environment has been discontinued and unsupported for years (since 2008). The runtime is still (I believe) supported because of the sheer number of apps that use it, although the most recent patch seems to be from 2012. But FWIW, you'd get a better return on your study time learning VB.net or C#.Net (or any of several non-Microsoft languages), rather than VB6...
I have a Setup and Deployment project in Visual Studio 2010.
I would like the installer to create two shortcuts to the executable of another project in my solution. One normal shortcut that simply runs the application using current credentials and another which has the Run as administrator flag set, thereby ensuring that the user is asked for credentials with administrative rights when clicking the shortcut.
Running the application with administrative rights enables certain features that are otherwise not available.
Setting this flag doesn't seem to be possible at first glance. Can this be done directly in Visual Studio? If not, are there any other options?
Edit: If not, is it possible to modify the shortcut programmatically using a custom installer class?
I know this is quite an old question, but I needed to find an answer and I thought I could help other searchers. I wrote a small function to perform this task in VBScript (pasted below). It is easily adapted to VB.net / VB6.
Return codes from function:
0 - success, changed the shortcut.
99 - shortcut flag already set to run as administrator.
114017 - file not found
114038 - Data file format not valid (specifically the file is way too small)
All other non-zero = unexpected errors.
As mentioned by Chada in a later post, this script will not work on msi Advertised shortcuts. If you use this method to manipulate the bits in the shortcut, it must be a standard, non-advertised shortcut.
References:
MS Shortcut LNK format: http://msdn.microsoft.com/en-us/library/dd871305
Some inspiration: Read and write binary file in VBscript
Please note that the function does not check for a valid LNK shortcut. In fact you can feed it ANY file and it will alter Hex byte 15h in the file to set bit 32 to on.
If copies the original shortcut to %TEMP% before amending it.
Daz.
'# D.Collins - 12:58 03/09/2012
'# Sets a shortcut to have the RunAs flag set. Drag an LNK file onto this script to test
Option Explicit
Dim oArgs, ret
Set oArgs = WScript.Arguments
If oArgs.Count > 0 Then
ret = fSetRunAsOnLNK(oArgs(0))
MsgBox "Done, return = " & ret
Else
MsgBox "No Args"
End If
Function fSetRunAsOnLNK(sInputLNK)
Dim fso, wshShell, oFile, iSize, aInput(), ts, i
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")
If Not fso.FileExists(sInputLNK) Then fSetRunAsOnLNK = 114017 : Exit Function
Set oFile = fso.GetFile(sInputLNK)
iSize = oFile.Size
ReDim aInput(iSize)
Set ts = oFile.OpenAsTextStream()
i = 0
Do While Not ts.AtEndOfStream
aInput(i) = ts.Read(1)
i = i + 1
Loop
ts.Close
If UBound(aInput) < 50 Then fSetRunAsOnLNK = 114038 : Exit Function
If (Asc(aInput(21)) And 32) = 0 Then
aInput(21) = Chr(Asc(aInput(21)) + 32)
Else
fSetRunAsOnLNK = 99 : Exit Function
End If
fso.CopyFile sInputLNK, wshShell.ExpandEnvironmentStrings("%temp%\" & oFile.Name & "." & Hour(Now()) & "-" & Minute(Now()) & "-" & Second(Now()))
On Error Resume Next
Set ts = fso.CreateTextFile(sInputLNK, True)
If Err.Number <> 0 Then fSetRunAsOnLNK = Err.number : Exit Function
ts.Write(Join(aInput, ""))
If Err.Number <> 0 Then fSetRunAsOnLNK = Err.number : Exit Function
ts.Close
fSetRunAsOnLNK = 0
End Function
This is largely due to the fact that Windows Installer uses 'Advertised shortcuts' for the Windows Installer packages.
There is no way inherently to disable this in Visual Studio, but it is possible to modify the MSI that is produced to make sure that it does not use advertised shortcuts (or uses only one). There are 2 ways of going about this:
If your application uses a single exe or two - Use ORCA to edit the MSI. Under the shortcuts table, change the Target Entry to "[TARGETDIR]\MyExeName.exe" - where MyExeName is the name of your exe - this ensures that that particular shortcut is not advertised.
Add DISABLEADVTSHORTCUTS=1 to the the property Table of the MSI using ORCA or a post build event (using the WiRunSQL.vbs script). If you need more info on this let me know. This disables all advertised shortcuts.
it may be better to use the first approach, create 2 shortcuts and modify only one in ORCA so that you can right click and run as admin.
Hope this helps
This is not supported by Windows Installer. Elevation is usually handled by the application through its manifest.
A solution is to create a wrapper (VBScript or EXE) which uses ShellExecute with runas verb to launch your application as an Administrator. Your shortcut can then point to this wrapper instead of the actual application.
Sorry for the confusion - I now understand what you are after.
There are indeed ways to set the shortcut flag but none that I know of straight in Visual Studio. I have found a number of functions written in C++ that set the SLDF_RUNAS_USER flag on a shortcut.
Some links to such functions include:
http://blogs.msdn.com/b/oldnewthing/archive/2007/12/19/6801084.aspx
http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/a55aa70e-ae4d-4bf6-b179-2e3df3668989/
Another interesting discussion on the same topic was carried out at NSIS forums, the thread may be of help. There is a function listed that can be built as well as mention of a registry location which stores such shortcut settings (this seems to be the easiest way to go, if it works) - I am unable to test the registry method at the moment, but can do a bit later to see if it works.
This thread can be found here: http://forums.winamp.com/showthread.php?t=278764
If you are quite keen to do this programatically, then maybe you could adapt one of the functions above to be run as a post-install task? This would set the flag of the shortcut after your install but this once again needs to be done on Non-Advertised shortcuts so the MSI would have to be fixed as I mentioned earlier.
I'll keep looking and test out the registry setting method to see if it works and report back.
Chada
I needed to make my application to be prompted for Administator's Rights when running from Start Menu or Program Files.
I achieved this behavior after setting in \bin\Debug\my_app.exe 'Run this program as administator' checkbox to true. ( located in Properties\Compatibility section ).
While installing project, this file was copied to the Program Files (and therefore the shortcut in the Start Menu) with needed behavior.
Thanks,
Pavlo
I have a lot of custom keyboard shortcuts set up. To avoid having to set them up every time I install a new visual studio (happens quite a lot currectly, with VS2010 being in beta/RC) I have created a macro, that sets up all my custom commands, like this:
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"
My main problem is that Ctrl+T is set up to map to the transpose char command by default. So I want to remove that default value in my macro.
I have tried the following two lines, but both throw an exception
DTE.Commands.Item("Edit.CharTranspose").Bindings = ""
DTE.Commands.Item("Edit.CharTranspose").Bindings = Nothing
Although they kind of work, because they actually remove the binding ;) But I would prefer the solution that doesn't throw an exception.
How is that done?
I have coped with the same issue. I use a macro to assign key bindings for a set of align macros.
Dim NewBindings() = {"Global::Alt+="}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignEquals").Bindings = NewBindings
NewBindings(0) = "Global::Alt+Num -"
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignMinus").Bindings = NewBindings
...
And to remove key bindings i use the following statements :
Dim DelBindings() = {}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignPlus").Bindings = DelBindings
It works fine under Visual Studio 2005.
I followed a little more pragmatic way (using your example):
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T"
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"
With the first assignment Ctrl+T is unassigned from any other function and then becomes unbound with the second assignment.
Works like a charm for me.
You do not need to change it with macro, Just go to
Menu>Tools>Options -- Keyboard and then select what you want to change the shortcut from the dropdown and assignyour desiered short cut